Skip to content

Commit caa6dd5

Browse files
committed
Handle output filenames correctly, add undocumented options
1 parent 34269ab commit caa6dd5

File tree

2 files changed

+73
-12
lines changed

2 files changed

+73
-12
lines changed

nipype/interfaces/freesurfer/tests/test_auto_MRIsExpand.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def test_MRIsExpand_inputs():
1010
mandatory=True,
1111
position=-2,
1212
),
13+
dt=dict(argstr='-T %g',
14+
),
1315
environ=dict(nohash=True,
1416
usedefault=True,
1517
),
@@ -20,16 +22,29 @@ def test_MRIsExpand_inputs():
2022
mandatory=True,
2123
position=-3,
2224
),
23-
out_file=dict(argstr='%s',
24-
name_source='in_file',
25-
name_template='%s.expanded',
25+
navgs=dict(argstr='-navgs %d %d',
26+
),
27+
nsurfaces=dict(argstr='-N %d',
28+
),
29+
out_name=dict(argstr='%s',
2630
position=-1,
31+
usedefault=True,
32+
),
33+
pial=dict(argstr='-pial %s',
34+
),
35+
smooth_averages=dict(argstr='-A %d',
36+
),
37+
spring=dict(argstr='-S %g',
2738
),
2839
subjects_dir=dict(),
2940
terminal_output=dict(nohash=True,
3041
),
3142
thickness=dict(argstr='-thickness',
3243
),
44+
thickness_name=dict(argstr='-thickness_name %s',
45+
),
46+
write_iterations=dict(argstr='-W %d',
47+
),
3348
)
3449
inputs = MRIsExpand.input_spec()
3550

nipype/interfaces/freesurfer/utils.py

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,19 +2909,47 @@ def _list_outputs(self):
29092909

29102910

29112911
class MRIsExpandInputSpec(FSTraitedSpec):
2912+
# Input spec derived from
2913+
# https://github.com/freesurfer/freesurfer/blob/102e053/mris_expand/mris_expand.c
29122914
in_file = File(
29132915
exists=True, mandatory=True, argstr='%s', position=-3,
29142916
desc='Surface to expand')
29152917
distance = traits.Float(
29162918
mandatory=True, argstr='%g', position=-2,
29172919
desc='Distance in mm or fraction of cortical thickness')
2918-
out_file = File(
2919-
argstr='%s', position=-1,
2920-
name_template='%s.expanded', name_source='in_file',
2921-
desc='Output surface file')
2920+
out_name = traits.Str(
2921+
'expanded', argstr='%s', position=-1, usedefault=True,
2922+
desc=('Output surface file\n'
2923+
'If missing "lh." or "rh.", derive from `in_file`'))
29222924
thickness = traits.Bool(
29232925
argstr='-thickness',
29242926
desc='Expand by fraction of cortical thickness, not mm')
2927+
thickness_name = traits.Str(
2928+
argstr="-thickness_name %s",
2929+
desc=('Name of thickness file (implicit: "thickness")\n'
2930+
'If no path, uses directory of `in_file`\n'
2931+
'If missing "lh." or "rh.", derive from `in_file`'))
2932+
navgs = traits.Tuple(
2933+
traits.Int, traits.Int,
2934+
argstr='-navgs %d %d',
2935+
desc=('Tuple of (n_averages, min_averages) parameters '
2936+
'(implicit: (16, 0))'))
2937+
pial = traits.Str(
2938+
argstr='-pial %s',
2939+
desc=('Name of pial file (implicit: "pial")\n'
2940+
'If no path, uses directory of `in_file`\n'
2941+
'If missing "lh." or "rh.", derive from `in_file`'))
2942+
spring = traits.Float(argstr='-S %g', desc="Spring term (implicit: 0.05)")
2943+
dt = traits.Float(argstr='-T %g', desc='dt (implicit: 0.25)')
2944+
write_iterations = traits.Int(
2945+
argstr='-W %d',
2946+
desc='Write snapshots of expansion every N iterations')
2947+
smooth_averages = traits.Int(
2948+
argstr='-A %d',
2949+
desc='Smooth surface with N iterations after expansion')
2950+
nsurfaces = traits.Int(
2951+
argstr='-N %d',
2952+
desc='Number of surfacces to write during expansion')
29252953

29262954

29272955
class MRIsExpandOutputSpec(TraitedSpec):
@@ -2938,12 +2966,30 @@ class MRIsExpand(FSCommand):
29382966
>>> from nipype.interfaces.freesurfer import MRIsExpand
29392967
>>> mris_expand = MRIsExpand(thickness=True, distance=0.5)
29402968
>>> mris_expand.inputs.in_file = 'lh.white'
2941-
>>> mris_expand.cmdline # doctest: +ALLOW_UNICODE
2942-
'mris_expand -thickness lh.white 0.5 lh.expanded'
2943-
>>> mris_expand.inputs.out_file = 'lh.graymid'
2944-
>>> mris_expand.cmdline # doctest: +ALLOW_UNICODE
2945-
'mris_expand -thickness lh.white 0.5 lh.graymid'
2969+
>>> mris_expand.cmdline # doctest: +ALLOW_UNICODE, +ELLIPSIS
2970+
'mris_expand -thickness lh.white 0.5 .../lh.expanded'
2971+
>>> mris_expand.inputs.out_name = 'graymid'
2972+
>>> mris_expand.cmdline # doctest: +ALLOW_UNICODE, +ELLIPSIS
2973+
'mris_expand -thickness lh.white 0.5 .../lh.graymid'
29462974
"""
29472975
_cmd = 'mris_expand'
29482976
input_spec = MRIsExpandInputSpec
29492977
output_spec = MRIsExpandOutputSpec
2978+
2979+
def _format_arg(self, name, spec, value):
2980+
if name == 'out_name':
2981+
value = self._list_outputs()['out_file']
2982+
return super(MRIsExpand, self)._format_arg(name, spec, value)
2983+
2984+
def _list_outputs(self):
2985+
outputs = self._outputs().get()
2986+
# Mimic FreeSurfer output filename derivation, but in local directory
2987+
# if no path specified
2988+
out_file = self.inputs.out_name
2989+
path, base = os.path.split(out_file)
2990+
if path == '' and base[:3] not in ('lh.', 'rh.'):
2991+
in_file = os.path.basename(self.inputs.in_file)
2992+
if in_file[:3] in ('lh.', 'rh.'):
2993+
out_file = os.path.basename(self.inputs.in_file)[:3] + base
2994+
outputs["out_file"] = os.path.abspath(out_file)
2995+
return outputs

0 commit comments

Comments
 (0)