From d815d7f8a533e711941fd32d89048aa41eb5b3ac Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Sun, 15 Oct 2023 16:49:15 -0400 Subject: [PATCH] Update outputs.py --- xcp_d/workflows/outputs.py | 83 +++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/xcp_d/workflows/outputs.py b/xcp_d/workflows/outputs.py index 9a64dfc93..e9f0132de 100644 --- a/xcp_d/workflows/outputs.py +++ b/xcp_d/workflows/outputs.py @@ -395,36 +395,50 @@ def _custom_to_source(out_file): ]) # fmt:on - ds_temporal_mask = pe.Node( - DerivativesDataSink( - base_directory=output_dir, - dismiss_entities=["atlas", "den", "res", "space", "cohort", "desc"], - suffix="outliers", - extension=".tsv", - source_file=name_source, - # Metadata - Threshold=fd_thresh, - ), - name="ds_temporal_mask", + merge_dense_src = pe.Node( + niu.Merge(numinputs=(1 + (1 if fd_thresh > 0 else 0) + (1 if params != "none" else 0))), + name="merge_dense_src", run_without_submitting=True, mem_gb=1, ) - # fmt:off - workflow.connect([ - (inputnode, ds_temporal_mask, [ - ("temporal_mask_metadata", "meta_dict"), - ("temporal_mask", "in_file"), - ]), - (ds_filtered_motion, ds_temporal_mask, [ - (("out_file", _postproc_to_source, output_dir), "Sources"), - ]), - (ds_temporal_mask, outputnode, [("out_file", "temporal_mask")]), - ]) - # fmt:on + merge_dense_src.inputs.in1 = preproc_bold_src + + if fd_thresh > 0: + ds_temporal_mask = pe.Node( + DerivativesDataSink( + base_directory=output_dir, + dismiss_entities=["atlas", "den", "res", "space", "cohort", "desc"], + suffix="outliers", + extension=".tsv", + source_file=name_source, + # Metadata + Threshold=fd_thresh, + ), + name="ds_temporal_mask", + run_without_submitting=True, + mem_gb=1, + ) + # fmt:off + workflow.connect([ + (inputnode, ds_temporal_mask, [ + ("temporal_mask_metadata", "meta_dict"), + ("temporal_mask", "in_file"), + ]), + (ds_filtered_motion, ds_temporal_mask, [ + (("out_file", _postproc_to_source, output_dir), "Sources"), + ]), + (ds_temporal_mask, outputnode, [("out_file", "temporal_mask")]), + (ds_temporal_mask, merge_dense_src, [ + (("out_file", _postproc_to_source, output_dir), "in2"), + ]), + ]) + # fmt:on if params != "none": confounds_src = pe.Node( - niu.Merge(numinputs=3 if custom_confounds_file else 2), + niu.Merge( + numinputs=(1 + (1 if fd_thresh > 0 else 0) + (1 if custom_confounds_file else 0)) + ), name="confounds_src", run_without_submitting=True, mem_gb=1, @@ -436,7 +450,7 @@ def _custom_to_source(out_file): (("out_file", _postproc_to_source, output_dir), "in2"), ]), ]) - # fmt:on + # fmt:off if custom_confounds_file: confounds_src.inputs.in3 = _custom_to_source(custom_confounds_file) @@ -456,25 +470,12 @@ def _custom_to_source(out_file): workflow.connect([ (inputnode, ds_confounds, [("confounds_file", "in_file")]), (confounds_src, ds_confounds, [("out", "Sources")]), + (ds_confounds, merge_dense_src, [ + (("out_file", _postproc_to_source, output_dir), f"in{3 if fd_thresh > 0 else 2}"), + ]), ]) # fmt:on - merge_dense_src = pe.Node( - niu.Merge(numinputs=3), - name="merge_dense_src", - run_without_submitting=True, - mem_gb=1, - ) - merge_dense_src.inputs.in1 = preproc_bold_src - # fmt:off - workflow.connect([ - (ds_confounds, merge_dense_src, [(("out_file", _postproc_to_source, output_dir), "in2")]), - (ds_temporal_mask, merge_dense_src, [ - (("out_file", _postproc_to_source, output_dir), "in3"), - ]), - ]) - # fmt:on - # Write out derivatives via DerivativesDataSink ds_denoised_bold = pe.Node( DerivativesDataSink(