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

General refactoring

parent 753adb16
No related branches found
No related tags found
No related merge requests found
Showing
with 651 additions and 81 deletions
This diff is collapsed.
...@@ -26,7 +26,7 @@ def run(ctx, ...@@ -26,7 +26,7 @@ def run(ctx,
fsaverage: Ref, fsaverage: Ref,
rh_entorhinal_exvivo_label: Out): rh_entorhinal_exvivo_label: Out):
with redirect_logging('FS_proc', outdir=logs_dir): with redirect_logging(job_name(run), outdir=logs_dir):
# We need to delete the folder because otherwise, FreeSurfer complains # We need to delete the folder because otherwise, FreeSurfer complains
if os.path.exists(FreeSurfer_dir): if os.path.exists(FreeSurfer_dir):
......
...@@ -25,7 +25,7 @@ def run(ctx, ...@@ -25,7 +25,7 @@ def run(ctx,
FreeSurfer_dir: Ref, FreeSurfer_dir: Ref,
ThalamicNuclei: Out): ThalamicNuclei: Out):
with redirect_logging('FS_segm', outdir=logs_dir): with redirect_logging(job_name(run), outdir=logs_dir):
env = dict(os.environ, SUBJECTS_DIR=os.getcwd() + "/" + ctx.subject) env = dict(os.environ, SUBJECTS_DIR=os.getcwd() + "/" + ctx.subject)
......
...@@ -7,32 +7,25 @@ ...@@ -7,32 +7,25 @@
# Author: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk> # Author: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk>
# #
# pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915 # pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915
# pylint: disable=W0613
# #
import logging import logging
from bip.utils.log_utils import redirect_logging from bip.utils.log_utils import job_name
from bip.pipelines.struct_FS import FS_proc, FS_segm, FS_get_IDPs from bip.pipelines.struct_FS import FS_proc, FS_segm, FS_get_IDPs
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def add_to_pipeline(ctx, pipe, tree, targets): def add_to_pipeline(ctx, pipe, tree):
logs_dir=tree.get('logs_dir') subj = ctx.subject
subj = ctx.subject pipe(FS_proc.run,
submit=dict(jobtime=200, name=job_name(FS_proc.run, subj)),
with redirect_logging('pipe_struct_FS', outdir=logs_dir): kwargs={'ctx' : ctx})
pipe(FS_proc.run, pipe(FS_segm.run,
submit=dict(jobtime=200, name="BIP_FS_proc_" + subj), submit=dict(jobtime=200, name=job_name(FS_segm.run, subj)),
kwargs={'ctx' : ctx}) kwargs={'ctx' : ctx})
targets.append('rh_entorhinal_exvivo_label') pipe(FS_get_IDPs.run,
pipe(FS_segm.run, submit=dict(jobtime=200, name=job_name(FS_get_IDPs.run, subj)),
submit=dict(jobtime=200, name="BIP_FS_segm_" + subj), kwargs={'ctx' : ctx})
kwargs={'ctx' : ctx})
targets.append('ThalamicNuclei')
pipe(FS_get_IDPs.run,
submit=dict(jobtime=200, name="BIP_FS_get_IDPs_" + subj),
kwargs={'ctx' : ctx})
targets.append('FS_IDPs')
return pipe, targets
...@@ -30,7 +30,7 @@ def run(ctx, ...@@ -30,7 +30,7 @@ def run(ctx,
logs_dir: Ref, logs_dir: Ref,
tmp_dir: Ref): tmp_dir: Ref):
with redirect_logging('T1_QC_CNR_corners', outdir=logs_dir),\ with redirect_logging(job_name(run), outdir=logs_dir),\
tempdir(tmp_dir): tempdir(tmp_dir):
roi_1_1 = tmp_dir + '/roi_1_1.nii.gz' roi_1_1 = tmp_dir + '/roi_1_1.nii.gz'
......
...@@ -40,7 +40,7 @@ def run(ctx, ...@@ -40,7 +40,7 @@ def run(ctx,
logs_dir: Ref, logs_dir: Ref,
tmp_dir: Ref): tmp_dir: Ref):
with redirect_logging('T1_QC_CNR_eyes', outdir=logs_dir),\ with redirect_logging(job_name(run), outdir=logs_dir),\
tempdir(tmp_dir): tempdir(tmp_dir):
T1_brain_GM_mask_orig = tmp_dir + '/T1_brain_GM_mask_orig.nii.gz' T1_brain_GM_mask_orig = tmp_dir + '/T1_brain_GM_mask_orig.nii.gz'
......
...@@ -24,7 +24,7 @@ def run(ctx, ...@@ -24,7 +24,7 @@ def run(ctx,
logs_dir: Ref, logs_dir: Ref,
tmp_dir: Ref): tmp_dir: Ref):
with redirect_logging('T1_QC_COG', outdir=logs_dir),\ with redirect_logging(job_name(run), outdir=logs_dir),\
tempdir(tmp_dir): tempdir(tmp_dir):
T1_tmp_5 = tmp_dir + '/T1_tmp_5.nii.gz' T1_tmp_5 = tmp_dir + '/T1_tmp_5.nii.gz'
......
...@@ -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('T1_brain_extract', outdir=logs_dir),tempdir(tmp_dir): with redirect_logging(job_name(run), outdir=logs_dir), tempdir(tmp_dir):
T1_tmp_1 = tmp_dir + '/T1_tmp_1.nii.gz' T1_tmp_1 = tmp_dir + '/T1_tmp_1.nii.gz'
T1_tmp_2 = tmp_dir + '/T1_tmp_2.nii.gz' T1_tmp_2 = tmp_dir + '/T1_tmp_2.nii.gz'
......
...@@ -28,7 +28,7 @@ def run(ctx, ...@@ -28,7 +28,7 @@ def run(ctx,
logs_dir: Ref, logs_dir: Ref,
tmp_dir: Ref): tmp_dir: Ref):
with redirect_logging('T1_defacing', outdir=logs_dir),\ with redirect_logging(job_name(run), outdir=logs_dir),\
tempdir(tmp_dir): tempdir(tmp_dir):
T1_tmp_4 = tmp_dir + '/T1_tmp_4.nii.gz' T1_tmp_4 = tmp_dir + '/T1_tmp_4.nii.gz'
......
...@@ -33,7 +33,7 @@ def run(ctx, ...@@ -33,7 +33,7 @@ def run(ctx,
T1_fast_WM_mask: Out, T1_fast_WM_mask: Out,
T1_fast_brain_bias: Out): T1_fast_brain_bias: Out):
with redirect_logging('T1_fast', outdir=logs_dir): with redirect_logging(job_name(run), outdir=logs_dir):
#Run fast #Run fast
wrappers.fast(T1_brain, out = T1_fast_dir + '/T1_brain', b=True) wrappers.fast(T1_brain, out = T1_fast_dir + '/T1_brain', b=True)
......
...@@ -27,7 +27,7 @@ def run(ctx, ...@@ -27,7 +27,7 @@ def run(ctx,
logs_dir: Ref, logs_dir: Ref,
T1_first_all_fast_firstseg: Out): T1_first_all_fast_firstseg: Out):
with redirect_logging('T1_first', outdir=logs_dir): with redirect_logging(job_name(run), outdir=logs_dir):
# Creates a link inside T1_first to T1_unbiased_brain.nii.gz # Creates a link inside T1_first to T1_unbiased_brain.nii.gz
if not os.path.exists(T1_first_unbiased_brain): if not os.path.exists(T1_first_unbiased_brain):
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
import logging import logging
from shutil import copyfile from shutil import copyfile
from pipe_tree import In, Out, Ref from pipe_tree import In, Out, Ref
from bip.utils.log_utils import redirect_logging from bip.utils.log_utils import redirect_logging, job_name
from gradunwarp.core.gradient_unwarp_apply import gradient_unwarp_apply from gradunwarp.core.gradient_unwarp_apply import gradient_unwarp_apply
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -24,7 +24,7 @@ def run(ctx, ...@@ -24,7 +24,7 @@ def run(ctx,
logs_dir: Ref, logs_dir: Ref,
T1_GDC: Ref): T1_GDC: Ref):
with redirect_logging('T1_gdc', outdir=logs_dir): with redirect_logging(job_name(run), outdir=logs_dir):
if ctx.gdc != '': if ctx.gdc != '':
#Calculate and apply the Gradient Distortion Unwarp #Calculate and apply the Gradient Distortion Unwarp
......
...@@ -39,7 +39,7 @@ def run(ctx, ...@@ -39,7 +39,7 @@ def run(ctx,
logs_dir: Ref, logs_dir: Ref,
tmp_dir: Ref): tmp_dir: Ref):
with redirect_logging('T1_sienax', outdir=logs_dir),\ with redirect_logging(job_name(run), outdir=logs_dir),\
tempdir(tmp_dir): tempdir(tmp_dir):
T1_tmp_mat_1 = tmp_dir + '/tmp_mat_1.mat' T1_tmp_mat_1 = tmp_dir + '/tmp_mat_1.mat'
......
#!/usr/bin/env python
#
# struct_T1.py - Pipeline with the T1w processing.
#
# Author: Fidel Alfaro Almagro <fidel.alfaroalmagro@ndcn.ox.ac.uk>
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
# Author: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk>
#
# pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915
# pylint: disable=W0613
#
import logging
from bip.utils.log_utils import job_name
from bip.pipelines.struct_T1 import T1_gdc, T1_brain_extract, T1_defacing
from bip.pipelines.struct_T1 import T1_fast, T1_first, T1_sienax, T1_QC_COG
from bip.pipelines.struct_T1 import T1_QC_CNR_corners, T1_QC_CNR_eyes
log = logging.getLogger(__name__)
def add_to_pipeline(ctx, pipe, tree):
subj = ctx.subject
pipe(T1_gdc.run,
submit=dict(jobtime=200, name=job_name(T1_gdc.run, subj)),
kwargs={'ctx' : ctx})
pipe(T1_brain_extract.run,
submit=dict(jobtime=200, name=job_name(T1_brain_extract.run, subj)),
kwargs={'ctx' : ctx})
pipe(T1_defacing.run,
submit=dict(jobtime=200, name=job_name(T1_defacing.run, subj)),
kwargs={'ctx' : ctx})
pipe(T1_fast.run,
submit=dict(jobtime=200, name=job_name(T1_fast.run, subj)),
kwargs={'ctx' : ctx})
pipe(T1_first.run,
submit=dict(jobtime=200, name=job_name(T1_first.run, subj)),
kwargs={'ctx' : ctx})
pipe(T1_sienax.run,
submit=dict(jobtime=200, name=job_name(T1_sienax.run, subj)),
kwargs={'ctx' : ctx})
pipe(T1_QC_COG.run,
submit=dict(jobtime=200, name=job_name(T1_QC_COG.run, subj)),
kwargs={'ctx' : ctx})
pipe(T1_QC_CNR_corners.run,
submit=dict(jobtime=200, name=job_name(T1_QC_CNR_corners.run, subj)),
kwargs={'ctx' : ctx})
pipe(T1_QC_CNR_eyes.run,
submit=dict(jobtime=200, name=job_name(T1_QC_CNR_eyes.run, subj)),
kwargs={'ctx' : ctx})
#!/usr/bin/env python
#
# struct_T1.py - Pipeline with the T1w processing.
#
# Author: Fidel Alfaro Almagro <fidel.alfaroalmagro@ndcn.ox.ac.uk>
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
# Author: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk>
#
# pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915
#
import logging
from bip.utils.log_utils import redirect_logging
from bip.pipelines.struct_T1 import T1_gdc, T1_brain_extract, T1_defacing
from bip.pipelines.struct_T1 import T1_fast, T1_first, T1_sienax, T1_QC_COG
from bip.pipelines.struct_T1 import T1_QC_CNR_corners, T1_QC_CNR_eyes
log = logging.getLogger(__name__)
def add_to_pipeline(ctx, pipe, tree, targets):
logs_dir=tree.get('logs_dir')
subj = ctx.subject
with redirect_logging('pipe_struct_T1', outdir=logs_dir):
pipe(T1_gdc.run,
submit=dict(jobtime=200, name="BIP_T1_gdc_" + subj),
kwargs={'ctx' : ctx})
targets.append('T1_orig_ud_warp')
pipe(T1_brain_extract.run,
submit=dict(jobtime=200, name="BIP_T1_brain_extract_" + subj),
kwargs={'ctx' : ctx})
targets.append('T1_brain')
pipe(T1_defacing.run,
submit=dict(jobtime=200, name="BIP_T1_defacing_" + subj),
kwargs={'ctx' : ctx})
targets.append('T1_QC_face_mask_inside_brain_mask')
pipe(T1_fast.run,
submit=dict(jobtime=200, name="BIP_T1_fast_" + subj),
kwargs={'ctx' : ctx})
targets.append('T1_unbiased_brain')
pipe(T1_first.run,
submit=dict(jobtime=200, name="BIP_T1_first_" + subj),
kwargs={'ctx' : ctx})
targets.append('T1_first_all_fast_firstseg')
pipe(T1_sienax.run,
submit=dict(jobtime=200, name="BIP_T1_sienax_" + subj),
kwargs={'ctx' : ctx})
targets.append('T1_sienax_report')
pipe(T1_QC_COG.run,
submit=dict(jobtime=200, name="BIP_T1_QC_COG_" + subj),
kwargs={'ctx' : ctx})
targets.append('T1_QC_COG')
pipe(T1_QC_CNR_corners.run,
submit=dict(jobtime=200, name="BIP_T1_QC_CNR_corners_" + subj),
kwargs={'ctx' : ctx})
targets.append('T1_notNorm_QC_CNR_upper')
pipe(T1_QC_CNR_eyes.run,
submit=dict(jobtime=200, name="BIP_T1_QC_CNR_eyes_" + subj),
kwargs={'ctx' : ctx})
targets.append('T1_QC_CNR_eyes')
return pipe, targets
...@@ -27,7 +27,7 @@ def run(ctx, ...@@ -27,7 +27,7 @@ def run(ctx,
T2_FLAIR_unbiased: Out, T2_FLAIR_unbiased: Out,
T2_FLAIR_unbiased_brain: Out): T2_FLAIR_unbiased_brain: Out):
with redirect_logging('T2_FLAIR_apply_bfc', outdir=logs_dir): with redirect_logging(job_name(run), outdir=logs_dir):
#Apply bias field correction to T2_FLAIR warped #Apply bias field correction to T2_FLAIR warped
if os.path.isfile(T1_fast_brain_bias): if os.path.isfile(T1_fast_brain_bias):
......
...@@ -44,7 +44,7 @@ def run(ctx, ...@@ -44,7 +44,7 @@ def run(ctx,
T2_FLAIR_bianca_tot_pvent_deep_volume: Out, T2_FLAIR_bianca_tot_pvent_deep_volume: Out,
T2_FLAIR_bianca_volume: Out): T2_FLAIR_bianca_volume: Out):
with redirect_logging('T2_FLAIR_bianca', outdir=logs_dir): with redirect_logging(job_name(run), outdir=logs_dir):
# Create bianca mask # Create bianca mask
wrappers.make_bianca_mask(T1_unbiased, T1_fast_pve_0, wrappers.make_bianca_mask(T1_unbiased, T1_fast_pve_0,
......
...@@ -38,7 +38,7 @@ def run(ctx, ...@@ -38,7 +38,7 @@ def run(ctx,
logs_dir: Ref, logs_dir: Ref,
tmp_dir: Ref): tmp_dir: Ref):
with redirect_logging('T2_FLAIR_brain_extract', outdir=logs_dir),\ with redirect_logging(job_name(run), outdir=logs_dir),\
tempdir(tmp_dir): tempdir(tmp_dir):
T2_FLAIR_tmp_1_mat = tmp_dir + '/T2_FLAIR_tmp_1.mat' T2_FLAIR_tmp_1_mat = tmp_dir + '/T2_FLAIR_tmp_1.mat'
......
...@@ -31,7 +31,7 @@ def run(ctx, ...@@ -31,7 +31,7 @@ def run(ctx,
logs_dir: Ref, logs_dir: Ref,
tmp_dir: Ref): tmp_dir: Ref):
with redirect_logging('T2_FLAIR_defacing', outdir=logs_dir),\ with redirect_logging(job_name(run), outdir=logs_dir),\
tempdir(tmp_dir): tempdir(tmp_dir):
T2_FLAIR_tmp_1 = tmp_dir + '/T2_FLAIR_tmp_1nii.gz' T2_FLAIR_tmp_1 = tmp_dir + '/T2_FLAIR_tmp_1nii.gz'
......
...@@ -25,7 +25,7 @@ def run(ctx, ...@@ -25,7 +25,7 @@ def run(ctx,
logs_dir: Ref, logs_dir: Ref,
T2_FLAIR_GDC: Ref): T2_FLAIR_GDC: Ref):
with redirect_logging('T2_FLAIR_gdc', outdir=logs_dir): with redirect_logging(job_name(run), outdir=logs_dir):
if ctx.gdc != '': if ctx.gdc != '':
#Calculate and apply the Gradient Distortion Unwarp #Calculate and apply the Gradient Distortion Unwarp
......
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