Skip to content

Commit 2353ac4

Browse files
committed
feat: Create GeneratedBy metadata for xfm files
1 parent c961b3c commit 2353ac4

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

fmriprep/workflows/bold/fit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,10 @@ def init_bold_fit_wf(
682682
(regref_buffer, bold_reg_wf, [('boldref', 'inputnode.ref_bold_brain')]),
683683
# Incomplete sources
684684
(regref_buffer, ds_boldreg_wf, [('boldref', 'inputnode.source_files')]),
685-
(bold_reg_wf, ds_boldreg_wf, [('outputnode.itk_bold_to_t1', 'inputnode.xform')]),
685+
(bold_reg_wf, ds_boldreg_wf, [
686+
('outputnode.itk_bold_to_t1', 'inputnode.xform'),
687+
('outputnode.metadata', 'inputnode.metadata'),
688+
]),
686689
(ds_boldreg_wf, outputnode, [('outputnode.xform', 'boldref2anat_xfm')]),
687690
(bold_reg_wf, summary, [('outputnode.fallback', 'fallback')]),
688691
]) # fmt:skip

fmriprep/workflows/bold/outputs.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def init_ds_registration_wf(
546546
workflow = pe.Workflow(name=name)
547547

548548
inputnode = pe.Node(
549-
niu.IdentityInterface(fields=['source_files', 'xform']),
549+
niu.IdentityInterface(fields=['source_files', 'xform', 'metadata']),
550550
name='inputnode',
551551
)
552552
outputnode = pe.Node(niu.IdentityInterface(fields=['xform']), name='outputnode')
@@ -574,15 +574,16 @@ def init_ds_registration_wf(
574574
mem_gb=DEFAULT_MEMORY_MIN_GB,
575575
)
576576

577-
# fmt:off
578577
workflow.connect([
579578
(inputnode, sources, [('source_files', 'in1')]),
580-
(inputnode, ds_xform, [('xform', 'in_file'),
581-
('source_files', 'source_file')]),
579+
(inputnode, ds_xform, [
580+
('xform', 'in_file'),
581+
('source_files', 'source_file'),
582+
('metadata', 'meta_dict'),
583+
]),
582584
(sources, ds_xform, [('out', 'Sources')]),
583585
(ds_xform, outputnode, [('out_file', 'xform')]),
584-
])
585-
# fmt:on
586+
]) # fmt:skip
586587

587588
return workflow
588589

fmriprep/workflows/bold/registration.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ def init_bold_reg_wf(
128128
Affine transform from T1 space to BOLD space (ITK format)
129129
fallback
130130
Boolean indicating whether BBR was rejected (mri_coreg registration returned)
131+
metadata
132+
Output metadata from the registration workflow
131133
132134
See Also
133135
--------
@@ -154,7 +156,7 @@ def init_bold_reg_wf(
154156
)
155157

156158
outputnode = pe.Node(
157-
niu.IdentityInterface(fields=['itk_bold_to_t1', 'itk_t1_to_bold', 'fallback']),
159+
niu.IdentityInterface(fields=['itk_bold_to_t1', 'itk_t1_to_bold', 'fallback', 'metadata']),
158160
name='outputnode',
159161
)
160162

@@ -188,6 +190,7 @@ def init_bold_reg_wf(
188190
('outputnode.itk_bold_to_t1', 'itk_bold_to_t1'),
189191
('outputnode.itk_t1_to_bold', 'itk_t1_to_bold'),
190192
('outputnode.fallback', 'fallback'),
193+
('outputnode.metadata', 'metadata'),
191194
]),
192195
]) # fmt:skip
193196

