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
#!/usr/bin/env python
#
# struct_T2_FLAIR.py - Pipeline with the T2 FLAIR 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_T2_FLAIR import T2_FLAIR_gdc, T2_FLAIR_brain_extract
from bip.pipelines.struct_T2_FLAIR import T2_FLAIR_defacing, T2_FLAIR_apply_bfc
from bip.pipelines.struct_T2_FLAIR import T2_FLAIR_bianca
log = logging.getLogger(__name__)
def add_to_pipeline(ctx, pipe, tree):
subj = ctx.subject
pipe(T2_FLAIR_gdc.run,
submit=dict(jobtime=200, name=job_name(T2_FLAIR_gdc.run, subj)),
kwargs={'ctx' : ctx})
pipe(T2_FLAIR_brain_extract.run,
submit=dict(jobtime=200, name=job_name(T2_FLAIR_brain_extract.run,
subj)),
kwargs={'ctx' : ctx})
pipe(T2_FLAIR_defacing.run,
submit=dict(jobtime=200, name=job_name(T2_FLAIR_defacing.run, subj)),
kwargs={'ctx' : ctx})
pipe(T2_FLAIR_apply_bfc.run,
submit=dict(jobtime=200, name=job_name(T2_FLAIR_apply_bfc.run, subj)),
kwargs={'ctx' : ctx})
pipe(T2_FLAIR_bianca.run,
submit=dict(jobtime=200, name=job_name(T2_FLAIR_bianca.run, subj)),
kwargs={'ctx' : ctx})
#!/usr/bin/env python
#
# struct_T2_FLAIR.py - Pipeline with the T2 FLAIR 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_T2_FLAIR import T2_FLAIR_gdc, T2_FLAIR_brain_extract
from bip.pipelines.struct_T2_FLAIR import T2_FLAIR_defacing, T2_FLAIR_apply_bfc
from bip.pipelines.struct_T2_FLAIR import T2_FLAIR_bianca
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_T2_FLAIR', outdir=logs_dir):
pipe(T2_FLAIR_gdc.run,
submit=dict(jobtime=200, name="BIP_T2_FLAIR_gdc_" + subj),
kwargs={'ctx' : ctx})
targets.append('T2_FLAIR_orig_ud_warp')
pipe(T2_FLAIR_brain_extract.run,
submit=dict(jobtime=200, name="BIP_T2_FLAIR_brain_extract_" + subj),
kwargs={'ctx' : ctx})
targets.append('T2_FLAIR_brain')
pipe(T2_FLAIR_defacing.run,
submit=dict(jobtime=200, name="BIP_T2_FLAIR_defacing_" + subj),
kwargs={'ctx' : ctx})
targets.append('T2_FLAIR_defacing_mask')
pipe(T2_FLAIR_apply_bfc.run,
submit=dict(jobtime=200, name="BIP_T2_FLAIR_apply_bfc_" + subj),
kwargs={'ctx' : ctx})
targets.append('T2_FLAIR_unbiased_brain')
pipe(T2_FLAIR_bianca.run,
submit=dict(jobtime=200, name="BIP_T2_FLAIR_bianca_" + subj),
kwargs={'ctx' : ctx})
targets.append('T2_FLAIR_bianca_volume')
return pipe, targets
...@@ -7,28 +7,22 @@ ...@@ -7,28 +7,22 @@
# 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_asl import asl_proc, asl_get_IDPs from bip.pipelines.struct_asl import asl_proc, asl_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(asl_proc.run,
submit=dict(jobtime=200, name=job_name(asl_proc.run, subj)),
with redirect_logging('pipe_struct_asl', outdir=logs_dir): kwargs={'ctx' : ctx})
pipe(asl_proc.run, pipe(asl_get_IDPs.run,
submit=dict(jobtime=200, name="BIP_asl_proc_" + subj), submit=dict(jobtime=200, name=job_name(asl_get_IDPs.run, subj)),
kwargs={'ctx' : ctx}) kwargs={'ctx' : ctx})
targets.append('region_analysis_gm_csv')
pipe(asl_get_IDPs.run,
submit=dict(jobtime=200, name="BIP_asl_get_IDPs_" + subj),
kwargs={'ctx' : ctx})
targets.append('ASL_IDPs')
return pipe, targets
...@@ -22,7 +22,7 @@ def run(ctx, ...@@ -22,7 +22,7 @@ def run(ctx,
ASL_region_analysis_dir: Ref, ASL_region_analysis_dir: Ref,
ASL_IDPs: Out): ASL_IDPs: Out):
with redirect_logging('asl_get_IDPs', outdir=logs_dir): with redirect_logging(job_name(run), outdir=logs_dir):
result = ctx.subject result = ctx.subject
......
...@@ -55,7 +55,7 @@ def run(ctx, ...@@ -55,7 +55,7 @@ def run(ctx,
ASL_std_ACBV_calib: Out, ASL_std_ACBV_calib: Out,
region_analysis_gm_csv: Out): region_analysis_gm_csv: Out):
with redirect_logging('asl_proc', outdir=logs_dir): with redirect_logging(job_name(run), outdir=logs_dir):
BBASL_ROI_DIR = ctx.get_data("asl/ukb_rois/") BBASL_ROI_DIR = ctx.get_data("asl/ukb_rois/")
......
...@@ -7,24 +7,19 @@ ...@@ -7,24 +7,19 @@
# 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_swMRI import swMRI_proc from bip.pipelines.struct_swMRI import swMRI_proc
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(swMRI_proc.run,
submit=dict(jobtime=200, name=job_name(swMRI_proc.run, subj)),
with redirect_logging('pipe_struct_swMRI', outdir=logs_dir): kwargs={'ctx' : ctx})
pipe(swMRI_proc.run,
submit=dict(jobtime=200, name="BIP_swMRI_proc_" + subj),
kwargs={'ctx' : ctx})
targets.append('SWI')
return pipe, targets
...@@ -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
......
...@@ -51,7 +51,7 @@ def run(ctx, ...@@ -51,7 +51,7 @@ def run(ctx,
T1_to_SWI_mat: Out, T1_to_SWI_mat: Out,
filtered_phase: Out): filtered_phase: Out):
with redirect_logging('swMRI_proc', outdir=logs_dir): with redirect_logging(job_name(run), outdir=logs_dir):
with open(SWI_num_coils, 'r', encoding="utf-8") as f: with open(SWI_num_coils, 'r', encoding="utf-8") as f:
num_coils = int(f.read()) num_coils = int(f.read())
......
...@@ -22,13 +22,10 @@ from subprocess import check_output ...@@ -22,13 +22,10 @@ from subprocess import check_output
from fsl import wrappers from fsl import wrappers
def run_command(logger, command, **kwargs): This fails def run_command(logger, command, **kwargs):
#def run_command(logger, command, env):
try: try:
logger.info(command.strip()) logger.info(command.strip())
# This fails
job_output = check_output(command,shell=True,**kwargs).decode('UTF-8') job_output = check_output(command,shell=True,**kwargs).decode('UTF-8')
#job_output = check_output(command,shell=True,env=env).decode('UTF-8')
logger.info('Output: \t' + job_output.strip()) logger.info('Output: \t' + job_output.strip())
except Exception as e: except Exception as e:
...@@ -40,6 +37,10 @@ def run_command(logger, command, **kwargs): This fails ...@@ -40,6 +37,10 @@ def run_command(logger, command, **kwargs): This fails
return job_output.strip() return job_output.strip()
def job_name(function, *args):
func = function.__module__.removeprefix('bip.pipelines.')
return '_'.join([func] + list(args))
def create_formatter(): def create_formatter():
"""Create a logging.Formatter. """ """Create a logging.Formatter. """
......
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