Skip to content

Commit 02b5b84

Browse files
authored
Merge pull request #2140 from effigies/enh/lta_convert
ENH: Add interface for FreeSurfer's lta_convert
2 parents 0728dd8 + 69a59a9 commit 02b5b84

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..utils import LTAConvert
4+
5+
6+
def test_LTAConvert_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
environ=dict(nohash=True,
10+
usedefault=True,
11+
),
12+
ignore_exception=dict(nohash=True,
13+
usedefault=True,
14+
),
15+
in_fsl=dict(argstr='--infsl %s',
16+
mandatory=True,
17+
xor=('in_lta', 'in_fsl', 'in_mni', 'in_reg', 'in_niftyreg'),
18+
),
19+
in_lta=dict(argstr='--inlta %s',
20+
mandatory=True,
21+
xor=('in_lta', 'in_fsl', 'in_mni', 'in_reg', 'in_niftyreg'),
22+
),
23+
in_mni=dict(argstr='--inmni %s',
24+
mandatory=True,
25+
xor=('in_lta', 'in_fsl', 'in_mni', 'in_reg', 'in_niftyreg'),
26+
),
27+
in_niftyreg=dict(argstr='--inniftyreg %s',
28+
mandatory=True,
29+
xor=('in_lta', 'in_fsl', 'in_mni', 'in_reg', 'in_niftyreg'),
30+
),
31+
in_reg=dict(argstr='--inreg %s',
32+
mandatory=True,
33+
xor=('in_lta', 'in_fsl', 'in_mni', 'in_reg', 'in_niftyreg'),
34+
),
35+
invert=dict(argstr='--invert',
36+
),
37+
ltavox2vox=dict(argstr='--ltavox2vox',
38+
requires=['out_lta'],
39+
),
40+
out_fsl=dict(argstr='--outfsl %s',
41+
),
42+
out_lta=dict(argstr='--outlta %s',
43+
),
44+
out_mni=dict(argstr='--outmni %s',
45+
),
46+
out_reg=dict(argstr='--outreg %s',
47+
),
48+
source_file=dict(argstr='--src %s',
49+
),
50+
target_conform=dict(argstr='--trgconform',
51+
),
52+
target_file=dict(argstr='--trg %s',
53+
),
54+
terminal_output=dict(nohash=True,
55+
),
56+
)
57+
inputs = LTAConvert.input_spec()
58+
59+
for key, metadata in list(input_map.items()):
60+
for metakey, value in list(metadata.items()):
61+
assert getattr(inputs.traits()[key], metakey) == value
62+
63+
64+
def test_LTAConvert_outputs():
65+
output_map = dict(out_fsl=dict(),
66+
out_lta=dict(),
67+
out_mni=dict(),
68+
out_reg=dict(),
69+
)
70+
outputs = LTAConvert.output_spec()
71+
72+
for key, metadata in list(output_map.items()):
73+
for metakey, value in list(metadata.items()):
74+
assert getattr(outputs.traits()[key], metakey) == value

nipype/interfaces/freesurfer/utils.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,3 +3080,76 @@ def _normalize_filenames(self):
30803080
thickness_name)
30813081

30823082
self.inputs.sphere = self._associated_file(in_file, self.inputs.sphere)
3083+
3084+
3085+
class LTAConvertInputSpec(CommandLineInputSpec):
3086+
# Inputs
3087+
_in_xor = ('in_lta', 'in_fsl', 'in_mni', 'in_reg', 'in_niftyreg')
3088+
in_lta = traits.Either(
3089+
File(exists=True), 'identity.nofile', argstr='--inlta %s',
3090+
mandatory=True, xor=_in_xor, desc='input transform of LTA type')
3091+
in_fsl = File(
3092+
exists=True, argstr='--infsl %s', mandatory=True, xor=_in_xor,
3093+
desc='input transform of FSL type')
3094+
in_mni = File(
3095+
exists=True, argstr='--inmni %s', mandatory=True, xor=_in_xor,
3096+
desc='input transform of MNI/XFM type')
3097+
in_reg = File(
3098+
exists=True, argstr='--inreg %s', mandatory=True, xor=_in_xor,
3099+
desc='input transform of TK REG type (deprecated format)')
3100+
in_niftyreg = File(
3101+
exists=True, argstr='--inniftyreg %s', mandatory=True, xor=_in_xor,
3102+
desc='input transform of Nifty Reg type (inverse RAS2RAS)')
3103+
# Outputs
3104+
out_lta = traits.Either(
3105+
traits.Bool, File, argstr='--outlta %s',
3106+
desc='output linear transform (LTA Freesurfer format)')
3107+
out_fsl = traits.Either(traits.Bool, File, argstr='--outfsl %s',
3108+
desc='output transform in FSL format')
3109+
out_mni = traits.Either(traits.Bool, File, argstr='--outmni %s',
3110+
desc='output transform in MNI/XFM format')
3111+
out_reg = traits.Either(traits.Bool, File, argstr='--outreg %s',
3112+
desc='output transform in reg dat format')
3113+
# Optional flags
3114+
invert = traits.Bool(argstr='--invert')
3115+
ltavox2vox = traits.Bool(argstr='--ltavox2vox', requires=['out_lta'])
3116+
source_file = File(exists=True, argstr='--src %s')
3117+
target_file = File(exists=True, argstr='--trg %s')
3118+
target_conform = traits.Bool(argstr='--trgconform')
3119+
3120+
3121+
class LTAConvertOutputSpec(TraitedSpec):
3122+
out_lta = File(exists=True,
3123+
desc='output linear transform (LTA Freesurfer format)')
3124+
out_fsl = File(exists=True, desc='output transform in FSL format')
3125+
out_mni = File(exists=True, desc='output transform in MNI/XFM format')
3126+
out_reg = File(exists=True, desc='output transform in reg dat format')
3127+
3128+
3129+
class LTAConvert(CommandLine):
3130+
"""Convert different transformation formats.
3131+
Some formats may require you to pass an image if the geometry information
3132+
is missing form the transform file format.
3133+
3134+
For complete details, see the `lta_convert documentation.
3135+
<https://ftp.nmr.mgh.harvard.edu/pub/docs/html/lta_convert.help.xml.html>`_
3136+
"""
3137+
input_spec = LTAConvertInputSpec
3138+
output_spec = LTAConvertOutputSpec
3139+
_cmd = 'lta_convert'
3140+
3141+
def _format_arg(self, name, spec, value):
3142+
if name.startswith('out_') and value is True:
3143+
value = self._list_outputs()[name]
3144+
return super(LTAConvert, self)._format_arg(name, spec, value)
3145+
3146+
def _list_outputs(self):
3147+
outputs = self.output_spec().get()
3148+
for name, default in (('out_lta', 'out.lta'), ('out_fsl', 'out.mat'),
3149+
('out_mni', 'out.xfm'), ('out_reg', 'out.dat')):
3150+
attr = getattr(self.inputs, name)
3151+
if attr:
3152+
fname = default if attr is True else attr
3153+
outputs[name] = os.path.abspath(fname)
3154+
3155+
return outputs

0 commit comments

Comments
 (0)