Skip to content

Commit 5976769

Browse files
authored
Merge pull request #3071 from oesteban/fix/3070
FIX: Restore ``AFNICommand._get_fname``, required by some interfaces
2 parents 0e11cea + e6a1cc7 commit 5976769

File tree

2 files changed

+50
-53
lines changed

2 files changed

+50
-53
lines changed

nipype/interfaces/afni/base.py

+50-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from distutils import spawn
1212

1313
from ... import logging, LooseVersion
14-
from ...utils.filemanip import split_filename
14+
from ...utils.filemanip import split_filename, fname_presuffix
1515
from ..base import (CommandLine, traits, CommandLineInputSpec, isdefined, File,
1616
TraitedSpec, PackageInfo)
1717
from ...external.due import BibTeX
@@ -237,6 +237,55 @@ def _list_outputs(self):
237237
outputs[name] = outputs[name] + "+orig.BRIK"
238238
return outputs
239239

240+
def _gen_fname(self,
241+
basename,
242+
cwd=None,
243+
suffix=None,
244+
change_ext=True,
245+
ext=None):
246+
"""
247+
Generate a filename based on the given parameters.
248+
249+
The filename will take the form: cwd/basename<suffix><ext>.
250+
If change_ext is True, it will use the extentions specified in
251+
<instance>intputs.output_type.
252+
253+
Parameters
254+
----------
255+
basename : str
256+
Filename to base the new filename on.
257+
cwd : str
258+
Path to prefix to the new filename. (default is os.getcwd())
259+
suffix : str
260+
Suffix to add to the `basename`. (defaults is '' )
261+
change_ext : bool
262+
Flag to change the filename extension to the FSL output type.
263+
(default True)
264+
265+
Returns
266+
-------
267+
fname : str
268+
New filename based on given parameters.
269+
270+
"""
271+
if not basename:
272+
msg = 'Unable to generate filename for command %s. ' % self.cmd
273+
msg += 'basename is not set!'
274+
raise ValueError(msg)
275+
276+
if cwd is None:
277+
cwd = os.getcwd()
278+
if ext is None:
279+
ext = Info.output_type_to_ext(self.inputs.outputtype)
280+
if change_ext:
281+
suffix = ''.join((suffix, ext)) if suffix else ext
282+
283+
if suffix is None:
284+
suffix = ''
285+
fname = fname_presuffix(
286+
basename, suffix=suffix, use_ext=False, newpath=cwd)
287+
return fname
288+
240289

241290
def no_afni():
242291
"""Check whether AFNI is not available."""

nipype/interfaces/afni/model.py

-52
Original file line numberDiff line numberDiff line change
@@ -309,58 +309,6 @@ def _list_outputs(self):
309309
return outputs
310310

311311

312-
def _gen_fname(self,
313-
basename,
314-
cwd=None,
315-
suffix=None,
316-
change_ext=True,
317-
ext=None):
318-
"""Generate a filename based on the given parameters.
319-
320-
The filename will take the form: cwd/basename<suffix><ext>.
321-
If change_ext is True, it will use the extentions specified in
322-
<instance>intputs.output_type.
323-
324-
Parameters
325-
----------
326-
basename : str
327-
Filename to base the new filename on.
328-
cwd : str
329-
Path to prefix to the new filename. (default is os.getcwd())
330-
suffix : str
331-
Suffix to add to the `basename`. (defaults is '' )
332-
change_ext : bool
333-
Flag to change the filename extension to the FSL output type.
334-
(default True)
335-
336-
Returns
337-
-------
338-
fname : str
339-
New filename based on given parameters.
340-
341-
"""
342-
from nipype.utils.filemanip import fname_presuffix
343-
344-
if basename == '':
345-
msg = 'Unable to generate filename for command %s. ' % self.cmd
346-
msg += 'basename is not set!'
347-
raise ValueError(msg)
348-
if cwd is None:
349-
cwd = os.getcwd()
350-
if ext is None:
351-
ext = Info.output_type_to_ext(self.inputs.outputtype)
352-
if change_ext:
353-
if suffix:
354-
suffix = ''.join((suffix, ext))
355-
else:
356-
suffix = ext
357-
if suffix is None:
358-
suffix = ''
359-
fname = fname_presuffix(
360-
basename, suffix=suffix, use_ext=False, newpath=cwd)
361-
return fname
362-
363-
364312
class RemlfitInputSpec(AFNICommandInputSpec):
365313
# mandatory files
366314
in_files = InputMultiPath(

0 commit comments

Comments
 (0)