From e6a1cc71fbbc650f4e64d8fae78a4b801d23d386 Mon Sep 17 00:00:00 2001 From: oesteban Date: Mon, 7 Oct 2019 16:16:53 -0700 Subject: [PATCH] FIX: Restore ``AFNICommand._get_fname``, required by some interfaces In #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). Also remove a definition of the same function for ``Deconvolve``. This PR restores the missing function. Closes #3070. --- nipype/interfaces/afni/base.py | 51 +++++++++++++++++++++++++++++++- nipype/interfaces/afni/model.py | 52 --------------------------------- 2 files changed, 50 insertions(+), 53 deletions(-) diff --git a/nipype/interfaces/afni/base.py b/nipype/interfaces/afni/base.py index 815f0619c8..1a21dcb2cf 100644 --- a/nipype/interfaces/afni/base.py +++ b/nipype/interfaces/afni/base.py @@ -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 @@ -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. + If change_ext is True, it will use the extentions specified in + 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.""" diff --git a/nipype/interfaces/afni/model.py b/nipype/interfaces/afni/model.py index 96afbe7320..ff6994b374 100644 --- a/nipype/interfaces/afni/model.py +++ b/nipype/interfaces/afni/model.py @@ -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. - If change_ext is True, it will use the extentions specified in - 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(