Skip to content

[Freesurfer] Improved Tkregister2 #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions nipype/interfaces/freesurfer/tests/test_auto_Tkregister2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,42 @@ def test_Tkregister2_inputs():
),
fsl_in_matrix=dict(argstr='--fsl %s',
),
fsl_out=dict(argstr='--fslregout %s',
),
fstal=dict(argstr='--fstal',
xor=['target_image', 'moving_image'],
),
fstarg=dict(argstr='--fstarg',
xor=['target_image'],
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
moving_image=dict(argstr='--mov %s',
mandatory=True,
),
movscale=dict(argstr='--movscale %f',
),
noedit=dict(argstr='--noedit',
usedefault=True,
),
reg_file=dict(argstr='--reg %s',
mandatory=True,
name_source='fsl',
name_template='%s.dat',
usedefault=True,
),
reg_header=dict(argstr='--regheader',
),
subject_id=dict(argstr='--s %s',
mandatory=True,
),
subjects_dir=dict(),
target_image=dict(argstr='--targ %s',
xor=['fstarg'],
),
terminal_output=dict(mandatory=True,
nohash=True,
),
xfm=dict(argstr='--xfm %s',
),
)
inputs = Tkregister2.input_spec()

Expand All @@ -39,7 +54,8 @@ def test_Tkregister2_inputs():
yield assert_equal, getattr(inputs.traits()[key], metakey), value

def test_Tkregister2_outputs():
output_map = dict(reg_file=dict(),
output_map = dict(fsl_file=dict(),
reg_file=dict(),
)
outputs = Tkregister2.output_spec()

Expand Down
76 changes: 63 additions & 13 deletions nipype/interfaces/freesurfer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,39 +1191,89 @@ class ExtractMainComponent(CommandLine):


class Tkregister2InputSpec(FSTraitedSpec):
target_image = File(exists=True, argstr="--targ %s",
xor=['fstarg'],
desc='target volume')
fstarg = traits.Bool(False, argstr='--fstarg',
xor=['target_image'],
desc='use subject\'s T1 as reference')

moving_image = File(exists=True, mandatory=True, argstr="--mov %s",
desc='moving volume')
desc='moving volume')
fsl_in_matrix = File(exists=True, argstr="--fsl %s",
desc='fsl-style registration input matrix')
subject_id = traits.String(argstr="--s %s", mandatory=True,
desc='fsl-style registration input matrix')
subject_id = traits.String(argstr="--s %s",
desc='freesurfer subject ID')
noedit = traits.Bool(True, argstr="--noedit", desc='do not open edit window (exit)', usedefault=True)
reg_file = File(name_template='%s.dat', name_source='fsl',
mandatory=True, argstr="--reg %s",
desc='freesurfer-style registration file')
noedit = traits.Bool(True, argstr="--noedit", usedefault=True,
desc='do not open edit window (exit)')
reg_file = File('register.dat', usedefault=True,
mandatory=True, argstr='--reg %s',
desc='freesurfer-style registration file')
reg_header = traits.Bool(False, argstr='--regheader',
desc='compute regstration from headers')
fstal = traits.Bool(False, argstr='--fstal',
xor=['target_image', 'moving_image'],
desc='set mov to be tal and reg to be tal xfm')
movscale = traits.Float(argstr='--movscale %f',
desc='adjust registration matrix to scale mov')
xfm = File(exists=True, argstr='--xfm %s',
desc='use a matrix in MNI coordinates as initial registration')
fsl_out = File(argstr='--fslregout %s',
desc='compute an FSL-compatible resgitration matrix')


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


class Tkregister2(FSCommand):
"""Use tkregister2 without the manual editing stage to convert
FSL-style registration matrix (.mat) to FreeSurfer-style registration matrix (.dat)
"""

Examples
--------

Get transform matrix between orig (*tkRAS*) and native (*scannerRAS*)
coordinates in Freesurfer. Implements the first step of mapping surfaces
to native space in `this guide
<http://surfer.nmr.mgh.harvard.edu/fswiki/FsAnat-to-NativeAnat>`_.

>>> from nipype.interfaces.freesurfer import Tkregister2
>>> tk2 = Tkregister2(reg_file='T1_to_native.dat')
>>> tk2.inputs.moving_image = 'T1.mgz'
>>> tk2.inputs.target_image = 'structural.nii'
>>> tk2.inputs.reg_header = True
>>> tk2.cmdline
'tkregister2 --mov T1.mgz --noedit --reg T1_to_native.dat --regheader \
--targ structural.nii'
>>> tk2.run() # doctest: +SKIP

The example below uses tkregister2 without the manual editing
stage to convert FSL-style registration matrix (.mat) to
FreeSurfer-style registration matrix (.dat)

>>> from nipype.interfaces.freesurfer import Tkregister2
>>> tk2 = Tkregister2(reg_file='register.dat')
>>> tk2 = Tkregister2()
>>> tk2.inputs.moving_image = 'epi.nii'
>>> tk2.inputs.fsl_in_matrix = 'flirt.mat'
>>> tk2.inputs.subject_id = 'test_subject'
>>> tk2.cmdline
'tkregister2 --fsl flirt.mat --mov epi.nii --noedit --reg register.dat'
>>> tk2.run() # doctest: +SKIP
"""
_cmd = "tkregister2"
input_spec = Tkregister2InputSpec
output_spec = Tkregister2OutputSpec



def _list_outputs(self):
outputs = self._outputs().get()
outputs['reg_file'] = os.path.abspath(self.inputs.reg_file)
if isdefined(self.inputs.fsl_out):
outputs['fsl_file'] = op.abspath(self.inputs.fsl_out)
return outputs

def _gen_outfilename(self):
if isdefined(self.inputs.out_file):
return os.path.abspath(self.inputs.out_file)
else:
_, name, ext = split_filename(self.inputs.in_file)
return os.path.abspath(name + '_smoothed' + ext)