Skip to content

Commit 93d1e73

Browse files
committed
FIX: Patch nipype interface to handle inverse transforms
1 parent f87b509 commit 93d1e73

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

nibabies/interfaces/patches.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
freesurfer as fs,
55
)
66
from nipype.interfaces.ants.base import ANTSCommand, ANTSCommandInputSpec
7+
from nipype.interfaces.ants.registration import (
8+
CompositeTransformUtil as _CompositeTransformUtil,
9+
)
10+
from nipype.interfaces.ants.registration import (
11+
CompositeTransformUtilInputSpec as _CompositeTransformUtilInputSpec,
12+
)
713
from nipype.interfaces.base import File, InputMultiObject, TraitedSpec, traits
814

915

@@ -105,3 +111,38 @@ def _list_outputs(self):
105111
outputs = self._outputs().get()
106112
outputs['out_xfm'] = Path(self.inputs.out_xfm).absolute()
107113
return outputs
114+
115+
116+
class CompositeTransformUtilInputSpec(_CompositeTransformUtilInputSpec):
117+
inverse = traits.Bool(
118+
False,
119+
usedefault=True,
120+
desc='When disassembling an inverse component transform, the indexing will be reversed.',
121+
)
122+
123+
124+
class CompositeTransformUtil(_CompositeTransformUtil):
125+
"""Outputs have changed in newer versions of ANTs."""
126+
127+
input_spec = CompositeTransformUtilInputSpec
128+
129+
def _list_outputs(self):
130+
outputs = self.output_spec().get()
131+
132+
# Index may change depending on forward/inverse transform
133+
# Forward: <prefix>_00_AffineTransform.mat, <prefix>_01_DisplacementFieldTransform.nii.gz
134+
# Inverse: <prefix>_01_AffineTransform.mat, <prefix>_00_DisplacementFieldTransform.nii.gz
135+
idx = ['00', '01']
136+
if self.inputs.inverse:
137+
idx = idx[::-1]
138+
139+
if self.inputs.process == 'disassemble':
140+
outputs['affine_transform'] = Path(
141+
f'{self.inputs.output_prefix}_{idx[0]}_AffineTransform.mat'
142+
).absolute()
143+
outputs['displacement_field'] = Path(
144+
f'{self.inputs.output_prefix}_{idx[1]}_DisplacementFieldTransform.nii.gz'
145+
).absolute()
146+
elif self.inputs.process == 'assemble':
147+
outputs['out_file'] = Path(self.inputs.out_file).absolute()
148+
return outputs

0 commit comments

Comments
 (0)