Skip to content

Commit d8097b9

Browse files
committed
Refactor AFNI
1 parent 1a3c420 commit d8097b9

File tree

2 files changed

+111
-391
lines changed

2 files changed

+111
-391
lines changed

nipype/interfaces/afni/base.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import os
77
import warnings
88

9-
from ...utils.filemanip import fname_presuffix
10-
from ..base import (CommandLine, traits, CommandLineInputSpec, isdefined)
9+
from ...utils.filemanip import fname_presuffix, split_filename
10+
from ..base import (CommandLine, traits, CommandLineInputSpec, isdefined, File, TraitedSpec)
1111

1212
warn = warnings.warn
1313
warnings.filterwarnings('always', category=UserWarning)
@@ -98,6 +98,9 @@ def standard_image(img_name):
9898
class AFNITraitedSpec(CommandLineInputSpec):
9999
outputtype = traits.Enum('AFNI', Info.ftypes.keys(),
100100
desc = 'AFNI output filetype')
101+
102+
103+
101104

102105

103106
class AFNICommand(CommandLine):
@@ -143,7 +146,7 @@ def set_default_outputtype(cls, outputtype):
143146
else:
144147
raise AttributeError('Invalid AFNI outputtype: %s' % outputtype)
145148

146-
def _gen_fname(self, basename, cwd=None, suffix='_afni', change_ext=True):
149+
def _gen_fname(self, basename, cwd=None, suffix='_afni', change_ext=True, prefix=''):
147150
"""Generate a filename based on the given parameters.
148151
149152
The filename will take the form: cwd/basename<suffix><ext>.
@@ -182,8 +185,42 @@ def _gen_fname(self, basename, cwd=None, suffix='_afni', change_ext=True):
182185
else:
183186
suffix = ext
184187
fname = fname_presuffix(basename, suffix = suffix,
185-
use_ext = False, newpath = cwd)
188+
use_ext = False, newpath = cwd, prefix=prefix)
186189
return fname
187190

188-
189-
191+
class AFNIPrefixInputSpec(AFNITraitedSpec):
192+
out_file = File(desc='output image file name',
193+
argstr='-prefix %s', xor=['out_file', 'prefix', 'suffix'], genfile=True, hash_files=True)
194+
prefix = traits.Str(desc='output image prefix', xor=['out_file', 'prefix'])
195+
suffix = traits.Str(desc='output image suffix', xor=['out_file', 'suffix'])
196+
197+
class AFNIPrefixCommand(AFNICommand):
198+
input_spec = AFNIPrefixInputSpec
199+
_suffix = '_afni'
200+
201+
def _gen_out_file(self, source_filename):
202+
suffix = self._suffix
203+
prefix = ''
204+
if isdefined(self.inputs.prefix):
205+
prefix = self.inputs.prefix
206+
if isdefined(self.inputs.suffix):
207+
suffix = self.inputs.suffix
208+
209+
_, base, _ = split_filename(source_filename)
210+
return self._gen_fname(basename=base, prefix=prefix, suffix=suffix)
211+
212+
def _gen_filename(self, name):
213+
if name == 'out_file':
214+
return self._gen_out_file(self.inputs.in_file)
215+
return None
216+
217+
def _list_outputs(self):
218+
outputs = self.output_spec().get()
219+
outputs['out_file'] = self.inputs.out_file
220+
if not isdefined(outputs['out_file']):
221+
outputs['out_file'] = self._gen_filename('out_file')
222+
return outputs
223+
224+
class AFNIPrefixOutputSpec(TraitedSpec):
225+
out_file = File(desc='output file',
226+
exists=True)

0 commit comments

Comments
 (0)