Skip to content

Commit ad72b45

Browse files
committed
RF: Extend template workflow for other anatomical image types
1 parent 7852cba commit ad72b45

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

smriprep/workflows/outputs.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -230,36 +230,39 @@ def init_anat_reports_wf(*, spaces, freesurfer, output_dir, sloppy=False, name='
230230

231231
def init_ds_template_wf(
232232
*,
233-
num_t1w,
234-
output_dir,
235-
name='ds_template_wf',
233+
num_anat: int,
234+
output_dir: str,
235+
image_type: str = 'T1w',
236+
name: str = 'ds_template_wf',
236237
):
237238
"""
238239
Save the subject-specific template
239240
240241
Parameters
241242
----------
242-
num_t1w : :obj:`int`
243-
Number of T1w images
243+
num_anat : :obj:`int`
244+
Number of anatomical images
244245
output_dir : :obj:`str`
245246
Directory in which to save derivatives
247+
image_type
248+
MR image type (T1w, T2w, etc.)
246249
name : :obj:`str`
247250
Workflow name (default: ds_template_wf)
248251
249252
Inputs
250253
------
251254
source_files
252-
List of input T1w images
253-
t1w_ref_xfms
254-
List of affine transforms to realign input T1w images
255-
t1w_preproc
256-
The T1w reference map, which is calculated as the average of bias-corrected
257-
and preprocessed T1w images, defining the anatomical space.
255+
List of input anatomical images
256+
anat_ref_xfms
257+
List of affine transforms to realign input anatomical images
258+
anat_preproc
259+
The anatomical reference map, which is calculated as the average of bias-corrected
260+
and preprocessed anatomical images, defining the anatomical space.
258261
259262
Outputs
260263
-------
261-
t1w_preproc
262-
The location in the output directory of the preprocessed T1w image
264+
anat_preproc
265+
The location in the output directory of the preprocessed anatomical image
263266
264267
"""
265268
workflow = Workflow(name=name)
@@ -268,49 +271,49 @@ def init_ds_template_wf(
268271
niu.IdentityInterface(
269272
fields=[
270273
'source_files',
271-
't1w_ref_xfms',
272-
't1w_preproc',
274+
'anat_ref_xfms',
275+
'anat_preproc',
273276
]
274277
),
275278
name='inputnode',
276279
)
277-
outputnode = pe.Node(niu.IdentityInterface(fields=['t1w_preproc']), name='outputnode')
280+
outputnode = pe.Node(niu.IdentityInterface(fields=['anat_preproc']), name='outputnode')
278281

279-
ds_t1w_preproc = pe.Node(
282+
ds_anat_preproc = pe.Node(
280283
DerivativesDataSink(base_directory=output_dir, desc='preproc', compress=True),
281-
name='ds_t1w_preproc',
284+
name='ds_anat_preproc',
282285
run_without_submitting=True,
283286
)
284-
ds_t1w_preproc.inputs.SkullStripped = False
287+
ds_anat_preproc.inputs.SkullStripped = False
285288

286289
# fmt:off
287290
workflow.connect([
288-
(inputnode, ds_t1w_preproc, [('t1w_preproc', 'in_file'),
291+
(inputnode, ds_anat_preproc, [('anat_preproc', 'in_file'),
289292
('source_files', 'source_file')]),
290-
(ds_t1w_preproc, outputnode, [('out_file', 't1w_preproc')]),
293+
(ds_anat_preproc, outputnode, [('out_file', 'anat_preproc')]),
291294
])
292295
# fmt:on
293296

294-
if num_t1w > 1:
297+
if num_anat > 1:
295298
# Please note the dictionary unpacking to provide the from argument.
296299
# It is necessary because from is a protected keyword (not allowed as argument name).
297-
ds_t1w_ref_xfms = pe.MapNode(
300+
ds_anat_ref_xfms = pe.MapNode(
298301
DerivativesDataSink(
299302
base_directory=output_dir,
300-
to='T1w',
303+
to=image_type,
301304
mode='image',
302305
suffix='xfm',
303306
extension='txt',
304307
**{'from': 'orig'},
305308
),
306309
iterfield=['source_file', 'in_file'],
307-
name='ds_t1w_ref_xfms',
310+
name='ds_anat_ref_xfms',
308311
run_without_submitting=True,
309312
)
310313
# fmt:off
311314
workflow.connect([
312-
(inputnode, ds_t1w_ref_xfms, [('source_files', 'source_file'),
313-
('t1w_ref_xfms', 'in_file')]),
315+
(inputnode, ds_anat_ref_xfms, [('source_files', 'source_file'),
316+
('anat_ref_xfms', 'in_file')]),
314317
])
315318
# fmt:on
316319

0 commit comments

Comments
 (0)