Skip to content

Commit d10791e

Browse files
committed
[Freesurfer] Improved Tkregister2
* Added some inputs * Corrected output name generation * Added doctests
1 parent f626d94 commit d10791e

File tree

2 files changed

+79
-17
lines changed

2 files changed

+79
-17
lines changed

nipype/interfaces/freesurfer/tests/test_auto_Tkregister2.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,46 @@ def test_Tkregister2_inputs():
88
environ=dict(nohash=True,
99
usedefault=True,
1010
),
11+
fsl=dict(argstr='--fsl %s',
12+
),
1113
fsl_in_matrix=dict(argstr='--fsl %s',
1214
),
15+
fsl_out=dict(argstr='--fslregout %s',
16+
),
17+
fstal=dict(argstr='--fstal',
18+
xor=['target_image', 'moving_image'],
19+
),
20+
fstarg=dict(argstr='--fstarg',
21+
xor=['target_image'],
22+
),
1323
ignore_exception=dict(nohash=True,
1424
usedefault=True,
1525
),
1626
moving_image=dict(argstr='--mov %s',
1727
mandatory=True,
1828
),
29+
movscale=dict(argstr='--movscale %f',
30+
),
1931
noedit=dict(argstr='--noedit',
2032
usedefault=True,
2133
),
2234
reg_file=dict(argstr='--reg %s',
2335
mandatory=True,
24-
name_source='fsl',
25-
name_template='%s.dat',
36+
usedefault=True,
37+
),
38+
reg_header=dict(argstr='--regheader',
2639
),
2740
subject_id=dict(argstr='--s %s',
28-
mandatory=True,
2941
),
3042
subjects_dir=dict(),
43+
target_image=dict(argstr='--targ %s',
44+
xor=['fstarg'],
45+
),
3146
terminal_output=dict(mandatory=True,
3247
nohash=True,
3348
),
49+
xfm=dict(argstr='--xfm %s',
50+
),
3451
)
3552
inputs = Tkregister2.input_spec()
3653

@@ -39,7 +56,8 @@ def test_Tkregister2_inputs():
3956
yield assert_equal, getattr(inputs.traits()[key], metakey), value
4057

4158
def test_Tkregister2_outputs():
42-
output_map = dict(reg_file=dict(),
59+
output_map = dict(fsl_file=dict(),
60+
reg_file=dict(),
4361
)
4462
outputs = Tkregister2.output_spec()
4563

nipype/interfaces/freesurfer/utils.py

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,39 +1191,83 @@ class ExtractMainComponent(CommandLine):
11911191

11921192

11931193
class Tkregister2InputSpec(FSTraitedSpec):
1194+
target_image = File(exists=True, argstr="--targ %s",
1195+
xor=['fstarg'],
1196+
desc='target volume')
1197+
fstarg = traits.Bool(False, argstr='--fstarg',
1198+
xor=['target_image'],
1199+
desc='use subject\'s T1 as reference')
1200+
11941201
moving_image = File(exists=True, mandatory=True, argstr="--mov %s",
1195-
desc='moving volume')
1202+
desc='moving volume')
11961203
fsl_in_matrix = File(exists=True, argstr="--fsl %s",
1197-
desc='fsl-style registration input matrix')
1198-
subject_id = traits.String(argstr="--s %s", mandatory=True,
1204+
desc='fsl-style registration input matrix')
1205+
subject_id = traits.String(argstr="--s %s",
11991206
desc='freesurfer subject ID')
1200-
noedit = traits.Bool(True, argstr="--noedit", desc='do not open edit window (exit)', usedefault=True)
1201-
reg_file = File(name_template='%s.dat', name_source='fsl',
1202-
mandatory=True, argstr="--reg %s",
1203-
desc='freesurfer-style registration file')
1207+
noedit = traits.Bool(True, argstr="--noedit", usedefault=True,
1208+
desc='do not open edit window (exit)')
1209+
reg_file = File('register.dat', usedefault=True,
1210+
mandatory=True, argstr="--reg %s",
1211+
desc='freesurfer-style registration file')
1212+
reg_header = traits.Bool(False, argstr='--regheader',
1213+
desc='compute regstration from headers')
1214+
fstal = traits.Bool(False, argstr='--fstal',
1215+
xor=['target_image', 'moving_image'],
1216+
desc='set mov to be tal and reg to be tal xfm')
1217+
movscale = traits.Float(argstr='--movscale %f',
1218+
desc='adjust registration matrix to scale mov')
1219+
fsl = File(exists=True, argstr='--fsl %s',
1220+
desc='use the matrix produced by FSL as initial registration')
1221+
xfm = File(exists=True, argstr='--xfm %s',
1222+
desc='use a matrix in MNI coordinates as initial registration')
1223+
fsl_out = File(argstr='--fslregout %s',
1224+
desc='compute an FSL-compatible resgitration matrix')
12041225

12051226

12061227
class Tkregister2OutputSpec(TraitedSpec):
12071228
reg_file = File(exists=True, desc='freesurfer-style registration file')
1229+
fsl_file = File(desc='FSL-style registration file')
12081230

12091231

12101232
class Tkregister2(FSCommand):
1211-
"""Use tkregister2 without the manual editing stage to convert
1212-
FSL-style registration matrix (.mat) to FreeSurfer-style registration matrix (.dat)
1233+
"""
12131234
12141235
Examples
12151236
--------
12161237
1238+
Get transform matrix between orig (*tkRAS*) and native (*scannerRAS*)
1239+
coordinates in Freesurfer. Implements the first step of mapping surfaces
1240+
to native space in `this guide
1241+
<http://surfer.nmr.mgh.harvard.edu/fswiki/FsAnat-to-NativeAnat>`_.
1242+
12171243
>>> from nipype.interfaces.freesurfer import Tkregister2
1218-
>>> tk2 = Tkregister2(reg_file='register.dat')
1244+
>>> tk2 = Tkregister2(reg_file='T1_to_native.dat')
1245+
>>> tk2.inputs.moving_image = 'T1.mgz'
1246+
>>> tk2.inputs.target_image = 'structural.nii'
1247+
>>> tk2.inputs.reg_header = True
1248+
>>> tk2.cmdline
1249+
'tkregister2 --mov T1.mgz --noedit --reg T1_to_native.dat --regheader \
1250+
--targ structural.nii'
1251+
>>> tk2.run() # doctest: +SKIP
1252+
1253+
The example below uses tkregister2 without the manual editing
1254+
stage to convert FSL-style registration matrix (.mat) to
1255+
FreeSurfer-style registration matrix (.dat)
1256+
1257+
>>> from nipype.interfaces.freesurfer import Tkregister2
1258+
>>> tk2 = Tkregister2()
12191259
>>> tk2.inputs.moving_image = 'epi.nii'
12201260
>>> tk2.inputs.fsl_in_matrix = 'flirt.mat'
1221-
>>> tk2.inputs.subject_id = 'test_subject'
1261+
>>> tk2.cmdline
1262+
'tkregister2 --fsl flirt.mat --mov epi.nii --noedit --reg register.dat'
12221263
>>> tk2.run() # doctest: +SKIP
12231264
"""
12241265
_cmd = "tkregister2"
12251266
input_spec = Tkregister2InputSpec
12261267
output_spec = Tkregister2OutputSpec
1227-
12281268

1229-
1269+
def _list_outputs(self):
1270+
outputs = super(Tkregister2, self)._list_outputs()
1271+
if isdefined(self.inputs.fsl_out):
1272+
outputs['fsl_file'] = op.abspath(self.inputs.fsl_out)
1273+
return outputs

0 commit comments

Comments
 (0)