Skip to content

Commit 8e9b574

Browse files
authored
Merge pull request #554 from effigies/enh/multiapply-identity
FIX: Patch ApplyTransforms spec to permit identity in a chain
2 parents 587a15b + 93eb5ee commit 8e9b574

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

niworkflows/interfaces/fixes.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
import nibabel as nb
66

7-
from nipype.interfaces.base import traits
7+
from nipype.interfaces.base import traits, InputMultiObject, File
88
from nipype.utils.filemanip import fname_presuffix
9-
from nipype.interfaces.ants.resampling import ApplyTransforms
9+
from nipype.interfaces.ants.resampling import ApplyTransforms, ApplyTransformsInputSpec
1010
from nipype.interfaces.ants.registration import Registration
1111
from nipype.interfaces.ants.segmentation import (
1212
N4BiasFieldCorrection as VanillaN4,
@@ -17,12 +17,22 @@
1717
from .utils import _copyxform
1818

1919

20+
class FixTraitApplyTransformsInputSpec(ApplyTransformsInputSpec):
21+
transforms = InputMultiObject(
22+
traits.Either(File(exists=True), 'identity'),
23+
argstr="%s",
24+
mandatory=True,
25+
desc="transform files: will be applied in reverse order. For "
26+
"example, the last specified transform will be applied first.",
27+
)
28+
2029
class FixHeaderApplyTransforms(ApplyTransforms):
2130
"""
2231
A replacement for nipype.interfaces.ants.resampling.ApplyTransforms that
2332
fixes the resampled image header to match the xform of the reference
2433
image
2534
"""
35+
input_spec = FixTraitApplyTransformsInputSpec
2636

2737
def _run_interface(self, runtime, correct_return_codes=(0,)):
2838
# Run normally

niworkflows/interfaces/itk.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
TraitedSpec,
1313
BaseInterfaceInputSpec,
1414
File,
15-
InputMultiPath,
16-
OutputMultiPath,
15+
InputMultiObject,
16+
OutputMultiObject,
1717
SimpleInterface,
1818
)
19-
from nipype.interfaces.ants.resampling import ApplyTransformsInputSpec
19+
from niworkflows.interfaces.fixes import FixTraitApplyTransformsInputSpec
2020

2121
LOGGER = logging.getLogger("nipype.interface")
2222

2323

2424
class _MCFLIRT2ITKInputSpec(BaseInterfaceInputSpec):
25-
in_files = InputMultiPath(
25+
in_files = InputMultiObject(
2626
File(exists=True), mandatory=True, desc="list of MAT files from MCFLIRT"
2727
)
2828
in_reference = File(
@@ -96,8 +96,8 @@ def _run_interface(self, runtime):
9696
return runtime
9797

9898

99-
class _MultiApplyTransformsInputSpec(ApplyTransformsInputSpec):
100-
input_image = InputMultiPath(
99+
class _MultiApplyTransformsInputSpec(FixTraitApplyTransformsInputSpec):
100+
input_image = InputMultiObject(
101101
File(exists=True),
102102
mandatory=True,
103103
desc="input time-series as a list of volumes after splitting"
@@ -115,7 +115,7 @@ class _MultiApplyTransformsInputSpec(ApplyTransformsInputSpec):
115115

116116

117117
class _MultiApplyTransformsOutputSpec(TraitedSpec):
118-
out_files = OutputMultiPath(File(), desc="the output ITKTransform file")
118+
out_files = OutputMultiObject(File(), desc="the output ITKTransform file")
119119
log_cmdline = File(desc="a list of command lines used to apply transforms")
120120

121121

@@ -254,6 +254,10 @@ def _arrange_xfms(transforms, num_files, tmp_folder):
254254
# Initialize the transforms matrix
255255
xfms_T = []
256256
for i, tf_file in enumerate(transforms):
257+
if tf_file == "identity":
258+
xfms_T.append([tf_file] * num_files)
259+
continue
260+
257261
# If it is a deformation field, copy to the tfs_matrix directly
258262
if guess_type(tf_file)[0] != "text/plain":
259263
xfms_T.append([tf_file] * num_files)

0 commit comments

Comments
 (0)