Skip to content

Commit

Permalink
FIX: Restore AFNICommand._get_fname, required by some interfaces
Browse files Browse the repository at this point in the history
In nipy#2964 I broke some interfaces (@tsalo identified `Allineate` as one
of those) by removing the ``_get_fname`` function from the base
``AFNICommand``.

The intent was to migrate to a ``name_source``-based management of
automatically generated names, but in the case of ``Allineate``, the use
of `_get_fname` was a bit different (modifying the user-provide input
value under certain conditions to follow ANFI's ``3dAllineate``
behavior).

This PR restores the missing function. Closes nipy#3070.
  • Loading branch information
oesteban committed Oct 7, 2019
1 parent cffb1f2 commit c6351fc
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions nipype/interfaces/afni/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,52 @@ def _list_outputs(self):
outputs[name] = outputs[name] + "+orig.BRIK"
return outputs

def _gen_fname(self,
basename,
cwd=None,
suffix=None,
change_ext=True,
ext=None):
"""Generate a filename based on the given parameters.
The filename will take the form: cwd/basename<suffix><ext>.
If change_ext is True, it will use the extentions specified in
<instance>intputs.output_type.
Parameters
----------
basename : str
Filename to base the new filename on.
cwd : str
Path to prefix to the new filename. (default is os.getcwd())
suffix : str
Suffix to add to the `basename`. (defaults is '' )
change_ext : bool
Flag to change the filename extension to the FSL output type.
(default True)
Returns
-------
fname : str
New filename based on given parameters.
"""

if basename == '':
msg = 'Unable to generate filename for command %s. ' % self.cmd
msg += 'basename is not set!'
raise ValueError(msg)
if cwd is None:
cwd = os.getcwd()
if ext is None:
ext = Info.output_type_to_ext(self.inputs.outputtype)
if change_ext:
if suffix:
suffix = ''.join((suffix, ext))
else:
suffix = ext
if suffix is None:
suffix = ''
fname = fname_presuffix(
basename, suffix=suffix, use_ext=False, newpath=cwd)
return fname


def no_afni():
"""Check whether AFNI is not available."""
Expand Down

0 comments on commit c6351fc

Please sign in to comment.