Skip to content

Commit f023334

Browse files
committed
Simplifying interfaces by using name_template, name_source and editing tests
1 parent 9b275a7 commit f023334

File tree

10 files changed

+228
-449
lines changed

10 files changed

+228
-449
lines changed

nipype/interfaces/niftyfit/asl.py

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
>>> os.chdir(datadir)
1212
"""
1313

14-
from ..base import TraitedSpec, traits, isdefined, CommandLineInputSpec
14+
from ..base import TraitedSpec, traits, CommandLineInputSpec
1515
from .base import NiftyFitCommand, get_custom_path
1616

1717

@@ -28,11 +28,17 @@ class FitAslInputSpec(CommandLineInputSpec):
2828

2929
# *** Output options:
3030
desc = 'Filename of the Cerebral Blood Flow map (in ml/100g/min).'
31-
cbf_file = traits.File(genfile=True, argstr='-cbf %s', desc=desc)
31+
cbf_file = traits.File(name_source=['source_file'],
32+
name_template='%s_cbf.nii.gz',
33+
argstr='-cbf %s', desc=desc)
3234
desc = 'Filename of the CBF error map.'
33-
error_file = traits.File(genfile=True, argstr='-error %s', desc=desc)
35+
error_file = traits.File(name_source=['source_file'],
36+
name_template='%s_error.nii.gz',
37+
argstr='-error %s', desc=desc)
3438
desc = 'Filename of the synthetic ASL data.'
35-
syn_file = traits.File(genfile=True, argstr='-syn %s', desc=desc)
39+
syn_file = traits.File(name_source=['source_file'],
40+
name_template='%s_syn.nii.gz',
41+
argstr='-syn %s', desc=desc)
3642

3743
# *** Input options (see also fit_qt1 for generic T1 fitting):
3844
desc = 'Filename of the estimated input T1 map (in ms).'
@@ -139,44 +145,12 @@ class FitAsl(NiftyFitCommand):
139145
>>> from nipype.interfaces import niftyfit
140146
>>> node = niftyfit.FitAsl()
141147
>>> node.inputs.source_file = 'asl.nii.gz'
142-
>>> node.cmdline # doctest: +ELLIPSIS +ALLOW_UNICODE
143-
'fit_asl -source asl.nii.gz -cbf .../asl_cbf.nii.gz -error \
144-
.../asl_error.nii.gz -syn .../asl_syn.nii.gz'
148+
>>> node.cmdline # doctest: +ALLOW_UNICODE
149+
'fit_asl -source asl.nii.gz -cbf asl_cbf.nii.gz -error asl_error.nii.gz \
150+
-syn asl_syn.nii.gz'
145151
146152
"""
147153
_cmd = get_custom_path('fit_asl')
148154
input_spec = FitAslInputSpec
149155
output_spec = FitAslOutputSpec
150156
_suffix = '_fit_asl'
151-
152-
def _gen_filename(self, name):
153-
if name == 'error_file':
154-
return self._gen_fname(self.inputs.source_file,
155-
suffix='_error', ext='.nii.gz')
156-
if name == 'syn_file':
157-
return self._gen_fname(self.inputs.source_file,
158-
suffix='_syn', ext='.nii.gz')
159-
if name == 'cbf_file':
160-
return self._gen_fname(self.inputs.source_file,
161-
suffix='_cbf', ext='.nii.gz')
162-
return None
163-
164-
def _list_outputs(self):
165-
outputs = self.output_spec().get()
166-
167-
if isdefined(self.inputs.error_file):
168-
outputs['error_file'] = self.inputs.error_file
169-
else:
170-
outputs['error_file'] = self._gen_filename('error_file')
171-
172-
if isdefined(self.inputs.syn_file):
173-
outputs['syn_file'] = self.inputs.syn_file
174-
else:
175-
outputs['syn_file'] = self._gen_filename('syn_file')
176-
177-
if isdefined(self.inputs.cbf_file):
178-
outputs['cbf_file'] = self.inputs.cbf_file
179-
else:
180-
outputs['cbf_file'] = self._gen_filename('cbf_file')
181-
182-
return outputs

0 commit comments

Comments
 (0)