Skip to content
Snippets Groups Projects
Commit c570ea0c authored by Fidel Alfaro Almagro's avatar Fidel Alfaro Almagro :speech_balloon:
Browse files

Remove bugs that prevented the pipeline from running

parent 8c179bfd
No related branches found
No related tags found
No related merge requests found
Showing
with 52 additions and 55 deletions
...@@ -12,7 +12,6 @@ import sys ...@@ -12,7 +12,6 @@ import sys
import logging import logging
import argparse import argparse
import json import json
from dataclasses import dataclass, field
from file_tree import FileTree from file_tree import FileTree
from pipe_tree import Pipeline, Ref from pipe_tree import Pipeline, Ref
import bip import bip
...@@ -35,18 +34,17 @@ class Usage(Exception): ...@@ -35,18 +34,17 @@ class Usage(Exception):
def __init__(self, msg): def __init__(self, msg):
self.msg = msg self.msg = msg
@dataclass
class Context: class Context:
subject: str = ""
BB_BIN_DIR: str = bip.__path__[0]
FSLDIR: str = os.environ['FSLDIR']
gdc: str = field(init=False)
with open(self.get_data('dMRI/autoptx/struct_list.json'), 'r') as f: def __init__(self, subject=""):
tract_struct = json.load(f)
def __post_init__(self): self.subject = subject
self.gdc = self.get_data('GDC/UKB.txt') self.BB_BIN_DIR = bip.__path__[0]
self.FSLDIR = os.environ['FSLDIR']
self.gdc = self.get_data('GDC/UKB.txt')
with open(self.get_data('dMRI/autoptx/struct_list.json'), 'r') as f:
self.tract_struct = json.load(f)
@property @property
def MNI(self): def MNI(self):
...@@ -84,54 +82,67 @@ def parseArguments(ctx): ...@@ -84,54 +82,67 @@ def parseArguments(ctx):
parser = MyParser(description='BioBank Pipeline Manager V. 2.0') parser = MyParser(description='BioBank Pipeline Manager V. 2.0')
parser.add_argument("subjectFolder", help='Subject Folder', action="store") parser.add_argument("subjectFolder", help='Subject Folder', action="store")
parser.add_argument("-q", "--queue", help='Queue modifier (default: normal)', parser.add_argument("-q", "--queue", help='Queue modifier (default: normal)',
action="store", nargs="?", dest="queue", default="normal") action="store", nargs="?", dest="queue", default="normal")
parser.add_argument("-n", "--normcheck", action="store_false", default=True, parser.add_argument("-n", "--normcheck", action="store_false", default=True,
help='Do NOT check Normalisation in structural image (default if flag not used: Check normalisation)', help='Do NOT check Normalisation in structural image '+\
'(default if flag not used: Check normalisation)',
dest="norm_check") dest="norm_check")
parser.add_argument("-P", "--namingPatterns", action="store", nargs="?", parser.add_argument("-P", "--namingPatterns", action="store", nargs="?",
default=ctx.get_data("config/naming_pattern_UKBB.json"), default=ctx.get_data("config/naming_pattern_UKBB.json"),
help='File with the naming patterns coming from dcm2niix (default: UKB naming patterns)', help='File with the naming patterns coming from ' +\
'dcm2niix (default: UKB naming patterns)',
dest="naming_patterns") dest="naming_patterns")
parser.add_argument("-c", "--coeff", action="store", nargs="?", parser.add_argument("-c", "--coeff", action="store", nargs="?",
default=ctx.get_data("GDC/UKB.txt"), default=ctx.get_data("GDC/UKB.txt"),
help='Coefficient file for the GDC (Gradient Distiortion Correction). \n' + help='Coefficient file for the GDC (Gradient ' +\
'Distiortion Correction). \n' +
' Options: \n' + ' Options: \n' +
' none--> No GDC is performed' + ' none--> No GDC is performed' +
' <path to file> --> Uses the user-pecified gradients file' + ' <path to file> --> Uses the user-pecified gradients file' +
' --> If this option is not used, the default is the UKB', ' --> If this option is not used, the default is the UKB',
dest="coeff") dest="coeff")
parser.add_argument("-C", "--coils_SWI", action="store", nargs="?", default=32, parser.add_argument("-C", "--coils_SWI",action="store",nargs="?",default=32,
help='Number of coils for SWI data. Default: 32. 0 means "no separate coil data"', help='Number of coils for SWI data. Default: 32. 0 ' +\
'means "no separate coil data"',
dest="coils_SWI") dest="coils_SWI")
parser.add_argument("-E", "--echoes_SWI", action="store", nargs="?", default=2, parser.add_argument("-E", "--echoes_SWI",action="store",nargs="?",default=2,
help='Number of echo times for SWI data (default: 2)', help='Number of echo times for SWI data (default: 2)',
dest="echoes_SWI") dest="echoes_SWI")
parser.add_argument("-Q", "--basic_QC_file", action="store", nargs="?", parser.add_argument("-Q", "--basic_QC_file", action="store", nargs="?",
default=ctx.get_data("config/ideal_config_sizes_UKBB.json"), default=ctx.get_data("config/ideal_config_sizes_UKBB.json"),
help='File with the ideal configuration of the files (default: UKB)', help='File with the ideal configuration of the files +'\
'(default: UKB)',
dest="basic_QC_file") dest="basic_QC_file")
parser.add_argument("-p", "--complex_phase", action="store_true", default=False, parser.add_argument("-p", "--complex_phase", action="store_true",
default=False,
help='SWI phase is complex (default: False)', help='SWI phase is complex (default: False)',
dest="complex_phase") dest="complex_phase")
parser.add_argument("-i", "--inverted_PED", action="store_true", default=False, parser.add_argument("-i", "--inverted_PED", action="store_true",
help='Use if the dMRI Phase Encoding Direction is inverted (default if flag not used: False)', default=False,
help='Use if the dMRI Phase Encoding Direction is '+\
'inverted (default if flag not used: False)',
dest="inverted_PED") dest="inverted_PED")
parser.add_argument("-b", "--b_value_shell", action="store", nargs="?", parser.add_argument("-b", "--b_value_shell", action="store", nargs="?",
default=1000, default=1000,
help='B value for the single shell data to be used (default: 1000)', help='B value for the single shell data to be used '+\
'(default: 1000)',
dest="b_value_shell") dest="b_value_shell")
parser.add_argument("-B", "--B_files", action="store", nargs="?", parser.add_argument("-B", "--B_files", action="store", nargs="?",
default="", default="",
help='Name of the directory with the bval and bvec files for dMRI data.\n' + help='Name of the directory with the bval and bvec '+\
'If specified, the directory needs to have these 4 files: \n' + 'files for dMRI data.\n' +
'If specified, the directory needs to have these'+\
' 4 files: \n' +
' - AP.bval\n ' + ' - AP.bval\n ' +
' - AP.bvec\n ' + ' - AP.bvec\n ' +
' - PA.bval\n ' + ' - PA.bval\n ' +
' - PA.bvec\n ' + ' - PA.bvec\n ' +
'If not set, the pipeline will use the dcm2niix generated files', 'If not set, the pipeline will use the dcm2niix '+\
'generated files',
dest="B_files") dest="B_files")
parser.add_argument("-S", "--num_shells", action="store", nargs="?", default=2, parser.add_argument("-S", "--num_shells",action="store",nargs="?",default=2,
help='Number of different shells (B-values) for dMRI data.', help='Number of different shells (B-values) '+\
'for dMRI data.',
dest="num_shells") dest="num_shells")
parser.add_argument("-X", "--exec_block", action="store", nargs="?", default=0, parser.add_argument("-X", "--exec_block", action="store", nargs="?", default=0,
help='Pipeline block(s) to execute: Option (default 0): \n' + help='Pipeline block(s) to execute: Option (default 0): \n' +
...@@ -320,12 +331,12 @@ def main(): ...@@ -320,12 +331,12 @@ def main():
setup_logging(op.join(ctx.subject, 'logs', 'main.log')) setup_logging(op.join(ctx.subject, 'logs', 'main.log'))
tree = FileTree.read(ctx.get_data('FileTree'), tree = FileTree.read(ctx.get_data('FileTree'),
subject=ctx.subject, subject=ctx.subject,
autoptx_tract=list(ctx.tract_struct.keys()), autoptx_tract=list(ctx.tract_struct.keys()),
netmats_dim=["25", "100"]) netmats_dim=["25", "100"])
# add submit parameters here that should # add submit parameters here that should
# be applied to all jobs in the pipeline # be applied to all jobs in the pipeline
pipe = Pipeline(default_submit=dict(logdir=Ref("logs_dir"), pipe = Pipeline(default_submit=dict(logdir=Ref("logs_dir"),
export_vars=list(os.environ.keys()))) export_vars=list(os.environ.keys())))
...@@ -334,7 +345,7 @@ def main(): ...@@ -334,7 +345,7 @@ def main():
#ctx.save_context(tree.get('config_file')) #ctx.save_context(tree.get('config_file'))
# This list will be filled with all desired outputs ... Later # This list will be filled with all desired outputs ... Later
targets = [] #targets = []
struct_T1.add_to_pipeline (ctx, pipe, tree) struct_T1.add_to_pipeline (ctx, pipe, tree)
struct_T2_FLAIR.add_to_pipeline(ctx, pipe, tree) struct_T2_FLAIR.add_to_pipeline(ctx, pipe, tree)
...@@ -349,8 +360,8 @@ def main(): ...@@ -349,8 +360,8 @@ def main():
# The skip-missing flag deals with cases where the subject is missing # The skip-missing flag deals with cases where the subject is missing
# the data of some modalities. For more details, check: # the data of some modalities. For more details, check:
# https://open.win.ox.ac.uk/pages/ndcn0236/pipe-tree/tutorial.html#dealing-with-missing-data # https://open.win.ox.ac.uk/pages/ndcn0236/pipe-tree/tutorial.html#dealing-with-missing-data
jobs = pipe.generate_jobs(tree).filter(targets, skip_missing=True) jobs = pipe.generate_jobs(tree).filter(None, skip_missing=True)
jobs.report() jobs.report()
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os
import os.path as op import os.path as op
import logging import logging
from fsl import wrappers from fsl import wrappers
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os
import os.path as op import os.path as op
import logging import logging
from fsl import wrappers from fsl import wrappers
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os
import os.path as op import os.path as op
import logging import logging
from shutil import copyfile from shutil import copyfile
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
# pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915 # pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915
# #
import os
import os.path as op import os.path as op
import logging import logging
from fsl import wrappers from fsl import wrappers
...@@ -32,7 +33,7 @@ def run(ctx, ...@@ -32,7 +33,7 @@ def run(ctx,
tmp_jac = op.join(tmp_dir, 'tmpjac.nii.gz') tmp_jac = op.join(tmp_dir, 'tmpjac.nii.gz')
tmp_mat = op.join(tmp_dir, 'tmp_mat.mat') tmp_mat = op.join(tmp_dir, 'tmp_mat.mat')
MC=ctx.FSLDIR + '/etc/flirtschop.join(tmp_dir, 'op.join(tmp_dir, 'measurecost1.sch' MC=ctx.FSLDIR + os.sep + op.join('etc', 'flirtsch', 'measurecost1.sch')
MNI152_T1_1mm_brain = ctx.get_standard("MNI152_T1_1mm_brain.nii.gz") MNI152_T1_1mm_brain = ctx.get_standard("MNI152_T1_1mm_brain.nii.gz")
MNI152_T1_1mm_brain_mask = ctx.get_standard("MNI152_T1_1mm_brain_mask.nii.gz") MNI152_T1_1mm_brain_mask = ctx.get_standard("MNI152_T1_1mm_brain_mask.nii.gz")
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
# pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915 # pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915
# #
import os
import os.path as op import os.path as op
import logging import logging
from fsl import wrappers from fsl import wrappers
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os
import os.path as op import os.path as op
import logging import logging
from pipe_tree import In, Out, Ref from pipe_tree import In, Out, Ref
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os
import os.path as op import os.path as op
import logging import logging
import nibabel as nib import nibabel as nib
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os
import os.path as op import os.path as op
import logging import logging
from pipe_tree import In, Out, Ref from pipe_tree import In, Out, Ref
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os
import os.path as op import os.path as op
import logging import logging
from fsl import wrappers from fsl import wrappers
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os
import os.path as op import os.path as op
import json import json
import logging import logging
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os
import os.path as op import os.path as op
import logging import logging
from pipe_tree import In, Out, Ref from pipe_tree import In, Out, Ref
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
# pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915 # pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915
# #
import os
import os.path as op import os.path as op
import json import json
import logging import logging
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
# pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915 # pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915
# #
import os
import os.path as op import os.path as op
import json import json
import logging import logging
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os.path as op
import logging import logging
from shutil import copyfile from shutil import copyfile
import numpy as np import numpy as np
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=E1130 # pylint: disable=E1130
# #
import os.path as op
import numpy as np import numpy as np
import nibabel as nib import nibabel as nib
......
...@@ -139,7 +139,7 @@ def fix_aseg_data(data_dict, subjectDir): ...@@ -139,7 +139,7 @@ def fix_aseg_data(data_dict, subjectDir):
# For some reason, the VentricleChoroidVol is not caught by asegstats2table # For some reason, the VentricleChoroidVol is not caught by asegstats2table
try: try:
file_name = op.join(subjectDir, 'stats' , 'aseg.stats') file_name = op.join(subjectDir, 'stats' , 'aseg.stats')
with open(, 'r', encoding="utf-8") as f: with open(file_name, 'r', encoding="utf-8") as f:
val=[x.split(',')[3].strip() for x in f.readlines() if 'VentricleChoroidVol' in x] val=[x.split(',')[3].strip() for x in f.readlines() if 'VentricleChoroidVol' in x]
except: except:
val=["NaN"] val=["NaN"]
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os
import os.path as op import os.path as op
import logging import logging
import nibabel as nib import nibabel as nib
......
...@@ -40,7 +40,7 @@ def run(ctx, ...@@ -40,7 +40,7 @@ def run(ctx,
T1_to_MNI_warp_coef: Out, T1_to_MNI_warp_coef: Out,
T1_to_MNI_warp_jac: Out): T1_to_MNI_warp_jac: Out):
with redirect_logging(job_name(run), outdir=logs_dir), with redirect_logging(job_name(run), outdir=logs_dir),\
tempdir(op.join(tmp_dir, job_name(run))): tempdir(op.join(tmp_dir, job_name(run))):
T1_tmp_1 = op.join(tmp_dir, 'T1_tmp_1.nii.gz') T1_tmp_1 = op.join(tmp_dir, 'T1_tmp_1.nii.gz')
...@@ -67,7 +67,7 @@ def run(ctx, ...@@ -67,7 +67,7 @@ def run(ctx,
#Generate the actual affine from the orig_ud volume to the cut version #Generate the actual affine from the orig_ud volume to the cut version
#we haveand combine it to have an affine matrix from orig_ud to MNI #we haveand combine it to have an affine matrix from orig_ud to MNI
wrappers.flirt(src=T1, ref=T1_orig_ud, omat=T1_to_T1_orig_ud_mat, wrappers.flirt(src=T1, ref=T1_orig_ud, omat=T1_to_T1_orig_ud_mat,
schedule = op.join(ctx.FSLDIR, 'etc', 'flirtsch', 'xyztrans.sch') schedule = op.join(ctx.FSLDIR, 'etc', 'flirtsch', 'xyztrans.sch'))
wrappers.invxfm(inmat=T1_to_T1_orig_ud_mat, omat=T1_orig_ud_to_T1_mat) wrappers.invxfm(inmat=T1_to_T1_orig_ud_mat, omat=T1_orig_ud_to_T1_mat)
wrappers.concatxfm(atob=T1_to_T1_orig_ud_mat,btoc=T1_orig_ud_to_std_mat, wrappers.concatxfm(atob=T1_to_T1_orig_ud_mat,btoc=T1_orig_ud_to_std_mat,
atoc=T1_to_MNI_linear_mat) atoc=T1_to_MNI_linear_mat)
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# pylint: disable=W0613 # pylint: disable=W0613
# #
import os.symlink import os
import os.path as op import os.path as op
import glob import glob
import logging import logging
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment