Skip to content

Commit b57ee74

Browse files
committed
feat: Replace c3d_affine_tool with ConvertAffine interface
1 parent 27598fb commit b57ee74

File tree

2 files changed

+33
-57
lines changed

2 files changed

+33
-57
lines changed

fmriprep/interfaces/nitransforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _run_interface(self, runtime):
6363
'fsl': 'mat',
6464
}[self.inputs.out_fmt]
6565

66-
in_fmt = self.inputs.in_xfm
66+
in_fmt = self.inputs.in_fmt
6767
if in_fmt == 'auto':
6868
in_fmt = {
6969
'.lta': 'fs',

fmriprep/workflows/bold/registration.py

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
import os.path as op
3535
import typing as ty
3636

37-
from nipype.interfaces import c3, fsl
37+
from nipype.interfaces import fsl
3838
from nipype.interfaces import utility as niu
3939
from nipype.pipeline import engine as pe
4040

4141
from ... import config, data
42+
from ...interfaces.nitransforms import ConvertAffine
4243

4344
DEFAULT_MEMORY_MIN_GB = config.DEFAULT_MEMORY_MIN_GB
4445
LOGGER = config.loggers.workflow
@@ -558,53 +559,38 @@ def init_fsl_bbr_wf(
558559
mem_gb=5,
559560
)
560561

561-
lta_to_fsl = pe.Node(LTAConvert(out_fsl=True), name='lta_to_fsl', mem_gb=DEFAULT_MEMORY_MIN_GB)
562-
563-
invt_bbr = pe.Node(
564-
fsl.ConvertXFM(invert_xfm=True), name='invt_bbr', mem_gb=DEFAULT_MEMORY_MIN_GB
565-
)
566-
567-
# BOLD to T1 transform matrix is from fsl, using c3 tools to convert to
568-
# something ANTs will like.
569-
fsl2itk_fwd = pe.Node(
570-
c3.C3dAffineTool(fsl2ras=True, itk_transform=True),
571-
name='fsl2itk_fwd',
572-
mem_gb=DEFAULT_MEMORY_MIN_GB,
573-
)
574-
fsl2itk_inv = pe.Node(
575-
c3.C3dAffineTool(fsl2ras=True, itk_transform=True),
576-
name='fsl2itk_inv',
562+
xfm2itk = pe.Node(
563+
ConvertAffine(in_fmt='fsl', out_fmt='itk', inverse=True),
564+
name='xfm2itk',
577565
mem_gb=DEFAULT_MEMORY_MIN_GB,
578566
)
579-
# fmt:off
567+
580568
workflow.connect([
581-
(inputnode, mask_t1w_brain, [('t1w_preproc', 'in_file'),
582-
('t1w_mask', 'in_mask')]),
569+
(inputnode, mask_t1w_brain, [
570+
('t1w_preproc', 'in_file'),
571+
('t1w_mask', 'in_mask'),
572+
]),
583573
(inputnode, mri_coreg, [('in_file', 'source_file')]),
584-
(inputnode, fsl2itk_fwd, [('in_file', 'source_file')]),
585-
(inputnode, fsl2itk_inv, [('in_file', 'reference_file')]),
574+
(inputnode, xfm2itk, [('in_file', 'moving')]),
586575
(mask_t1w_brain, mri_coreg, [('out_file', 'reference_file')]),
587-
(mask_t1w_brain, fsl2itk_fwd, [('out_file', 'reference_file')]),
588-
(mask_t1w_brain, fsl2itk_inv, [('out_file', 'source_file')]),
589-
(mri_coreg, lta_to_fsl, [('out_lta_file', 'in_lta')]),
590-
(invt_bbr, fsl2itk_inv, [('out_file', 'transform_file')]),
591-
(fsl2itk_fwd, outputnode, [('itk_transform', 'itk_bold_to_t1')]),
592-
(fsl2itk_inv, outputnode, [('itk_transform', 'itk_t1_to_bold')]),
593-
])
594-
# fmt:on
576+
(mask_t1w_brain, xfm2itk, [('out_file', 'reference')]),
577+
(xfm2itk, outputnode, [
578+
('out_xfm', 'itk_bold_to_t1'),
579+
('out_inv', 'itk_t1_to_bold'),
580+
]),
581+
]) # fmt:skip
595582