@@ -268,6 +271,8 @@ def init_bbreg_wf(
268271
Affine transform from T1 space to BOLD space (ITK format)
269272
fallback
270273
Boolean indicating whether BBR was rejected (mri_coreg registration returned)
274+
metadata
275+
Output metadata from the registration workflow
271276
272277
"""
273278
from nipype.interfaces.freesurfer import BBRegister
@@ -309,7 +314,7 @@ def init_bbreg_wf(
309314
name='inputnode',
310315
)
311316
outputnode = pe.Node(
312-
niu.IdentityInterface(['itk_bold_to_t1', 'itk_t1_to_bold', 'fallback']),
317+
niu.IdentityInterface(['itk_bold_to_t1', 'itk_t1_to_bold', 'fallback', 'metadata']),
313318
name='outputnode',
314319
)
315320

@@ -357,6 +362,9 @@ def init_bbreg_wf(
357362
merge_ltas = pe.Node(niu.Merge(2), name='merge_ltas', run_without_submitting=True)
358363
concat_xfm = pe.Node(ConcatenateXFMs(inverse=True), name='concat_xfm')
359364

365+
metadata = pe.Node(niu.Merge(2), run_without_submitting=True, name='metadata')
366+
select_meta = pe.Node(niu.Select(index=0), run_without_submitting=True, name='select_meta')
367+
360368
workflow.connect([
361369
(inputnode, merge_ltas, [('fsnative2t1w_xfm', 'in2')]),
362370
# Wire up the co-registration alternatives
@@ -365,10 +373,18 @@ def init_bbreg_wf(
365373
(merge_ltas, concat_xfm, [('out', 'in_xfms')]),
366374
(concat_xfm, outputnode, [('out_xfm', 'itk_bold_to_t1')]),
367375
(concat_xfm, outputnode, [('out_inv', 'itk_t1_to_bold')]),
376+
# Wire up the metadata alternatives
377+
(metadata, select_meta, [('out', 'inlist')]),
378+
(select_meta, outputnode, [('out', 'metadata')]),
368379
]) # fmt:skip
369380

370381
# Do not initialize with header, use mri_coreg
371382
if bold2anat_init != 'header':
383+
metadata.inputs.in2 = {
384+
'GeneratedBy': [
385+
{'Name': 'mri_coreg', 'Version': mri_coreg.interface.version or '<unknown>'}
386+
]
387+
}
372388
workflow.connect([
373389
(inputnode, mri_coreg, [('subjects_dir', 'subjects_dir'),
374390
('subject_id', 'subject_id'),
@@ -400,6 +416,12 @@ def init_bbreg_wf(
400416
(bbregister, transforms, [('out_lta_file', 'in1')]),
401417
]) # fmt:skip
402418

419+
metadata.inputs.in1 = {
420+
'GeneratedBy': [
421+
{'Name': 'bbregister', 'Version': bbregister.interface.version or '<unknown>'}
422+
]
423+
}
424+
403425
# Short-circuit workflow building, use boundary-based registration
404426
if use_bbr is True:
405427
outputnode.inputs.fallback = False
@@ -413,6 +435,7 @@ def init_bbreg_wf(
413435
(transforms, compare_transforms, [('out', 'lta_list')]),
414436
(compare_transforms, outputnode, [('out', 'fallback')]),
415437
(compare_transforms, select_transform, [('out', 'index')]),
438+
(compare_transforms, select_meta, [('out', 'index')]),
416439
]) # fmt:skip
417440

418441
return workflow
@@ -493,6 +516,8 @@ def init_fsl_bbr_wf(
493516
Affine transform from T1 space to BOLD space (ITK format)
494517
fallback
495518
Boolean indicating whether BBR was rejected (rigid FLIRT registration returned)
519+
metadata
520+
Output metadata from the registration workflow
496521
497522
"""
498523
from nipype.interfaces.freesurfer import MRICoreg
@@ -532,7 +557,7 @@ def init_fsl_bbr_wf(
532557
name='inputnode',
533558
)
534559
outputnode = pe.Node(
535-
niu.IdentityInterface(['itk_bold_to_t1', 'itk_t1_to_bold', 'fallback']),
560+
niu.IdentityInterface(['itk_bold_to_t1', 'itk_t1_to_bold', 'fallback', 'metadata']),
536561
name='outputnode',
537562
)
538563

@@ -549,6 +574,9 @@ def init_fsl_bbr_wf(
549574
'T2w intermediate for FSL is not implemented, registering with T1w instead.'
550575
)
551576

577+
metadata = pe.Node(niu.Merge(2), run_without_submitting=True, name='metadata')
578+
select_meta = pe.Node(niu.Select(index=0), run_without_submitting=True, name='select_meta')
579+
552580
# Mask T1w_preproc with T1w_mask to make T1w_brain
553581
mask_t1w_brain = pe.Node(ApplyMask(), name='mask_t1w_brain')
554582

@@ -565,6 +593,12 @@ def init_fsl_bbr_wf(
565593
mem_gb=DEFAULT_MEMORY_MIN_GB,
566594
)
567595

596+
metadata.inputs.in2 = {
597+
'GeneratedBy': [
598+
{'Name': 'mri_coreg', 'Version': mri_coreg.interface.version or '<unknown>'}
599+
]
600+
}
601+
568602
workflow.connect([
569603
(inputnode, mask_t1w_brain, [
570604
('t1w_preproc', 'in_file'),
@@ -578,6 +612,9 @@ def init_fsl_bbr_wf(
578612
('out_xfm', 'itk_bold_to_t1'),
579613
('out_inv', 'itk_t1_to_bold'),
580614
]),
615+
# Wire up the metadata alternatives
616+
(metadata, select_meta, [('out', 'inlist')]),
617+
(select_meta, outputnode, [('out', 'metadata')]),
581618
]) # fmt:skip
582619

583620
# Short-circuit workflow building, use rigid registration
@@ -604,6 +641,10 @@ def init_fsl_bbr_wf(
604641
LOGGER.warning('FSLDIR unset - using packaged BBR schedule')
605642
flt_bbr.inputs.schedule = data.load('flirtsch/bbr.sch')
606643

644+
metadata.inputs.in1 = {
645+
'GeneratedBy': [{'Name': 'flirt', 'Version': flt_bbr.interface.version or '<unknown>'}]
646+
}
647+
607648
workflow.connect([
608649
(inputnode, wm_mask, [('t1w_dseg', 'in_seg')]),
609650
(inputnode, flt_bbr, [('in_file', 'in_file')]),
@@ -658,6 +699,8 @@ def init_fsl_bbr_wf(
658699
(transforms, select_transform, [('out', 'inlist')]),
659700
(compare_transforms, select_transform, [('out', 'index')]),
660701
(select_transform, xfm2itk, [('out', 'in_xfm')]),
702+
# Select metadata
703+
(compare_transforms, select_meta, [('out', 'index')]),
661704
]) # fmt:skip
662705

663706
return workflow

0 commit comments

Comments
 (0)