Skip to content

FIX: Restore AFNICommand._get_fname, required by some interfaces #3071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion nipype/interfaces/afni/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from distutils import spawn

from ... import logging, LooseVersion
from ...utils.filemanip import split_filename
from ...utils.filemanip import split_filename, fname_presuffix
from ..base import (CommandLine, traits, CommandLineInputSpec, isdefined, File,
TraitedSpec, PackageInfo)
from ...external.due import BibTeX
Expand Down Expand Up @@ -237,6 +237,55 @@ 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 not 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:
suffix = ''.join((suffix, ext)) if suffix else 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
52 changes: 0 additions & 52 deletions nipype/interfaces/afni/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,58 +309,6 @@ def _list_outputs(self):
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.

"""
from nipype.utils.filemanip import fname_presuffix

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


class RemlfitInputSpec(AFNICommandInputSpec):
# mandatory files
in_files = InputMultiPath(
Expand Down