Skip to content

Commit 016bc6d

Browse files
committed
Merge pull request #894 from oesteban/enh/FreeSurferMRIPretess
enh: Freesurfer mri_pretess
2 parents 9a16838 + 2f2e47c commit 016bc6d

File tree

6 files changed

+129
-1
lines changed

6 files changed

+129
-1
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Next Release
22
============
33

4+
* ENH: New Freesurfer interface: MRIPretess
45
* ENH: New miscelaneous interface: AddCSVRow
56
* ENH: FUGUE interface has been refactored to use the name_template system, 3 examples
67
added to doctests, some bugs solved.

nipype/interfaces/freesurfer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
from .model import (MRISPreproc, GLMFit, OneSampleTTest, Binarize, Concatenate,
1111
SegStats, Label2Vol, MS_LDA)
1212
from .utils import (SampleToSurface, SurfaceSmooth, SurfaceTransform, Surface2VolTransform,
13-
SurfaceSnapshots,ApplyMask, MRIsConvert, MRITessellate,
13+
SurfaceSnapshots,ApplyMask, MRIsConvert, MRITessellate, MRIPretess,
1414
MRIMarchingCubes, SmoothTessellation, MakeAverageSubject,
1515
ExtractMainComponent)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.freesurfer.utils import MRIPretess
4+
5+
def test_MRIPretess_inputs():
6+
input_map = dict(args=dict(argstr='%s',
7+
),
8+
environ=dict(nohash=True,
9+
usedefault=True,
10+
),
11+
ignore_exception=dict(nohash=True,
12+
usedefault=True,
13+
),
14+
in_filled=dict(argstr='%s',
15+
mandatory=True,
16+
position=-4,
17+
),
18+
in_norm=dict(argstr='%s',
19+
mandatory=True,
20+
position=-2,
21+
),
22+
keep=dict(argstr='-keep',
23+
),
24+
label=dict(argstr='%s',
25+
mandatory=True,
26+
position=-3,
27+
usedefault=True,
28+
),
29+
nocorners=dict(argstr='-nocorners',
30+
),
31+
out_file=dict(argstr='%s',
32+
genfile=True,
33+
position=-1,
34+
),
35+
subjects_dir=dict(),
36+
terminal_output=dict(mandatory=True,
37+
nohash=True,
38+
),
39+
test=dict(argstr='-test',
40+
),
41+
)
42+
inputs = MRIPretess.input_spec()
43+
44+
for key, metadata in input_map.items():
45+
for metakey, value in metadata.items():
46+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
47+
48+
def test_MRIPretess_outputs():
49+
output_map = dict(out_file=dict(),
50+
)
51+
outputs = MRIPretess.output_spec()
52+
53+
for key, metadata in output_map.items():
54+
for metakey, value in metadata.items():
55+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
56+

nipype/interfaces/freesurfer/utils.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,77 @@ def _gen_outfilename(self):
923923
_, name, ext = split_filename(self.inputs.in_file)
924924
return name + ext + '_' + str(self.inputs.label_value)
925925

926+
927+
class MRIPretessInputSpec(FSTraitedSpec):
928+
in_filled = File(exists=True, mandatory=True, position=-4, argstr='%s',
929+
desc=('filled volume, usually wm.mgz'))
930+
label = traits.Either(traits.Str('wm'), traits.Int(1), argstr='%s', default='wm',
931+
mandatory=True, usedefault=True, position=-3,
932+
desc=('label to be picked up, can be a Freesurfer\'s string like '
933+
'\'wm\' or a label value (e.g. 127 for rh or 255 for lh)'))
934+
in_norm = File(exists=True, mandatory=True, position=-2, argstr='%s',
935+
desc=('the normalized, brain-extracted T1w image. Usually norm.mgz'))
936+
out_file = File(position=-1, argstr='%s', genfile=True,
937+
desc=('the output file after mri_pretess.'))
938+
939+
940+
nocorners = traits.Bool(False, argstr='-nocorners', desc=('do not remove corner configurations'
941+
' in addition to edge ones.'))
942+
keep = traits.Bool(False, argstr='-keep', desc=('keep WM edits'))
943+
test = traits.Bool(False, argstr='-test', desc=('adds a voxel that should be removed by '
944+
'mri_pretess. The value of the voxel is set to that of an ON-edited WM, '
945+
'so it should be kept with -keep. The output will NOT be saved.'))
946+
947+
class MRIPretessOutputSpec(TraitedSpec):
948+
out_file = File(exists=True, desc='output file after mri_pretess')
949+
950+
951+
class MRIPretess(FSCommand):
952+
"""
953+
Uses Freesurfer's mri_pretess to prepare volumes to be tessellated.
954+
955+
Description
956+
-----------
957+
958+
Changes white matter (WM) segmentation so that the neighbors of all
959+
voxels labeled as WM have a face in common - no edges or corners
960+
allowed.
961+
962+
Example
963+
-------
964+
965+
>>> import nipype.interfaces.freesurfer as fs
966+
>>> pretess = fs.MRIPretess()
967+
>>> pretess.inputs.in_filled = 'wm.mgz'
968+
>>> pretess.inputs.in_norm = 'norm.mgz'
969+
>>> pretess.inputs.nocorners = True
970+
>>> pretess.cmdline
971+
'mri_pretess -nocorners wm.mgz wm norm.mgz wm_pretesswm.mgz'
972+
>>> pretess.run() # doctest: +SKIP
973+
"""
974+
_cmd = 'mri_pretess'
975+
input_spec = MRIPretessInputSpec
976+
output_spec = MRIPretessOutputSpec
977+
978+
def _list_outputs(self):
979+
outputs = self.output_spec().get()
980+
outputs['out_file'] = os.path.abspath(self._gen_outfilename())
981+
return outputs
982+
983+
def _gen_filename(self, name):
984+
if name is 'out_file':
985+
return self._gen_outfilename()
986+
else:
987+
return None
988+
989+
def _gen_outfilename(self):
990+
if isdefined(self.inputs.out_file):
991+
return self.inputs.out_file
992+
else:
993+
_, name, ext = split_filename(self.inputs.in_filled)
994+
return name + '_pretess' + str(self.inputs.label) + ext
995+
996+
926997
class MRIMarchingCubesInputSpec(FSTraitedSpec):
927998
"""
928999
Uses Freesurfer's mri_mc to create surfaces by tessellating a given input volume

nipype/testing/data/norm.mgz

Whitespace-only changes.

nipype/testing/data/wm.mgz

Whitespace-only changes.

0 commit comments

Comments
 (0)