596583
# Short-circuit workflow building, use rigid registration
597584
if use_bbr is False:
598-
# fmt:off
599-
workflow.connect([
600-
(lta_to_fsl, invt_bbr, [('out_fsl', 'in_file')]),
601-
(lta_to_fsl, fsl2itk_fwd, [('out_fsl', 'transform_file')]),
602-
])
603-
# fmt:on
585+
xfm2itk.inputs.in_fmt = 'fs' # Override
586+
workflow.connect(mri_coreg, 'out_lta_file', xfm2itk, 'in_xfm')
587+
604588
outputnode.inputs.fallback = True
605589

606590
return workflow
607591

592+
lta_to_fsl = pe.Node(LTAConvert(out_fsl=True), name='lta_to_fsl', mem_gb=DEFAULT_MEMORY_MIN_GB)
593+
608594
flt_bbr = pe.Node(
609595
fsl.FLIRT(cost_func='bbr', dof=bold2anat_dof, args='-basescale 1'),
610596
name='flt_bbr',
@@ -617,44 +603,36 @@ def init_fsl_bbr_wf(
617603
# Should mostly be hit while building docs
618604
LOGGER.warning('FSLDIR unset - using packaged BBR schedule')
619605
flt_bbr.inputs.schedule = data.load('flirtsch/bbr.sch')
620-
# fmt:off
606+
621607
workflow.connect([
622608
(inputnode, wm_mask, [('t1w_dseg', 'in_seg')]),
623609
(inputnode, flt_bbr, [('in_file', 'in_file')]),
610+
(mri_coreg, lta_to_fsl, [('out_lta_file', 'in_lta')]),
624611
(lta_to_fsl, flt_bbr, [('out_fsl', 'in_matrix_file')]),
625-
])
626-
# fmt:on
612+
]) # fmt:skip
613+
627614
if sloppy is True:
628615
downsample = pe.Node(
629616
niu.Function(
630617
function=_conditional_downsampling, output_names=['out_file', 'out_mask']
631618
),
632619
name='downsample',
633620
)
634-
# fmt:off
635621
workflow.connect([
636622
(mask_t1w_brain, downsample, [('out_file', 'in_file')]),
637623
(wm_mask, downsample, [('out', 'in_mask')]),
638624
(downsample, flt_bbr, [('out_file', 'reference'),
639625
('out_mask', 'wm_seg')]),
640-
])
641-
# fmt:on
626+
]) # fmt:skip
642627
else:
643-
# fmt:off
644628
workflow.connect([
645629
(mask_t1w_brain, flt_bbr, [('out_file', 'reference')]),
646630
(wm_mask, flt_bbr, [('out', 'wm_seg')]),
647-
])
648-
# fmt:on
631+
]) # fmt:skip
649632

650633
# Short-circuit workflow building, use boundary-based registration
651634
if use_bbr is True:
652-
# fmt:off
653-
workflow.connect([
654-
(flt_bbr, invt_bbr, [('out_matrix_file', 'in_file')]),
655-
(flt_bbr, fsl2itk_fwd, [('out_matrix_file', 'transform_file')]),
656-
])
657-
# fmt:on
635+
workflow.connect(flt_bbr, 'out_matrix_file', xfm2itk, 'in_xfm')
658636
outputnode.inputs.fallback = False
659637

660638
return workflow
@@ -666,7 +644,7 @@ def init_fsl_bbr_wf(
666644
select_transform = pe.Node(niu.Select(), run_without_submitting=True, name='select_transform')
667645

668646
fsl_to_lta = pe.MapNode(LTAConvert(out_lta=True), iterfield=['in_fsl'], name='fsl_to_lta')
669-
# fmt:off
647+
670648
workflow.connect([
671649
(flt_bbr, transforms, [('out_matrix_file', 'in1')]),
672650
(lta_to_fsl, transforms, [('out_fsl', 'in2')]),
@@ -679,10 +657,8 @@ def init_fsl_bbr_wf(
679657
# Select output transform
680658
(transforms, select_transform, [('out', 'inlist')]),
681659
(compare_transforms, select_transform, [('out', 'index')]),
682-
(select_transform, invt_bbr, [('out', 'in_file')]),
683-
(select_transform, fsl2itk_fwd, [('out', 'transform_file')]),
684-
])
685-
# fmt:on
660+
(select_transform, xfm2itk, [('out', 'in_xfm')]),
661+
]) # fmt:skip
686662

687663
return workflow
688664

0 commit comments

Comments
 (0)