Skip to content

Commit c981c56

Browse files
committed
ENH: Add LTA in/out to Tkregister2
1 parent 2b10ff2 commit c981c56

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

nipype/interfaces/freesurfer/tests/test_auto_Tkregister2.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,23 @@ def test_Tkregister2_inputs():
1414
fsl_out=dict(argstr='--fslregout %s',
1515
),
1616
fstal=dict(argstr='--fstal',
17-
xor=['target_image', 'moving_image'],
17+
xor=['target_image', 'moving_image', 'reg_file'],
1818
),
1919
fstarg=dict(argstr='--fstarg',
2020
xor=['target_image'],
2121
),
2222
ignore_exception=dict(nohash=True,
2323
usedefault=True,
2424
),
25+
invert_lta_in=dict(requires=['lta_in'],
26+
),
27+
invert_lta_out=dict(argstr='--ltaout-inv',
28+
requires=['lta_in'],
29+
),
30+
lta_in=dict(argstr='--lta %s',
31+
),
32+
lta_out=dict(argstr='--ltaout %s',
33+
),
2534
moving_image=dict(argstr='--mov %s',
2635
mandatory=True,
2736
),
@@ -57,6 +66,7 @@ def test_Tkregister2_inputs():
5766

5867
def test_Tkregister2_outputs():
5968
output_map = dict(fsl_file=dict(),
69+
lta_file=dict(),
6070
reg_file=dict(),
6171
)
6272
outputs = Tkregister2.output_spec()

nipype/interfaces/freesurfer/utils.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,8 +1349,23 @@ class Tkregister2InputSpec(FSTraitedSpec):
13491349

13501350
moving_image = File(exists=True, mandatory=True, argstr="--mov %s",
13511351
desc='moving volume')
1352+
# Input registration file options
13521353
fsl_in_matrix = File(exists=True, argstr="--fsl %s",
13531354
desc='fsl-style registration input matrix')
1355+
xfm = File(exists=True, argstr='--xfm %s',
1356+
desc='use a matrix in MNI coordinates as initial registration')
1357+
lta_in = File(exists=True, argstr='--lta %s',
1358+
desc='use a matrix in MNI coordinates as initial registration')
1359+
invert_lta_in = traits.Bool(requires=['lta_in'],
1360+
desc='Invert input LTA before applying')
1361+
# Output registration file options
1362+
fsl_out = traits.Either(True, File, argstr='--fslregout %s',
1363+
desc='compute an FSL-compatible resgitration matrix')
1364+
lta_out = traits.Either(True, File, argstr='--ltaout %s',
1365+
desc='output registration file (LTA format)')
1366+
invert_lta_out = traits.Bool(argstr='--ltaout-inv', requires=['lta_in'],
1367+
desc='Invert input LTA before applying')
1368+
13541369
subject_id = traits.String(argstr="--s %s",
13551370
desc='freesurfer subject ID')
13561371
noedit = traits.Bool(True, argstr="--noedit", usedefault=True,
@@ -1361,19 +1376,16 @@ class Tkregister2InputSpec(FSTraitedSpec):
13611376
reg_header = traits.Bool(False, argstr='--regheader',
13621377
desc='compute regstration from headers')
13631378
fstal = traits.Bool(False, argstr='--fstal',
1364-
xor=['target_image', 'moving_image'],
1379+
xor=['target_image', 'moving_image', 'reg_file'],
13651380
desc='set mov to be tal and reg to be tal xfm')
13661381
movscale = traits.Float(argstr='--movscale %f',
13671382
desc='adjust registration matrix to scale mov')
1368-
xfm = File(exists=True, argstr='--xfm %s',
1369-
desc='use a matrix in MNI coordinates as initial registration')
1370-
fsl_out = File(argstr='--fslregout %s',
1371-
desc='compute an FSL-compatible resgitration matrix')
13721383

13731384

13741385
class Tkregister2OutputSpec(TraitedSpec):
13751386
reg_file = File(exists=True, desc='freesurfer-style registration file')
13761387
fsl_file = File(desc='FSL-style registration file')
1388+
lta_file = File(desc='LTA-style registration file')
13771389

13781390

13791391
class Tkregister2(FSCommand):
@@ -1413,11 +1425,34 @@ class Tkregister2(FSCommand):
14131425
input_spec = Tkregister2InputSpec
14141426
output_spec = Tkregister2OutputSpec
14151427

1428+
def _format_arg(self, name, spec, value):
1429+
if name == 'lta_in' and self.inputs.invert_lta_in:
1430+
spec = '--lta-inv %s'
1431+
if name in ('fsl_out', 'lta_out') and value is True:
1432+
value = self._list_outputs()[name]
1433+
return super(Tkregister2, self)._format_arg(name, spec, value)
1434+
14161435
def _list_outputs(self):
14171436
outputs = self._outputs().get()
1418-
outputs['reg_file'] = os.path.abspath(self.inputs.reg_file)
1419-
if isdefined(self.inputs.fsl_out):
1420-
outputs['fsl_file'] = os.path.abspath(self.inputs.fsl_out)
1437+
reg_file = os.path.abspath(self.inputs.reg_file)
1438+
outputs['reg_file'] = reg_file
1439+
1440+
cwd = os.getcwd()
1441+
fsl_out = self.inputs.fsl_out
1442+
if isdefined(fsl_out):
1443+
if fsl_out is True:
1444+
outputs['fsl_file'] = fname_presuffix(
1445+
reg_file, suffix='.mat', newpath=cwd, use_ext=False)
1446+
else:
1447+
outputs['fsl_file'] = os.path.abspath(self.inputs.fsl_out)
1448+
1449+
lta_out = self.inputs.lta_out
1450+
if isdefined(lta_out):
1451+
if lta_out is True:
1452+
outputs['lta_file'] = fname_presuffix(
1453+
reg_file, suffix='.lta', newpath=cwd, use_ext=False)
1454+
else:
1455+
outputs['lta_file'] = os.path.abspath(self.inputs.lta_out)
14211456
return outputs
14221457

14231458
def _gen_outfilename(self):

0 commit comments

Comments
 (0)