diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 13a065c27c..9ede8d13e0 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -218,7 +218,9 @@ class AllineateInputSpec(AFNICommandInputSpec): out_file = File( desc='output file from 3dAllineate', argstr='-prefix %s', - genfile=True, + name_template='%s_allineate', + name_source='in_file', + hash_files=False, xor=['allcostx']) out_param_file = File( argstr='-1Dparam_save %s', @@ -424,11 +426,11 @@ class AllineateInputSpec(AFNICommandInputSpec): _dirs = ['X', 'Y', 'Z', 'I', 'J', 'K'] nwarp_fixmot = traits.List( traits.Enum(*_dirs), - argstr='-nwarp_fixmot%s', + argstr='-nwarp_fixmot%s...', desc='To fix motion along directions.') nwarp_fixdep = traits.List( traits.Enum(*_dirs), - argstr='-nwarp_fixdep%s', + argstr='-nwarp_fixdep%s...', desc='To fix non-linear warp dependency along directions.') verbose = traits.Bool( argstr='-verb', desc='Print out verbose progress reports.') @@ -465,7 +467,6 @@ class Allineate(AFNICommand): '3dAllineate -source functional.nii -prefix functional_allineate.nii -1Dmatrix_apply cmatrix.mat' >>> res = allineate.run() # doctest: +SKIP - >>> from nipype.interfaces import afni >>> allineate = afni.Allineate() >>> allineate.inputs.in_file = 'functional.nii' >>> allineate.inputs.reference = 'structural.nii' @@ -473,23 +474,22 @@ class Allineate(AFNICommand): >>> allineate.cmdline '3dAllineate -source functional.nii -base structural.nii -allcostx |& tee out.allcostX.txt' >>> res = allineate.run() # doctest: +SKIP + + >>> allineate = afni.Allineate() + >>> allineate.inputs.in_file = 'functional.nii' + >>> allineate.inputs.reference = 'structural.nii' + >>> allineate.inputs.nwarp_fixmot = ['X', 'Y'] + >>> allineate.cmdline + '3dAllineate -source functional.nii -nwarp_fixmotX -nwarp_fixmotY -prefix functional_allineate -base structural.nii' + >>> res = allineate.run() # doctest: +SKIP """ _cmd = '3dAllineate' input_spec = AllineateInputSpec output_spec = AllineateOutputSpec - def _format_arg(self, name, trait_spec, value): - if name == 'nwarp_fixmot' or name == 'nwarp_fixdep': - arg = ' '.join([trait_spec.argstr % v for v in value]) - return arg - return super(Allineate, self)._format_arg(name, trait_spec, value) - def _list_outputs(self): - outputs = self.output_spec().get() - - if self.inputs.out_file: - outputs['out_file'] = op.abspath(self.inputs.out_file) + outputs = super(Allineate, self)._list_outputs() if self.inputs.out_weight_file: outputs['out_weight_file'] = op.abspath( @@ -512,16 +512,10 @@ def _list_outputs(self): outputs['out_param_file'] = op.abspath( self.inputs.out_param_file) - if isdefined(self.inputs.allcostx): - outputs['allcostX'] = os.path.abspath( - os.path.join(os.getcwd(), self.inputs.allcostx)) + if self.inputs.allcostx: + outputs['allcostX'] = os.path.abspath(self.inputs.allcostx) return outputs - def _gen_filename(self, name): - if name == 'out_file': - return self._list_outputs()[name] - return None - class AutoTcorrelateInputSpec(AFNICommandInputSpec): in_file = File( diff --git a/nipype/interfaces/afni/tests/test_auto_Allineate.py b/nipype/interfaces/afni/tests/test_auto_Allineate.py index 59b1929fbe..1c5476a429 100644 --- a/nipype/interfaces/afni/tests/test_auto_Allineate.py +++ b/nipype/interfaces/afni/tests/test_auto_Allineate.py @@ -61,12 +61,14 @@ def test_Allineate_inputs(): usedefault=True, ), nwarp=dict(argstr='-nwarp %s', ), - nwarp_fixdep=dict(argstr='-nwarp_fixdep%s', ), - nwarp_fixmot=dict(argstr='-nwarp_fixmot%s', ), + nwarp_fixdep=dict(argstr='-nwarp_fixdep%s...', ), + nwarp_fixmot=dict(argstr='-nwarp_fixmot%s...', ), one_pass=dict(argstr='-onepass', ), out_file=dict( argstr='-prefix %s', - genfile=True, + hash_files=False, + name_source='in_file', + name_template='%s_allineate', xor=['allcostx'], ), out_matrix=dict( diff --git a/nipype/interfaces/base/core.py b/nipype/interfaces/base/core.py index c199af3ca8..d15628fd6b 100644 --- a/nipype/interfaces/base/core.py +++ b/nipype/interfaces/base/core.py @@ -1072,6 +1072,12 @@ def _filename_from_source(self, name, chain=None): if not isdefined(retval) or "%s" in retval: if not trait_spec.name_source: return retval + + # Do not generate filename when excluded by other inputs + if trait_spec.xor and any(isdefined(getattr(self.inputs, field)) + for field in trait_spec.xor): + return retval + if isdefined(retval) and "%s" in retval: name_template = retval else: