Skip to content

Commit c6351fc

Browse files
committed
FIX: Restore AFNICommand._get_fname, required by some interfaces
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.
1 parent cffb1f2 commit c6351fc

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

nipype/interfaces/afni/base.py

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

241287
def no_afni():
242288
"""Check whether AFNI is not available."""

0 commit comments

Comments
 (0)