|
4 | 4 | freesurfer as fs, |
5 | 5 | ) |
6 | 6 | 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 | +) |
7 | 13 | from nipype.interfaces.base import File, InputMultiObject, TraitedSpec, traits |
8 | 14 |
|
9 | 15 |
|
@@ -105,3 +111,38 @@ def _list_outputs(self): |
105 | 111 | outputs = self._outputs().get() |
106 | 112 | outputs['out_xfm'] = Path(self.inputs.out_xfm).absolute() |
107 | 113 | 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