From ca6006cf4283add9fe9a77b68ec461ad9fb5231e Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Sat, 18 May 2024 10:23:05 -0400 Subject: [PATCH 1/7] Create init_ds_boldmask_wf. --- fmriprep/workflows/bold/outputs.py | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/fmriprep/workflows/bold/outputs.py b/fmriprep/workflows/bold/outputs.py index 3e561abe0..05f1f84ef 100644 --- a/fmriprep/workflows/bold/outputs.py +++ b/fmriprep/workflows/bold/outputs.py @@ -466,6 +466,50 @@ def init_ds_boldref_wf( return workflow +def init_ds_boldmask_wf( + *, + bids_root, + output_dir, + desc: str, + name='ds_boldmask_wf', +) -> pe.Workflow: + """Write out a BOLD mask.""" + workflow = pe.Workflow(name=name) + + inputnode = pe.Node( + niu.IdentityInterface(fields=['source_files', 'boldmask']), + name='inputnode', + ) + outputnode = pe.Node(niu.IdentityInterface(fields=['boldmask']), name='outputnode') + + raw_sources = pe.Node(niu.Function(function=_bids_relative), name="raw_sources") + raw_sources.inputs.bids_root = bids_root + + ds_boldmask = pe.Node( + DerivativesDataSink( + base_directory=output_dir, + desc=desc, + suffix='mask', + compress=True, + dismiss_entities=dismiss_echo(), + ), + name='ds_boldmask', + run_without_submitting=True, + ) + + workflow.connect([ + (inputnode, raw_sources, [('source_files', 'in_files')]), + (inputnode, ds_boldmask, [ + ('boldmask', 'in_file'), + ('source_files', 'source_file'), + ]), + (raw_sources, ds_boldmask, [('out', 'RawSources')]), + (ds_boldmask, outputnode, [('out_file', 'boldmask')]), + ]) # fmt:skip + + return workflow + + def init_ds_registration_wf( *, bids_root: str, From 6b8ea4456aa2783ec3afb620820f9281f9de6b81 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Sat, 18 May 2024 10:23:15 -0400 Subject: [PATCH 2/7] Write out boldref-space brain mask. --- fmriprep/workflows/bold/fit.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fmriprep/workflows/bold/fit.py b/fmriprep/workflows/bold/fit.py index f81285e62..971bbccf9 100644 --- a/fmriprep/workflows/bold/fit.py +++ b/fmriprep/workflows/bold/fit.py @@ -47,6 +47,7 @@ # BOLD workflows from .hmc import init_bold_hmc_wf from .outputs import ( + init_ds_boldmask_wf, init_ds_boldref_wf, init_ds_hmc_wf, init_ds_registration_wf, @@ -467,6 +468,12 @@ def init_bold_fit_wf( desc='coreg', name='ds_coreg_boldref_wf', ) + ds_boldmask_wf = init_ds_boldmask_wf( + bids_root=layout.root, + output_dir=config.execution.fmriprep_dir, + desc='brain', + name='ds_boldmask_wf', + ) # fmt:off workflow.connect([ @@ -474,6 +481,7 @@ def init_bold_fit_wf( (fmapref_buffer, enhance_boldref_wf, [("out", "inputnode.in_file")]), (fmapref_buffer, ds_coreg_boldref_wf, [("out", "inputnode.source_files")]), (ds_coreg_boldref_wf, regref_buffer, [("outputnode.boldref", "boldref")]), + (ds_boldmask_wf, regref_buffer, [('outputnode.boldmask', 'boldmask')]), (fmapref_buffer, func_fit_reports_wf, [("out", "inputnode.sdc_boldref")]), ]) # fmt:on @@ -557,8 +565,8 @@ def init_bold_fit_wf( (unwarp_wf, ds_coreg_boldref_wf, [ ('outputnode.corrected', 'inputnode.boldref'), ]), - (unwarp_wf, regref_buffer, [ - ('outputnode.corrected_mask', 'boldmask'), + (unwarp_wf, ds_boldmask_wf, [ + ('outputnode.corrected_mask', 'inputnode.boldmask'), ]), (fmap_select, func_fit_reports_wf, [("fmap_ref", "inputnode.fmap_ref")]), (fmap_select, summary, [("sdc_method", "distortion_correction")]), @@ -574,8 +582,8 @@ def init_bold_fit_wf( (enhance_boldref_wf, ds_coreg_boldref_wf, [ ('outputnode.bias_corrected_file', 'inputnode.boldref'), ]), - (enhance_boldref_wf, regref_buffer, [ - ('outputnode.mask_file', 'boldmask'), + (enhance_boldref_wf, ds_boldmask_wf, [ + ('outputnode.mask_file', 'inputnode.boldmask'), ]), ]) # fmt:on From 82d7bac41257e0cf9f779fccbdfc1a08327f40f2 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Sat, 18 May 2024 10:23:28 -0400 Subject: [PATCH 3/7] Update expected outputs. --- .circleci/ds005_fasttrack_outputs.txt | 4 ++++ .circleci/ds005_outputs.txt | 4 ++++ .circleci/ds005_partial_fasttrack_outputs.txt | 2 ++ .circleci/ds005_partial_outputs.txt | 2 ++ 4 files changed, 12 insertions(+) diff --git a/.circleci/ds005_fasttrack_outputs.txt b/.circleci/ds005_fasttrack_outputs.txt index 1b2052d68..2fdaea2e7 100644 --- a/.circleci/ds005_fasttrack_outputs.txt +++ b/.circleci/ds005_fasttrack_outputs.txt @@ -23,6 +23,8 @@ sub-01/anat/sub-01_hemi-R_desc-reg_sphere.surf.gii sub-01/anat/sub-01_hemi-R_space-fsLR_desc-msmsulc_sphere.surf.gii sub-01/anat/sub-01_hemi-R_space-fsLR_desc-reg_sphere.surf.gii sub-01/func +sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-brain_mask.json +sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-brain_mask.nii.gz sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-confounds_timeseries.json sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-confounds_timeseries.tsv sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-coreg_boldref.json @@ -41,6 +43,8 @@ sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsaverage5_bold.fun sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsaverage5_bold.json sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsnative_bold.func.gii sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsnative_bold.json +sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.json +sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.nii.gz sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.json sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.tsv sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-coreg_boldref.json diff --git a/.circleci/ds005_outputs.txt b/.circleci/ds005_outputs.txt index 1634090d5..9548adfaf 100644 --- a/.circleci/ds005_outputs.txt +++ b/.circleci/ds005_outputs.txt @@ -43,6 +43,8 @@ sub-01/anat/sub-01_label-CSF_probseg.nii.gz sub-01/anat/sub-01_label-GM_probseg.nii.gz sub-01/anat/sub-01_label-WM_probseg.nii.gz sub-01/func +sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-brain_mask.json +sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-brain_mask.nii.gz sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-confounds_timeseries.json sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-confounds_timeseries.tsv sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-coreg_boldref.json @@ -61,6 +63,8 @@ sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsaverage5_bold.fun sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsaverage5_bold.json sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsnative_bold.func.gii sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsnative_bold.json +sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.json +sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.nii.gz sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.json sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.tsv sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-coreg_boldref.json diff --git a/.circleci/ds005_partial_fasttrack_outputs.txt b/.circleci/ds005_partial_fasttrack_outputs.txt index 39533d137..243b1a8ab 100644 --- a/.circleci/ds005_partial_fasttrack_outputs.txt +++ b/.circleci/ds005_partial_fasttrack_outputs.txt @@ -51,6 +51,8 @@ sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-magnitude_fieldmap.nii.gz sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-preproc_fieldmap.json sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-preproc_fieldmap.nii.gz sub-01/func +sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.json +sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.nii.gz sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.json sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.tsv sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-coreg_boldref.json diff --git a/.circleci/ds005_partial_outputs.txt b/.circleci/ds005_partial_outputs.txt index 80e9078ca..b8909ad63 100644 --- a/.circleci/ds005_partial_outputs.txt +++ b/.circleci/ds005_partial_outputs.txt @@ -73,6 +73,8 @@ sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-magnitude_fieldmap.nii.gz sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-preproc_fieldmap.json sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-preproc_fieldmap.nii.gz sub-01/func +sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.json +sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.nii.gz sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.json sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.tsv sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-coreg_boldref.json From b63dbb6d089bbab3dd91ec332a9558cbb360d8c7 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Sat, 18 May 2024 11:42:37 -0400 Subject: [PATCH 4/7] Fix error. --- fmriprep/workflows/bold/fit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fmriprep/workflows/bold/fit.py b/fmriprep/workflows/bold/fit.py index 971bbccf9..60165189e 100644 --- a/fmriprep/workflows/bold/fit.py +++ b/fmriprep/workflows/bold/fit.py @@ -481,6 +481,7 @@ def init_bold_fit_wf( (fmapref_buffer, enhance_boldref_wf, [("out", "inputnode.in_file")]), (fmapref_buffer, ds_coreg_boldref_wf, [("out", "inputnode.source_files")]), (ds_coreg_boldref_wf, regref_buffer, [("outputnode.boldref", "boldref")]), + (fmapref_buffer, ds_boldmask_wf, [("out", "inputnode.source_files")]), (ds_boldmask_wf, regref_buffer, [('outputnode.boldmask', 'boldmask')]), (fmapref_buffer, func_fit_reports_wf, [("out", "inputnode.sdc_boldref")]), ]) From c4c10853724a041f672f9f043167450287756697 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Sat, 18 May 2024 11:42:52 -0400 Subject: [PATCH 5/7] Prevent double-sinking of boldref brain mask. --- fmriprep/workflows/bold/base.py | 3 --- fmriprep/workflows/bold/outputs.py | 24 +----------------------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/fmriprep/workflows/bold/base.py b/fmriprep/workflows/bold/base.py index 2643b8291..3c1548d27 100644 --- a/fmriprep/workflows/bold/base.py +++ b/fmriprep/workflows/bold/base.py @@ -325,9 +325,6 @@ def init_bold_wf( ds_bold_native_wf.inputs.inputnode.source_files = bold_series workflow.connect([ - (bold_fit_wf, ds_bold_native_wf, [ - ('outputnode.bold_mask', 'inputnode.bold_mask'), - ]), (bold_native_wf, ds_bold_native_wf, [ ('outputnode.bold_native', 'inputnode.bold'), ('outputnode.bold_echos', 'inputnode.bold_echos'), diff --git a/fmriprep/workflows/bold/outputs.py b/fmriprep/workflows/bold/outputs.py index 05f1f84ef..93791db80 100644 --- a/fmriprep/workflows/bold/outputs.py +++ b/fmriprep/workflows/bold/outputs.py @@ -482,7 +482,7 @@ def init_ds_boldmask_wf( ) outputnode = pe.Node(niu.IdentityInterface(fields=['boldmask']), name='outputnode') - raw_sources = pe.Node(niu.Function(function=_bids_relative), name="raw_sources") + raw_sources = pe.Node(niu.Function(function=_bids_relative), name='raw_sources') raw_sources.inputs.bids_root = bids_root ds_boldmask = pe.Node( @@ -619,7 +619,6 @@ def init_ds_bold_native_wf( fields=[ 'source_files', 'bold', - 'bold_mask', 'bold_echos', 't2star', ] @@ -631,27 +630,6 @@ def init_ds_bold_native_wf( raw_sources.inputs.bids_root = bids_root workflow.connect(inputnode, 'source_files', raw_sources, 'in_files') - # Masks should be output if any other derivatives are output - ds_bold_mask = pe.Node( - DerivativesDataSink( - base_directory=output_dir, - desc='brain', - suffix='mask', - compress=True, - dismiss_entities=dismiss_echo(), - ), - name='ds_bold_mask', - run_without_submitting=True, - mem_gb=DEFAULT_MEMORY_MIN_GB, - ) - workflow.connect([ - (inputnode, ds_bold_mask, [ - ('source_files', 'source_file'), - ('bold_mask', 'in_file'), - ]), - (raw_sources, ds_bold_mask, [('out', 'RawSources')]), - ]) # fmt:skip - if bold_output: ds_bold = pe.Node( DerivativesDataSink( From d9c64967a8c01622f5cfca8a0cb37cc9aadb91b2 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Sat, 18 May 2024 12:21:38 -0400 Subject: [PATCH 6/7] Set brain mask's datatype. --- fmriprep/workflows/bold/outputs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fmriprep/workflows/bold/outputs.py b/fmriprep/workflows/bold/outputs.py index 93791db80..fe06798a3 100644 --- a/fmriprep/workflows/bold/outputs.py +++ b/fmriprep/workflows/bold/outputs.py @@ -488,6 +488,7 @@ def init_ds_boldmask_wf( ds_boldmask = pe.Node( DerivativesDataSink( base_directory=output_dir, + datatype='func', desc=desc, suffix='mask', compress=True, From 7a0cdd022dc2c6a197f6dda0d7114146a70f0b69 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Mon, 20 May 2024 09:59:24 -0400 Subject: [PATCH 7/7] Address review. --- fmriprep/workflows/bold/fit.py | 2 +- fmriprep/workflows/bold/outputs.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/fmriprep/workflows/bold/fit.py b/fmriprep/workflows/bold/fit.py index 60165189e..e5b1961b2 100644 --- a/fmriprep/workflows/bold/fit.py +++ b/fmriprep/workflows/bold/fit.py @@ -474,6 +474,7 @@ def init_bold_fit_wf( desc='brain', name='ds_boldmask_wf', ) + ds_boldmask_wf.inputs.inputnode.source_files = [bold_file] # fmt:off workflow.connect([ @@ -481,7 +482,6 @@ def init_bold_fit_wf( (fmapref_buffer, enhance_boldref_wf, [("out", "inputnode.in_file")]), (fmapref_buffer, ds_coreg_boldref_wf, [("out", "inputnode.source_files")]), (ds_coreg_boldref_wf, regref_buffer, [("outputnode.boldref", "boldref")]), - (fmapref_buffer, ds_boldmask_wf, [("out", "inputnode.source_files")]), (ds_boldmask_wf, regref_buffer, [('outputnode.boldmask', 'boldmask')]), (fmapref_buffer, func_fit_reports_wf, [("out", "inputnode.sdc_boldref")]), ]) diff --git a/fmriprep/workflows/bold/outputs.py b/fmriprep/workflows/bold/outputs.py index fe06798a3..93791db80 100644 --- a/fmriprep/workflows/bold/outputs.py +++ b/fmriprep/workflows/bold/outputs.py @@ -488,7 +488,6 @@ def init_ds_boldmask_wf( ds_boldmask = pe.Node( DerivativesDataSink( base_directory=output_dir, - datatype='func', desc=desc, suffix='mask', compress=True,