Skip to content

Commit cb80f4f

Browse files
authored
FIX: Write out boldref-space brain mask with minimal level (#3292)
Closes #3290. Changes proposed in this pull request - Create `init_ds_boldmask_wf` workflow. This might be overkill. - Write out the boldref-space brain mask in `init_bold_fit_wf`. - Stop writing out boldref-space brain mask in `init_ds_bold_native_wf`, since it's written out in `init_bold_fit_wf` now. - Update expected outputs.
1 parent 6c95ebe commit cb80f4f

File tree

7 files changed

+69
-29
lines changed

7 files changed

+69
-29
lines changed

.circleci/ds005_fasttrack_outputs.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ sub-01/anat/sub-01_hemi-R_desc-reg_sphere.surf.gii
2323
sub-01/anat/sub-01_hemi-R_space-fsLR_desc-msmsulc_sphere.surf.gii
2424
sub-01/anat/sub-01_hemi-R_space-fsLR_desc-reg_sphere.surf.gii
2525
sub-01/func
26+
sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-brain_mask.json
27+
sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-brain_mask.nii.gz
2628
sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-confounds_timeseries.json
2729
sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-confounds_timeseries.tsv
2830
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
4143
sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsaverage5_bold.json
4244
sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsnative_bold.func.gii
4345
sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsnative_bold.json
46+
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.json
47+
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.nii.gz
4448
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.json
4549
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.tsv
4650
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-coreg_boldref.json

.circleci/ds005_outputs.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ sub-01/anat/sub-01_label-CSF_probseg.nii.gz
4343
sub-01/anat/sub-01_label-GM_probseg.nii.gz
4444
sub-01/anat/sub-01_label-WM_probseg.nii.gz
4545
sub-01/func
46+
sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-brain_mask.json
47+
sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-brain_mask.nii.gz
4648
sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-confounds_timeseries.json
4749
sub-01/func/sub-01_task-mixedgamblestask_run-01_desc-confounds_timeseries.tsv
4850
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
6163
sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsaverage5_bold.json
6264
sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsnative_bold.func.gii
6365
sub-01/func/sub-01_task-mixedgamblestask_run-01_hemi-R_space-fsnative_bold.json
66+
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.json
67+
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.nii.gz
6468
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.json
6569
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.tsv
6670
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-coreg_boldref.json

.circleci/ds005_partial_fasttrack_outputs.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-magnitude_fieldmap.nii.gz
5151
sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-preproc_fieldmap.json
5252
sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-preproc_fieldmap.nii.gz
5353
sub-01/func
54+
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.json
55+
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.nii.gz
5456
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.json
5557
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.tsv
5658
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-coreg_boldref.json

.circleci/ds005_partial_outputs.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-magnitude_fieldmap.nii.gz
7373
sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-preproc_fieldmap.json
7474
sub-01/fmap/sub-01_run-02_fmapid-auto00000_desc-preproc_fieldmap.nii.gz
7575
sub-01/func
76+
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.json
77+
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-brain_mask.nii.gz
7678
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.json
7779
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-confounds_timeseries.tsv
7880
sub-01/func/sub-01_task-mixedgamblestask_run-02_desc-coreg_boldref.json

fmriprep/workflows/bold/base.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,6 @@ def init_bold_wf(
325325
ds_bold_native_wf.inputs.inputnode.source_files = bold_series
326326

327327
workflow.connect([
328-
(bold_fit_wf, ds_bold_native_wf, [
329-
('outputnode.bold_mask', 'inputnode.bold_mask'),
330-
]),
331328
(bold_native_wf, ds_bold_native_wf, [
332329
('outputnode.bold_native', 'inputnode.bold'),
333330
('outputnode.bold_echos', 'inputnode.bold_echos'),

fmriprep/workflows/bold/fit.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
# BOLD workflows
4848
from .hmc import init_bold_hmc_wf
4949
from .outputs import (
50+
init_ds_boldmask_wf,
5051
init_ds_boldref_wf,
5152
init_ds_hmc_wf,
5253
init_ds_registration_wf,
@@ -467,13 +468,21 @@ def init_bold_fit_wf(
467468
desc='coreg',
468469
name='ds_coreg_boldref_wf',
469470
)
471+
ds_boldmask_wf = init_ds_boldmask_wf(
472+
bids_root=layout.root,
473+
output_dir=config.execution.fmriprep_dir,
474+
desc='brain',
475+
name='ds_boldmask_wf',
476+
)
477+
ds_boldmask_wf.inputs.inputnode.source_files = [bold_file]
470478

471479
# fmt:off
472480
workflow.connect([
473481
(hmcref_buffer, fmapref_buffer, [("boldref", "boldref_files")]),
474482
(fmapref_buffer, enhance_boldref_wf, [("out", "inputnode.in_file")]),
475483
(fmapref_buffer, ds_coreg_boldref_wf, [("out", "inputnode.source_files")]),
476484
(ds_coreg_boldref_wf, regref_buffer, [("outputnode.boldref", "boldref")]),
485+
(ds_boldmask_wf, regref_buffer, [('outputnode.boldmask', 'boldmask')]),
477486
(fmapref_buffer, func_fit_reports_wf, [("out", "inputnode.sdc_boldref")]),
478487
])
479488
# fmt:on
@@ -557,8 +566,8 @@ def init_bold_fit_wf(
557566
(unwarp_wf, ds_coreg_boldref_wf, [
558567
('outputnode.corrected', 'inputnode.boldref'),
559568
]),
560-
(unwarp_wf, regref_buffer, [
561-
('outputnode.corrected_mask', 'boldmask'),
569+
(unwarp_wf, ds_boldmask_wf, [
570+
('outputnode.corrected_mask', 'inputnode.boldmask'),
562571
]),
563572
(fmap_select, func_fit_reports_wf, [("fmap_ref", "inputnode.fmap_ref")]),
564573
(fmap_select, summary, [("sdc_method", "distortion_correction")]),
@@ -574,8 +583,8 @@ def init_bold_fit_wf(
574583
(enhance_boldref_wf, ds_coreg_boldref_wf, [
575584
('outputnode.bias_corrected_file', 'inputnode.boldref'),
576585
]),
577-
(enhance_boldref_wf, regref_buffer, [
578-
('outputnode.mask_file', 'boldmask'),
586+
(enhance_boldref_wf, ds_boldmask_wf, [
587+
('outputnode.mask_file', 'inputnode.boldmask'),
579588
]),
580589
])
581590
# fmt:on

fmriprep/workflows/bold/outputs.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,50 @@ def init_ds_boldref_wf(
466466
return workflow
467467

468468

469+
def init_ds_boldmask_wf(
470+
*,
471+
bids_root,
472+
output_dir,
473+
desc: str,
474+
name='ds_boldmask_wf',
475+
) -> pe.Workflow:
476+
"""Write out a BOLD mask."""
477+
workflow = pe.Workflow(name=name)
478+
479+
inputnode = pe.Node(
480+
niu.IdentityInterface(fields=['source_files', 'boldmask']),
481+
name='inputnode',
482+
)
483+
outputnode = pe.Node(niu.IdentityInterface(fields=['boldmask']), name='outputnode')
484+
485+
raw_sources = pe.Node(niu.Function(function=_bids_relative), name='raw_sources')
486+
raw_sources.inputs.bids_root = bids_root
487+
488+
ds_boldmask = pe.Node(
489+
DerivativesDataSink(
490+
base_directory=output_dir,
491+
desc=desc,
492+
suffix='mask',
493+
compress=True,
494+
dismiss_entities=dismiss_echo(),
495+
),
496+
name='ds_boldmask',
497+
run_without_submitting=True,
498+
)
499+
500+
workflow.connect([
501+
(inputnode, raw_sources, [('source_files', 'in_files')]),
502+
(inputnode, ds_boldmask, [
503+
('boldmask', 'in_file'),
504+
('source_files', 'source_file'),
505+
]),
506+
(raw_sources, ds_boldmask, [('out', 'RawSources')]),
507+
(ds_boldmask, outputnode, [('out_file', 'boldmask')]),
508+
]) # fmt:skip
509+
510+
return workflow
511+
512+
469513
def init_ds_registration_wf(
470514
*,
471515
bids_root: str,
@@ -575,7 +619,6 @@ def init_ds_bold_native_wf(
575619
fields=[
576620
'source_files',
577621
'bold',
578-
'bold_mask',
579622
'bold_echos',
580623
't2star',
581624
]
@@ -587,27 +630,6 @@ def init_ds_bold_native_wf(
587630
raw_sources.inputs.bids_root = bids_root
588631
workflow.connect(inputnode, 'source_files', raw_sources, 'in_files')
589632

590-
# Masks should be output if any other derivatives are output
591-
ds_bold_mask = pe.Node(
592-
DerivativesDataSink(
593-
base_directory=output_dir,
594-
desc='brain',
595-
suffix='mask',
596-
compress=True,
597-
dismiss_entities=dismiss_echo(),
598-
),
599-
name='ds_bold_mask',
600-
run_without_submitting=True,
601-
mem_gb=DEFAULT_MEMORY_MIN_GB,
602-
)
603-
workflow.connect([
604-
(inputnode, ds_bold_mask, [
605-
('source_files', 'source_file'),
606-
('bold_mask', 'in_file'),
607-
]),
608-
(raw_sources, ds_bold_mask, [('out', 'RawSources')]),
609-
]) # fmt:skip
610-
611633
if bold_output:
612634
ds_bold = pe.Node(
613635
DerivativesDataSink(

0 commit comments

Comments
 (0)