Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Write out boldref-space brain mask with minimal level #3292

Merged
merged 7 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .circleci/ds005_fasttrack_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .circleci/ds005_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .circleci/ds005_partial_fasttrack_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .circleci/ds005_partial_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions fmriprep/workflows/bold/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
17 changes: 13 additions & 4 deletions fmriprep/workflows/bold/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -467,13 +468,21 @@ 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',
)
ds_boldmask_wf.inputs.inputnode.source_files = [bold_file]

# fmt:off
workflow.connect([
(hmcref_buffer, fmapref_buffer, [("boldref", "boldref_files")]),
(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
Expand Down Expand Up @@ -557,8 +566,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")]),
Expand All @@ -574,8 +583,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
Expand Down
66 changes: 44 additions & 22 deletions fmriprep/workflows/bold/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -575,7 +619,6 @@ def init_ds_bold_native_wf(
fields=[
'source_files',
'bold',
'bold_mask',
'bold_echos',
't2star',
]
Expand All @@ -587,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(
Expand Down
Loading