Skip to content

Commit

Permalink
Replace fmt:on and fmt:off with fmt:skip (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo authored Dec 9, 2023
1 parent 09efa26 commit 28fe6b4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 66 deletions.
24 changes: 6 additions & 18 deletions aslprep/workflows/asl/cbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,14 +711,12 @@ def init_parcellate_cbf_wf(
merge_xforms = pe.Node(niu.Merge(3), name="merge_xforms")
merge_xforms.inputs.in1 = MNI152NLin6Asym_to_MNI152NLin2009cAsym

# fmt:off
workflow.connect([
(inputnode, merge_xforms, [
("MNI152NLin2009cAsym_to_anat_xfm", "in2"),
("aslref2anat_xfm", "in3"),
]),
])
# fmt:on
]) # fmt:skip

# Using the generated transforms, apply them to get everything in the correct MNI form
warp_atlases_to_asl_space = pe.MapNode(
Expand All @@ -735,13 +733,11 @@ def init_parcellate_cbf_wf(
n_procs=omp_nthreads,
)

# fmt:off
workflow.connect([
(inputnode, warp_atlases_to_asl_space, [("asl_mask", "reference_image")]),
(atlas_file_grabber, warp_atlases_to_asl_space, [("atlas_file", "input_image")]),
(merge_xforms, warp_atlases_to_asl_space, [("out", "transforms")]),
])
# fmt:on
]) # fmt:skip

for cbf_type in cbf_3d:
parcellate_cbf = pe.MapNode(
Expand All @@ -751,16 +747,14 @@ def init_parcellate_cbf_wf(
mem_gb=mem_gb,
)

# fmt:off
workflow.connect([
(inputnode, parcellate_cbf, [
(cbf_type, "in_file"),
("asl_mask", "mask"),
]),
(atlas_file_grabber, parcellate_cbf, [("atlas_labels_file", "atlas_labels")]),
(warp_atlases_to_asl_space, parcellate_cbf, [("output_image", "atlas")]),
])
# fmt:on
]) # fmt:skip

ds_cbf = pe.MapNode(
DerivativesDataSink(
Expand Down Expand Up @@ -829,7 +823,6 @@ def init_parcellate_cbf_wf(
run_without_submitting=True,
)

# fmt:off
workflow.connect([
(inputnode, ds_atlas, [("source_file", "source_file")]),
(atlas_file_grabber, ds_atlas, [("atlas_file", "in_file")]),
Expand All @@ -840,8 +833,7 @@ def init_parcellate_cbf_wf(
("suffix", "suffix"),
("extension", "extension"),
]),
])
# fmt:on
]) # fmt:skip

ds_atlas_labels_file = pe.MapNode(
DerivativesDataSink(
Expand All @@ -867,16 +859,14 @@ def init_parcellate_cbf_wf(
run_without_submitting=True,
)

# fmt:off
workflow.connect([
(inputnode, ds_atlas_labels_file, [("source_file", "source_file")]),
(atlas_file_grabber, ds_atlas_labels_file, [("atlas_labels_file", "in_file")]),
(get_atlas_entities, ds_atlas_labels_file, [
("atlas", "atlas"),
("suffix", "suffix"),
]),
])
# fmt:on
]) # fmt:skip

ds_atlas_metadata = pe.MapNode(
DerivativesDataSink(
Expand All @@ -902,15 +892,13 @@ def init_parcellate_cbf_wf(
run_without_submitting=True,
)

# fmt:off
workflow.connect([
(inputnode, ds_atlas_metadata, [("source_file", "source_file")]),
(atlas_file_grabber, ds_atlas_metadata, [("atlas_metadata_file", "in_file")]),
(get_atlas_entities, ds_atlas_metadata, [
("atlas", "atlas"),
("suffix", "suffix"),
]),
])
# fmt:on
]) # fmt:skip

return workflow
4 changes: 1 addition & 3 deletions aslprep/workflows/asl/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ def init_carpetplot_wf(
if cifti_output:
workflow.connect(inputnode, "cifti_asl", conf_plot, "in_cifti")

# fmt:off
workflow.connect([
(inputnode, mrg_xfms, [
("aslref2anat_xfm", "in1"),
Expand All @@ -449,8 +448,7 @@ def init_carpetplot_wf(
(parcels, conf_plot, [("out", "in_segm")]),
(conf_plot, ds_report_asl_conf, [("out_file", "in_file")]),
(conf_plot, outputnode, [("out_file", "out_carpetplot")]),
])
# fmt:on
]) # fmt:skip
return workflow


Expand Down
46 changes: 13 additions & 33 deletions aslprep/workflows/asl/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ def init_asl_fit_wf(
output_dir=config.execution.aslprep_dir,
)

# fmt:off
workflow.connect([
# XXX: Was from hmc_aslref_wf
(inputnode, hmcref_buffer, [("dummy_scans", "dummy_scans")]),
Expand Down Expand Up @@ -355,8 +354,7 @@ def init_asl_fit_wf(
("aslref2anat_xfm", "inputnode.aslref2anat_xfm"),
]),
(summary, asl_fit_reports_wf, [("out_report", "inputnode.summary_report")]),
])
# fmt:on
]) # fmt:skip

# Stage 1: Generate motion correction aslref
if not have_hmcref:
Expand All @@ -380,7 +378,6 @@ def init_asl_fit_wf(
)
ds_hmc_aslref_wf.inputs.inputnode.source_files = [asl_file]

# fmt:off
workflow.connect([
(hmc_aslref_wf, hmcref_buffer, [
("outputnode.asl_file", "asl_file"),
Expand All @@ -390,8 +387,7 @@ def init_asl_fit_wf(
(hmc_aslref_wf, asl_fit_reports_wf, [
("outputnode.validation_report", "inputnode.validation_report"),
]),
])
# fmt:on
]) # fmt:skip
else:
config.loggers.workflow.info("Found HMC aslref - skipping Stage 1")

Expand All @@ -400,12 +396,10 @@ def init_asl_fit_wf(

hmcref_buffer.inputs.aslref = precomputed["hmc_aslref"]

# fmt:off
workflow.connect([
(validate_asl, hmcref_buffer, [("out_file", "asl_file")]),
(validate_asl, asl_fit_reports_wf, [("out_report", "inputnode.validation_report")]),
])
# fmt:on
]) # fmt:skip

# Reduce the ASL series to only include volumes that need to be processed.
processing_target = pe.Node(
Expand All @@ -421,14 +415,13 @@ def init_asl_fit_wf(
ReduceASLFiles(metadata=metadata),
name="reduce_asl_file",
)
# fmt:off

workflow.connect([
(inputnode, processing_target, [("aslcontext", "aslcontext")]),
(inputnode, reduce_asl_file, [("aslcontext", "aslcontext")]),
(processing_target, reduce_asl_file, [("processing_target", "processing_target")]),
(hmcref_buffer, reduce_asl_file, [("asl_file", "asl_file")]),
])
# fmt:on
]) # fmt:skip

# Stage 2: Estimate head motion
if not hmc_xforms:
Expand All @@ -451,7 +444,6 @@ def init_asl_fit_wf(
ds_hmc_wf.get_node("ds_xforms").inputs.datatype = "perf"
ds_hmc_wf.get_node("ds_xforms").inputs.to = "aslref"

# fmt:off
workflow.connect([
(hmcref_buffer, asl_hmc_wf, [("aslref", "inputnode.raw_ref_image")]),
(reduce_asl_file, asl_hmc_wf, [
Expand All @@ -464,8 +456,7 @@ def init_asl_fit_wf(
("outputnode.movpar_file", "movpar_file"),
("outputnode.rmsd_file", "rmsd_file"),
]),
])
# fmt:on
]) # fmt:skip
else:
config.loggers.workflow.info("Found motion correction transforms - skipping Stage 2")
hmc_buffer.inputs.hmc_xforms = hmc_xforms
Expand All @@ -486,15 +477,13 @@ def init_asl_fit_wf(
name="ds_coreg_aslref_wf",
)

# fmt:off
workflow.connect([
(hmcref_buffer, fmapref_buffer, [("aslref", "aslref_files")]),
(fmapref_buffer, enhance_aslref_wf, [("out", "inputnode.in_file")]),
(fmapref_buffer, ds_coreg_aslref_wf, [("out", "inputnode.source_files")]),
(ds_coreg_aslref_wf, regref_buffer, [("outputnode.aslref", "aslref")]),
(fmapref_buffer, asl_fit_reports_wf, [("out", "inputnode.sdc_aslref")]),
])
# fmt:on
]) # fmt:skip

if fieldmap_id:
fmap_select = pe.Node(
Expand Down Expand Up @@ -527,7 +516,6 @@ def init_asl_fit_wf(
name="ds_fmapreg_wf",
)

# fmt:off
workflow.connect([
(enhance_aslref_wf, fmapreg_wf, [
("outputnode.bias_corrected_file", "inputnode.target_ref"),
Expand All @@ -541,8 +529,7 @@ def init_asl_fit_wf(
(itk_mat2txt, ds_fmapreg_wf, [("out_xfm", "inputnode.xform")]),
(fmapref_buffer, ds_fmapreg_wf, [("out", "inputnode.source_files")]),
(ds_fmapreg_wf, fmapreg_buffer, [("outputnode.xform", "aslref2fmap_xfm")]),
])
# fmt:on
]) # fmt:skip
else:
fmapreg_buffer.inputs.aslref2fmap_xfm = aslref2fmap_xform

Expand All @@ -553,7 +540,6 @@ def init_asl_fit_wf(
)
unwarp_wf.inputs.inputnode.metadata = layout.get_metadata(asl_file)

# fmt:off
workflow.connect([
(inputnode, fmap_select, [
("fmap_ref", "fmap_ref"),
Expand Down Expand Up @@ -581,17 +567,14 @@ def init_asl_fit_wf(
("aslref2fmap_xfm", "inputnode.aslref2fmap_xfm"),
]),
(unwarp_wf, asl_fit_reports_wf, [("outputnode.fieldmap", "inputnode.fieldmap")]),
])
# fmt:on
]) # fmt:skip
else:
# fmt:off
workflow.connect([
(enhance_aslref_wf, ds_coreg_aslref_wf, [
("outputnode.bias_corrected_file", "inputnode.aslref"),
]),
(enhance_aslref_wf, regref_buffer, [("outputnode.mask_file", "aslmask")]),
])
# fmt:on
]) # fmt:skip
else:
config.loggers.workflow.info("Found coregistration reference - skipping Stage 3")
regref_buffer.inputs.aslref = precomputed["coreg_aslref"]
Expand Down Expand Up @@ -620,7 +603,6 @@ def init_asl_fit_wf(
name="ds_aslreg_wf",
)

# fmt:off
workflow.connect([
(inputnode, asl_reg_wf, [
("t1w_preproc", "inputnode.t1w_preproc"),
Expand All @@ -637,8 +619,7 @@ def init_asl_fit_wf(
(asl_reg_wf, ds_aslreg_wf, [("outputnode.itk_bold_to_t1", "inputnode.xform")]),
(ds_aslreg_wf, outputnode, [("outputnode.xform", "aslref2anat_xfm")]),
(asl_reg_wf, summary, [("outputnode.fallback", "fallback")]),
])
# fmt:on
]) # fmt:skip
else:
outputnode.inputs.aslref2anat_xfm = aslref2anat_xform

Expand Down Expand Up @@ -789,7 +770,7 @@ def init_asl_native_wf(
ReduceASLFiles(metadata=metadata),
name="reduce_asl_file",
)
# fmt:off

workflow.connect([
(inputnode, processing_target, [("aslcontext", "aslcontext")]),
(processing_target, reduce_asl_file, [("processing_target", "processing_target")]),
Expand All @@ -800,8 +781,7 @@ def init_asl_native_wf(
("aslcontext", "aslcontext"),
("metadata", "metadata"),
]),
])
# fmt:on
]) # fmt:skip

# Prepare fieldmap metadata
if fieldmap_id:
Expand Down
16 changes: 4 additions & 12 deletions aslprep/workflows/asl/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ def init_asl_fit_reports_wf(
mem_gb=1,
)

# fmt:off
workflow.connect([
(inputnode, ds_summary, [
("source_file", "source_file"),
Expand All @@ -303,8 +302,7 @@ def init_asl_fit_reports_wf(
("aslref2anat_xfm", "transforms"),
]),
(t1w_wm, aslref_wm, [("out", "input_image")]),
])
# fmt:on
]) # fmt:skip

# Reportlets follow the structure of init_asl_fit_wf stages
# - SDC1:
Expand Down Expand Up @@ -376,7 +374,6 @@ def init_asl_fit_reports_wf(
name="ds_sdc_report",
)

# fmt:off
workflow.connect([
(inputnode, fmapref_aslref, [
("fmap_ref", "input_image"),
Expand All @@ -397,8 +394,7 @@ def init_asl_fit_reports_wf(
(aslref_wm, sdc_report, [("output_image", "wm_seg")]),
(inputnode, ds_sdc_report, [("source_file", "source_file")]),
(sdc_report, ds_sdc_report, [("out_report", "in_file")]),
])
# fmt:on
]) # fmt:skip

# EPI-T1 registration
# Resample T1w image onto EPI-space
Expand All @@ -424,15 +420,13 @@ def init_asl_fit_reports_wf(
name="ds_epi_t1_report",
)

# fmt:off
workflow.connect([
(inputnode, epi_t1_report, [("coreg_aslref", "after")]),
(t1w_aslref, epi_t1_report, [("output_image", "before")]),
(aslref_wm, epi_t1_report, [("output_image", "wm_seg")]),
(inputnode, ds_epi_t1_report, [("source_file", "source_file")]),
(epi_t1_report, ds_epi_t1_report, [("out_report", "in_file")]),
])
# fmt:on
]) # fmt:skip

return workflow

Expand Down Expand Up @@ -468,7 +462,6 @@ def init_ds_aslref_wf(
run_without_submitting=True,
)

# fmt:off
workflow.connect([
(inputnode, raw_sources, [("source_files", "in_files")]),
(inputnode, ds_aslref, [
Expand All @@ -477,8 +470,7 @@ def init_ds_aslref_wf(
]),
(raw_sources, ds_aslref, [("out", "RawSources")]),
(ds_aslref, outputnode, [("out_file", "aslref")]),
])
# fmt:on
]) # fmt:skip

return workflow

Expand Down

0 comments on commit 28fe6b4

Please sign in to comment.