Skip to content

Commit 89ae174

Browse files
committed
Reformated inputs and added tests
1 parent 753fb41 commit 89ae174

File tree

2 files changed

+78
-22
lines changed

2 files changed

+78
-22
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.freesurfer.utils import Surface2VolTransform
4+
def test_Surface2VolTransform_inputs():
5+
input_map = dict(ignore_exception=dict(nohash=True,
6+
usedefault=True,
7+
),
8+
transformed_file=dict(name_source=['source_file'],
9+
hash_files=False,
10+
name_template='%s_asVol.nii',
11+
argstr='--outvol %s',
12+
),
13+
hemi=dict(mandatory=True,
14+
argstr='--hemi %s',
15+
),
16+
template_file=dict(argstr='--template %s',
17+
),
18+
subject_id=dict(xor=['reg_file'],
19+
argstr='--identity %s',
20+
),
21+
args=dict(argstr='%s',
22+
),
23+
surf_name=dict(argstr='--surf %s',
24+
exists=True,
25+
),
26+
vertexvol_file=dict(name_source=['source_file'],
27+
hash_files=False,
28+
name_template='%s_asVol_vertex.nii',
29+
argstr='--vtxvol %s',
30+
),
31+
reg_file=dict(mandatory=True,
32+
argstr='--volreg %s',
33+
xor=['subject_id'],
34+
),
35+
environ=dict(nohash=True,
36+
usedefault=True,
37+
),
38+
subjects_dir=dict(argstr='--sd %s',
39+
),
40+
source_file=dict(copyfile=False,
41+
mandatory=True,
42+
argstr='--surfval %s',
43+
),
44+
projfrac=dict(argstr='--projfrac %s',
45+
exists=True,
46+
),
47+
mkmask=dict(argstr='--mkmask',
48+
),
49+
terminal_output=dict(mandatory=True,
50+
nohash=True,
51+
),
52+
)
53+
inputs = Surface2VolTransform.input_spec()
54+
55+
for key, metadata in input_map.items():
56+
for metakey, value in metadata.items():
57+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
58+
def test_Surface2VolTransform_outputs():
59+
output_map = dict(transformed_file=dict(),
60+
vertexvol_file=dict(),
61+
)
62+
outputs = Surface2VolTransform.output_spec()
63+
64+
for key, metadata in output_map.items():
65+
for metakey, value in metadata.items():
66+
yield assert_equal, getattr(outputs.traits()[key], metakey), value

nipype/interfaces/freesurfer/utils.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,21 @@ class Surface2VolTransformInputSpec(FSTraitedSpec):
387387
copyfile=False, mandatory=True,
388388
desc='This is the source of the surface values')
389389
hemi = traits.Str(argstr='--hemi %s', mandatory=True, desc='hemisphere of data')
390-
transformed_file = File(desc='Output volume', argstr='--outvol %s', genfile=True)
390+
transformed_file = File(name_template="%s_asVol.nii", desc='Output volume', argstr='--outvol %s',
391+
name_source=['source_file'], hash_files=False)
391392
reg_file = File(exists=True, argstr='--volreg %s',
392393
mandatory=True,
393394
desc='tkRAS-to-tkRAS matrix (tkregister2 format)',
394-
xor=['subject_id'])
395+
xor=['subject_id'])
395396
template_file = File(exists=True, argstr='--template %s',
396397
desc='Output template volume')
397398
mkmask = traits.Bool(desc='make a mask instead of loading surface values', argstr='--mkmask')
398-
vertexvol_file = File(desc='Path name of the vertex output volume, which is the same as output volume except that the value of each voxel is the vertex-id that is mapped to that voxel.', argstr='--vtxvol %s', genfile=True)
399-
surf_file = File(exists=True, argstr='--surf %s',desc='surfname (default is white)')
400-
projfrac_file = traits.Float(exists=True, argstr='--projfrac %s',desc='thickness fraction')
399+
vertexvol_file = File(name_template="%s_asVol_vertex.nii", desc='Path name of the vertex output '
400+
'volume, which is the same as output volume except that the value of each '
401+
'voxel is the vertex-id that is mapped to that voxel.',
402+
argstr='--vtxvol %s', name_source=['source_file'], hash_files=False)
403+
surf_name = traits.Str(exists=True, argstr='--surf %s',desc='surfname (default is white)')
404+
projfrac = traits.Float(exists=True, argstr='--projfrac %s',desc='thickness fraction')
401405
subjects_dir = traits.Str(argstr='--sd %s',desc='freesurfer subjects directory defaults to $SUBJECTS_DIR')
402406
subject_id = traits.Str(argstr='--identity %s',desc='subject id', xor=['reg_file'])
403407

@@ -417,6 +421,9 @@ class Surface2VolTransform(FSCommand):
417421
>>> xfm2vol.inputs.reg_file = 'register.mat'
418422
>>> xfm2vol.inputs.hemi = 'lh'
419423
>>> xfm2vol.inputs.template_file = 'cope1.nii.gz'
424+
>>> xfm2vol.inputs.subjects_dir = '.'
425+
>>> xfm2vol.cmdline
426+
'mri_surf2vol --hemi lh --volreg register.mat --surfval lh.cope1.mgz --sd . --template cope1.nii.gz --outvol lh.cope1_asVol.nii --vtxvol lh.cope1_asVol_vertex.nii'
420427
>>> res = xfm2vol.run()# doctest: +SKIP
421428
422429
"""
@@ -425,23 +432,6 @@ class Surface2VolTransform(FSCommand):
425432
input_spec = Surface2VolTransformInputSpec
426433
output_spec = Surface2VolTransformOutputSpec
427434

428-
def _get_outfile(self):
429-
outfile = self.inputs.transformed_file
430-
if not isdefined(outfile):
431-
outfile = self._gen_fname(self.inputs.source_file,
432-
suffix='_asVol')
433-
return outfile
434-
435-
def _list_outputs(self):
436-
outputs = self.output_spec().get()
437-
outputs['transformed_file'] = self._get_outfile()
438-
return outputs
439-
440-
def _gen_filename(self, name):
441-
if name == 'transformed_file':
442-
return self._get_outfile()
443-
return None
444-
445435
class ApplyMaskInputSpec(FSTraitedSpec):
446436

447437
in_file = File(exists=True, mandatory=True, position=-3, argstr="%s",

0 commit comments

Comments
 (0)