diff --git a/bip/main.py b/bip/main.py index ab6ef498f3e84a658386b7d34db30310040d642c..b23e0258c35787af1ea8ba34a8cd8c21aeb1fd07 100755 --- a/bip/main.py +++ b/bip/main.py @@ -12,7 +12,6 @@ import sys import logging import argparse import json -from dataclasses import dataclass, field from file_tree import FileTree from pipe_tree import Pipeline, Ref import bip @@ -35,18 +34,17 @@ class Usage(Exception): def __init__(self, msg): self.msg = msg -@dataclass 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: - tract_struct = json.load(f) + def __init__(self, subject=""): - def __post_init__(self): - self.gdc = self.get_data('GDC/UKB.txt') + self.subject = subject + 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 def MNI(self): @@ -84,54 +82,67 @@ def parseArguments(ctx): parser = MyParser(description='BioBank Pipeline Manager V. 2.0') parser.add_argument("subjectFolder", help='Subject Folder', action="store") 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, - 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") parser.add_argument("-P", "--namingPatterns", action="store", nargs="?", 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") parser.add_argument("-c", "--coeff", action="store", nargs="?", 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' + - ' none--> No GDC is performed' + - ' <path to file> --> Uses the user-pecified gradients file' + - ' --> If this option is not used, the default is the UKB', + ' none--> No GDC is performed' + + ' <path to file> --> Uses the user-pecified gradients file' + + ' --> If this option is not used, the default is the UKB', dest="coeff") - 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"', + 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"', 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)', dest="echoes_SWI") parser.add_argument("-Q", "--basic_QC_file", action="store", nargs="?", 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") - 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)', dest="complex_phase") - parser.add_argument("-i", "--inverted_PED", action="store_true", default=False, - help='Use if the dMRI Phase Encoding Direction is inverted (default if flag not used: False)', + parser.add_argument("-i", "--inverted_PED", action="store_true", + default=False, + help='Use if the dMRI Phase Encoding Direction is '+\ + 'inverted (default if flag not used: False)', dest="inverted_PED") parser.add_argument("-b", "--b_value_shell", action="store", nargs="?", 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") parser.add_argument("-B", "--B_files", action="store", nargs="?", default="", - help='Name of the directory with the bval and bvec files for dMRI data.\n' + - 'If specified, the directory needs to have these 4 files: \n' + + help='Name of the directory with the bval and bvec '+\ + 'files for dMRI data.\n' + + 'If specified, the directory needs to have these'+\ + ' 4 files: \n' + ' - AP.bval\n ' + ' - AP.bvec\n ' + ' - PA.bval\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") - parser.add_argument("-S", "--num_shells", action="store", nargs="?", default=2, - help='Number of different shells (B-values) for dMRI data.', + parser.add_argument("-S", "--num_shells",action="store",nargs="?",default=2, + help='Number of different shells (B-values) '+\ + 'for dMRI data.', dest="num_shells") parser.add_argument("-X", "--exec_block", action="store", nargs="?", default=0, help='Pipeline block(s) to execute: Option (default 0): \n' + @@ -320,12 +331,12 @@ def main(): 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, autoptx_tract=list(ctx.tract_struct.keys()), netmats_dim=["25", "100"]) - # add submit parameters here that should + # add submit parameters here that should # be applied to all jobs in the pipeline pipe = Pipeline(default_submit=dict(logdir=Ref("logs_dir"), export_vars=list(os.environ.keys()))) @@ -334,7 +345,7 @@ def main(): #ctx.save_context(tree.get('config_file')) # This list will be filled with all desired outputs ... Later - targets = [] + #targets = [] struct_T1.add_to_pipeline (ctx, pipe, tree) struct_T2_FLAIR.add_to_pipeline(ctx, pipe, tree) @@ -349,8 +360,8 @@ def main(): # The skip-missing flag deals with cases where the subject is missing # 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 - jobs = pipe.generate_jobs(tree).filter(targets, skip_missing=True) + # https://open.win.ox.ac.uk/pages/ndcn0236/pipe-tree/tutorial.html#dealing-with-missing-data + jobs = pipe.generate_jobs(tree).filter(None, skip_missing=True) jobs.report() diff --git a/bip/pipelines/IDPs_gen/IDP_SWI_T2star.py b/bip/pipelines/IDPs_gen/IDP_SWI_T2star.py index 910599531a2446157172fd92ca2a2b1465620529..d030aa850460a7b9e643c3cc73f50d0953641ffe 100755 --- a/bip/pipelines/IDPs_gen/IDP_SWI_T2star.py +++ b/bip/pipelines/IDPs_gen/IDP_SWI_T2star.py @@ -10,7 +10,6 @@ # pylint: disable=W0613 # -import os import os.path as op import logging from fsl import wrappers diff --git a/bip/pipelines/IDPs_gen/IDP_T1_FIRST_vols.py b/bip/pipelines/IDPs_gen/IDP_T1_FIRST_vols.py index 3aed0f4ea9919bf7c5d6446cd396f95f43500471..7b270d5bb32ae4d7a81a4f1f319bdc87704f149e 100755 --- a/bip/pipelines/IDPs_gen/IDP_T1_FIRST_vols.py +++ b/bip/pipelines/IDPs_gen/IDP_T1_FIRST_vols.py @@ -10,7 +10,6 @@ # pylint: disable=W0613 # -import os import os.path as op import logging from fsl import wrappers diff --git a/bip/pipelines/IDPs_gen/IDP_T1_SIENAX.py b/bip/pipelines/IDPs_gen/IDP_T1_SIENAX.py index bf275eb27d6ad57be80189fd2ce190546cb3f55e..ec2b6e4dcf22618f8b513a53d795c79fde2f7928 100755 --- a/bip/pipelines/IDPs_gen/IDP_T1_SIENAX.py +++ b/bip/pipelines/IDPs_gen/IDP_T1_SIENAX.py @@ -10,7 +10,6 @@ # pylint: disable=W0613 # -import os import os.path as op import logging from shutil import copyfile diff --git a/bip/pipelines/IDPs_gen/IDP_T1_align_to_std.py b/bip/pipelines/IDPs_gen/IDP_T1_align_to_std.py index c598f210e92a0a1c3392cef2cd38ae5e44422792..b5a51cd0d9fe7cbbbdbcd5ce5fadcddea03c3715 100755 --- a/bip/pipelines/IDPs_gen/IDP_T1_align_to_std.py +++ b/bip/pipelines/IDPs_gen/IDP_T1_align_to_std.py @@ -9,6 +9,7 @@ # pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915 # +import os import os.path as op import logging from fsl import wrappers @@ -32,7 +33,7 @@ def run(ctx, tmp_jac = op.join(tmp_dir, 'tmpjac.nii.gz') 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_mask = ctx.get_standard("MNI152_T1_1mm_brain_mask.nii.gz") diff --git a/bip/pipelines/IDPs_gen/IDP_all_align_to_T1.py b/bip/pipelines/IDPs_gen/IDP_all_align_to_T1.py index dbfac5e3cda68d783157633fdc5e3f949cba1a43..f33de1d6c4863ab3f72a97ca049853c6d0690460 100755 --- a/bip/pipelines/IDPs_gen/IDP_all_align_to_T1.py +++ b/bip/pipelines/IDPs_gen/IDP_all_align_to_T1.py @@ -9,7 +9,6 @@ # pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915 # -import os import os.path as op import logging from fsl import wrappers diff --git a/bip/pipelines/IDPs_gen/IDP_diff_TBSS.py b/bip/pipelines/IDPs_gen/IDP_diff_TBSS.py index b12d1c2ec2c63c84b3137e56f1cd227edef05ad6..342ca92c8f404c56393ba62e1dfa5a50997ae8be 100755 --- a/bip/pipelines/IDPs_gen/IDP_diff_TBSS.py +++ b/bip/pipelines/IDPs_gen/IDP_diff_TBSS.py @@ -10,7 +10,6 @@ # pylint: disable=W0613 # -import os import os.path as op import logging from pipe_tree import In, Out, Ref diff --git a/bip/pipelines/IDPs_gen/IDP_diff_autoPtx.py b/bip/pipelines/IDPs_gen/IDP_diff_autoPtx.py index eb2751059a8d7d0b0ae29e60da92aa8d1e3ae348..33988057a4140a5f562395454d5fba878de69dd3 100755 --- a/bip/pipelines/IDPs_gen/IDP_diff_autoPtx.py +++ b/bip/pipelines/IDPs_gen/IDP_diff_autoPtx.py @@ -10,7 +10,6 @@ # pylint: disable=W0613 # -import os import os.path as op import logging import nibabel as nib diff --git a/bip/pipelines/IDPs_gen/IDP_diff_eddy_outliers.py b/bip/pipelines/IDPs_gen/IDP_diff_eddy_outliers.py index a27c5d7352fd01487cd57fb15ce047ffab6add0a..063c89292ff73badf53dd73de0d412af88aa9b1e 100755 --- a/bip/pipelines/IDPs_gen/IDP_diff_eddy_outliers.py +++ b/bip/pipelines/IDPs_gen/IDP_diff_eddy_outliers.py @@ -10,7 +10,6 @@ # pylint: disable=W0613 # -import os import os.path as op import logging from pipe_tree import In, Out, Ref diff --git a/bip/pipelines/IDPs_gen/IDP_func_TSNR.py b/bip/pipelines/IDPs_gen/IDP_func_TSNR.py index 9c68babe0a713b051f0510feceaf930c7f8be915..047762b1e81a4abcb43a1bcbab9f3647c3533987 100755 --- a/bip/pipelines/IDPs_gen/IDP_func_TSNR.py +++ b/bip/pipelines/IDPs_gen/IDP_func_TSNR.py @@ -10,7 +10,6 @@ # pylint: disable=W0613 # -import os import os.path as op import logging from fsl import wrappers diff --git a/bip/pipelines/IDPs_gen/IDP_func_head_motion.py b/bip/pipelines/IDPs_gen/IDP_func_head_motion.py index ec5c137c5f89bbfa002ecc34bb47c947c3dab939..2685a07e6b824dd76223cd806c4e35948e6cb32a 100755 --- a/bip/pipelines/IDPs_gen/IDP_func_head_motion.py +++ b/bip/pipelines/IDPs_gen/IDP_func_head_motion.py @@ -10,7 +10,6 @@ # pylint: disable=W0613 # -import os import os.path as op import json import logging diff --git a/bip/pipelines/IDPs_gen/IDP_subject_COG_table.py b/bip/pipelines/IDPs_gen/IDP_subject_COG_table.py index ef09016ce0c751782d74a55cdcb53f291a19813f..80cbb70d86cdb313a0ab9658e2e7c951f081911a 100755 --- a/bip/pipelines/IDPs_gen/IDP_subject_COG_table.py +++ b/bip/pipelines/IDPs_gen/IDP_subject_COG_table.py @@ -10,7 +10,6 @@ # pylint: disable=W0613 # -import os import os.path as op import logging from pipe_tree import In, Out, Ref diff --git a/bip/pipelines/IDPs_gen/IDP_subject_centre.py b/bip/pipelines/IDPs_gen/IDP_subject_centre.py index c18932409b999891e822b8adafd5d5bfcf97e473..dbdcbde57d14625adb3c27aedc6ce0b24d43919c 100755 --- a/bip/pipelines/IDPs_gen/IDP_subject_centre.py +++ b/bip/pipelines/IDPs_gen/IDP_subject_centre.py @@ -9,7 +9,6 @@ # pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915 # -import os import os.path as op import json import logging diff --git a/bip/pipelines/IDPs_gen/IDPs_generator.py b/bip/pipelines/IDPs_gen/IDPs_generator.py index a4ba81554d3f6ed4bbb79e724b850b5f46c6afe6..cf4c32ad449bd39d323b4dbfdfbff75becda4998 100755 --- a/bip/pipelines/IDPs_gen/IDPs_generator.py +++ b/bip/pipelines/IDPs_gen/IDPs_generator.py @@ -9,7 +9,6 @@ # pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915 # -import os import os.path as op import json import logging diff --git a/bip/pipelines/dMRI_diff/diff_dtifit.py b/bip/pipelines/dMRI_diff/diff_dtifit.py index a6a900e8b8d01745b004aaf3c5b51b4a75da6370..ea4cc46f2611c0a43e9f5b3ba979cd0f24fb9b0c 100755 --- a/bip/pipelines/dMRI_diff/diff_dtifit.py +++ b/bip/pipelines/dMRI_diff/diff_dtifit.py @@ -10,7 +10,6 @@ # pylint: disable=W0613 # -import os.path as op import logging from shutil import copyfile import numpy as np diff --git a/bip/pipelines/fMRI_rest/rfMRI_netmats_fnc.py b/bip/pipelines/fMRI_rest/rfMRI_netmats_fnc.py index 106575f1fb8281cb4fbcdc4581c5292f5701541b..398f03288c3a8999cf1a4e56092472f2afb6c9fe 100755 --- a/bip/pipelines/fMRI_rest/rfMRI_netmats_fnc.py +++ b/bip/pipelines/fMRI_rest/rfMRI_netmats_fnc.py @@ -10,7 +10,6 @@ # pylint: disable=E1130 # -import os.path as op import numpy as np import nibabel as nib diff --git a/bip/pipelines/struct_FS/FS_get_IDPs_fnc.py b/bip/pipelines/struct_FS/FS_get_IDPs_fnc.py index 44fef49b535ea503a9676a75ba515fe14cd8b42e..273294f6de208aa0c5f18291e1d8655c7e091ada 100755 --- a/bip/pipelines/struct_FS/FS_get_IDPs_fnc.py +++ b/bip/pipelines/struct_FS/FS_get_IDPs_fnc.py @@ -139,7 +139,7 @@ def fix_aseg_data(data_dict, subjectDir): # For some reason, the VentricleChoroidVol is not caught by asegstats2table try: 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] except: val=["NaN"] diff --git a/bip/pipelines/struct_T1/T1_QC_CNR_eyes.py b/bip/pipelines/struct_T1/T1_QC_CNR_eyes.py index 3637366a7b3fecc7395fecb9ffcf15ef51533996..0b9f7824fc57985775f573b41909353341d7c3c8 100755 --- a/bip/pipelines/struct_T1/T1_QC_CNR_eyes.py +++ b/bip/pipelines/struct_T1/T1_QC_CNR_eyes.py @@ -10,7 +10,6 @@ # pylint: disable=W0613 # -import os import os.path as op import logging import nibabel as nib diff --git a/bip/pipelines/struct_T1/T1_brain_extract.py b/bip/pipelines/struct_T1/T1_brain_extract.py index f4b1d03329734ecbaaa75bff07f262c9a4481efa..c2aa51d8c17ed6004feff0fc2a76f41cc8c42a03 100755 --- a/bip/pipelines/struct_T1/T1_brain_extract.py +++ b/bip/pipelines/struct_T1/T1_brain_extract.py @@ -40,7 +40,7 @@ def run(ctx, T1_to_MNI_warp_coef: 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))): T1_tmp_1 = op.join(tmp_dir, 'T1_tmp_1.nii.gz') @@ -67,7 +67,7 @@ def run(ctx, #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 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.concatxfm(atob=T1_to_T1_orig_ud_mat,btoc=T1_orig_ud_to_std_mat, atoc=T1_to_MNI_linear_mat) diff --git a/bip/pipelines/struct_T1/T1_first.py b/bip/pipelines/struct_T1/T1_first.py index 193e1073a9f047f4b5bbd0d10232e927f656ded1..3a94f71abbb56c47cc5da50d39b4a1ac95d443c2 100755 --- a/bip/pipelines/struct_T1/T1_first.py +++ b/bip/pipelines/struct_T1/T1_first.py @@ -10,7 +10,7 @@ # pylint: disable=W0613 # -import os.symlink +import os import os.path as op import glob import logging diff --git a/bip/pipelines/struct_T1/T1_sienax.py b/bip/pipelines/struct_T1/T1_sienax.py index eb2230206ba718531e0333394228ffa55e612de8..5a226bd8c0c9e03bf6110da93e847f1a916e8d5f 100755 --- a/bip/pipelines/struct_T1/T1_sienax.py +++ b/bip/pipelines/struct_T1/T1_sienax.py @@ -47,10 +47,6 @@ def run(ctx, T1_tmp_mat_2 = op.join(tmp_dir, 'tmp_mat_2.mat') T1_tmp_mat_3 = op.join(tmp_dir, 'tmp_mat_3.mat') - FSLDIR = ctx.FSLDIR - FSLDATA = FSLDIR + '/data' - FSLMNI = FSLDATA + '/standard' - MNI = ctx.get_standard('MNI152_T1_1mm.nii.gz') MNI_2mm_brain = ctx.get_standard('MNI152_T1_2mm_brain.nii.gz') MNI_2mm_skull = ctx.get_standard('MNI152_T1_2mm_skull.nii.gz') diff --git a/bip/pipelines/struct_T2_FLAIR/T2_FLAIR_apply_bfc.py b/bip/pipelines/struct_T2_FLAIR/T2_FLAIR_apply_bfc.py index 3ed955aaabb42603b43932ce1ffde386e245fe09..e60003f1b3109f1cf15db1212b1340786a057fed 100755 --- a/bip/pipelines/struct_T2_FLAIR/T2_FLAIR_apply_bfc.py +++ b/bip/pipelines/struct_T2_FLAIR/T2_FLAIR_apply_bfc.py @@ -11,7 +11,6 @@ # pylint: disable=W0613 # -import os import os.path as op import logging from fsl import wrappers diff --git a/bip/pipelines/struct_T2_FLAIR/T2_FLAIR_bianca.py b/bip/pipelines/struct_T2_FLAIR/T2_FLAIR_bianca.py index 5d02a50aeb5c1f90e5a986e120e37b3e1bde8b4b..1cfbfec9e2a42e82de179a5932b559c685222274 100755 --- a/bip/pipelines/struct_T2_FLAIR/T2_FLAIR_bianca.py +++ b/bip/pipelines/struct_T2_FLAIR/T2_FLAIR_bianca.py @@ -9,7 +9,6 @@ # pylint: disable=W0613,C0301 # -import os.path as op import logging from shutil import copyfile from pipe_tree import In, Out, Ref diff --git a/bip/pipelines/struct_swMRI/swMRI_proc.py b/bip/pipelines/struct_swMRI/swMRI_proc.py index 08c5b20430d93e8d36665740934d98f40d849719..7ff4aa5b92b2a227f59523c6a92ccfae7c65be59 100755 --- a/bip/pipelines/struct_swMRI/swMRI_proc.py +++ b/bip/pipelines/struct_swMRI/swMRI_proc.py @@ -10,7 +10,6 @@ # pylint: disable=W0613,R0912 # -import os import os.path as op import logging from shutil import copyfile