Skip to content

Commit 1ddf3c5

Browse files
committed
rf: Factor out validation and dummy-scan detection from raw_boldref_wf
1 parent 12b7573 commit 1ddf3c5

File tree

1 file changed

+98
-11
lines changed

1 file changed

+98
-11
lines changed

fmriprep/workflows/bold/reference.py

Lines changed: 98 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,96 @@ def init_raw_boldref_wf(
106106
name='outputnode',
107107
)
108108

109+
# Simplify manually setting input image
110+
if bold_file is not None:
111+
inputnode.inputs.bold_file = bold_file
112+
113+
validation_and_dummies_wf = init_validation_and_dummies_wf()
114+
115+
gen_avg = pe.Node(RobustAverage(), name='gen_avg', mem_gb=1)
116+
117+
workflow.connect([
118+
(inputnode, validation_and_dummies_wf, [
119+
('bold_file', 'inputnode.bold_file'),
120+
('dummy_scans', 'inputnode.dummy_scans'),
121+
]),
122+
(validation_and_dummies_wf, gen_avg, [
123+
('outputnode.bold_file', 'in_file'),
124+
('outputnode.t_mask', 't_mask'),
125+
]),
126+
(validation_and_dummies_wf, outputnode, [
127+
('outputnode.bold_file', 'bold_file'),
128+
('outputnode.skip_vols', 'skip_vols'),
129+
('outputnode.algo_dummy_scans', 'algo_dummy_scans'),
130+
('outputnode.validation_report', 'validation_report'),
131+
]),
132+
(gen_avg, outputnode, [('out_file', 'boldref')]),
133+
]) # fmt:skip
134+
135+
return workflow
136+
137+
138+
def init_validation_and_dummies_wf(
139+
bold_file=None,
140+
name='validation_and_dummies_wf',
141+
):
142+
"""
143+
Build a workflow that validates a BOLD image and detects non-steady-state volumes.
144+
145+
Workflow Graph
146+
.. workflow::
147+
:graph2use: orig
148+
:simple_form: yes
149+
150+
from fmriprep.workflows.bold.reference import init_validation_and_dummies_wf
151+
wf = init_validation_and_dummies_wf()
152+
153+
Parameters
154+
----------
155+
bold_file : :obj:`str`
156+
BOLD series NIfTI file
157+
name : :obj:`str`
158+
Name of workflow (default: ``validation_and_dummies_wf``)
159+
160+
Inputs
161+
------
162+
bold_file : str
163+
BOLD series NIfTI file
164+
dummy_scans : int or None
165+
Number of non-steady-state volumes specified by user at beginning of ``bold_file``
166+
167+
Outputs
168+
-------
169+
bold_file : str
170+
Validated BOLD series NIfTI file
171+
skip_vols : int
172+
Number of non-steady-state volumes selected at beginning of ``bold_file``
173+
algo_dummy_scans : int
174+
Number of non-steady-state volumes agorithmically detected at
175+
beginning of ``bold_file``
176+
177+
"""
178+
from niworkflows.interfaces.bold import NonsteadyStatesDetector
179+
180+
workflow = Workflow(name=name)
181+
182+
inputnode = pe.Node(
183+
niu.IdentityInterface(fields=['bold_file', 'dummy_scans']),
184+
name='inputnode',
185+
)
186+
outputnode = pe.Node(
187+
niu.IdentityInterface(
188+
fields=[
189+
'bold_file',
190+
'skip_vols',
191+
'algo_dummy_scans',
192+
't_mask',
193+
'validation_report',
194+
]
195+
),
196+
name='outputnode',
197+
)
198+
109199
# Simplify manually setting input image
110200
if bold_file is not None:
111201
inputnode.inputs.bold_file = bold_file
@@ -117,7 +207,6 @@ def init_raw_boldref_wf(
117207
)
118208

119209
get_dummy = pe.Node(NonsteadyStatesDetector(), name='get_dummy')
120-
gen_avg = pe.Node(RobustAverage(), name='gen_avg', mem_gb=1)
121210

122211
calc_dummy_scans = pe.Node(
123212
niu.Function(function=pass_dummy_scans, output_names=['skip_vols_num']),
@@ -126,22 +215,20 @@ def init_raw_boldref_wf(
126215
mem_gb=DEFAULT_MEMORY_MIN_GB,
127216
)
128217

129-
# fmt: off
130218
workflow.connect([
131219
(inputnode, val_bold, [('bold_file', 'in_file')]),
132-
(inputnode, get_dummy, [('bold_file', 'in_file')]),
133-
(inputnode, calc_dummy_scans, [('dummy_scans', 'dummy_scans')]),
134-
(val_bold, gen_avg, [('out_file', 'in_file')]),
135-
(get_dummy, gen_avg, [('t_mask', 't_mask')]),
136-
(get_dummy, calc_dummy_scans, [('n_dummy', 'algo_dummy_scans')]),
137220
(val_bold, outputnode, [
138221
('out_file', 'bold_file'),
139222
('out_report', 'validation_report'),
140223
]),
224+
(inputnode, get_dummy, [('bold_file', 'in_file')]),
225+
(inputnode, calc_dummy_scans, [('dummy_scans', 'dummy_scans')]),
226+
(get_dummy, calc_dummy_scans, [('n_dummy', 'algo_dummy_scans')]),
227+
(get_dummy, outputnode, [
228+
('n_dummy', 'algo_dummy_scans'),
229+
('t_mask', 't_mask'),
230+
]),
141231
(calc_dummy_scans, outputnode, [('skip_vols_num', 'skip_vols')]),
142-
(gen_avg, outputnode, [('out_file', 'boldref')]),
143-
(get_dummy, outputnode, [('n_dummy', 'algo_dummy_scans')]),
144-
])
145-
# fmt: on
232+
]) # fmt:skip
146233

147234
return workflow

0 commit comments

Comments
 (0)