From 234893e9275712854f1a6c3abb3bd54a76b07127 Mon Sep 17 00:00:00 2001 From: Andrew Van Date: Tue, 20 Mar 2018 16:13:34 -0500 Subject: [PATCH 1/6] fix afni.allineate interface --- nipype/interfaces/afni/preprocess.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 13a065c27c..1735caa9d3 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -219,6 +219,7 @@ class AllineateInputSpec(AFNICommandInputSpec): desc='output file from 3dAllineate', argstr='-prefix %s', genfile=True, + hash_files=False, xor=['allcostx']) out_param_file = File( argstr='-1Dparam_save %s', @@ -485,17 +486,22 @@ def _format_arg(self, name, trait_spec, value): return arg return super(Allineate, self)._format_arg(name, trait_spec, value) + def _gen_outfilename(self): + out_file = self.inputs.out_file + if not isdefined(out_file) and isdefined(self.inputs.in_file) and not isdefined(self.inputs.allcostx): + out_file = op.abspath(self._gen_fname(self.inputs.in_file,op.dirname(self.inputs.in_file),suffix='_allineate')) + return out_file + def _list_outputs(self): outputs = self.output_spec().get() - if self.inputs.out_file: - outputs['out_file'] = op.abspath(self.inputs.out_file) + outputs['out_file'] = self._gen_outfilename() - if self.inputs.out_weight_file: + if isdefined(self.inputs.out_weight_file): outputs['out_weight_file'] = op.abspath( self.inputs.out_weight_file) - if self.inputs.out_matrix: + if isdefined(self.inputs.out_matrix): path, base, ext = split_filename(self.inputs.out_matrix) if ext.lower() not in ['.1d', '.1D']: outputs['out_matrix'] = self._gen_fname( @@ -503,7 +509,7 @@ def _list_outputs(self): else: outputs['out_matrix'] = op.abspath(self.inputs.out_matrix) - if self.inputs.out_param_file: + if isdefined(self.inputs.out_param_file): path, base, ext = split_filename(self.inputs.out_param_file) if ext.lower() not in ['.1d', '.1D']: outputs['out_param_file'] = self._gen_fname( @@ -519,7 +525,7 @@ def _list_outputs(self): def _gen_filename(self, name): if name == 'out_file': - return self._list_outputs()[name] + return self._gen_outfilename() return None From 34f67b4f5e7a3fd3aa9feb82bf1aec29bc0f869a Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Mon, 23 Apr 2018 17:54:45 -0400 Subject: [PATCH 2/6] FIX: Do not generate filenames in violation of xor --- nipype/interfaces/base/core.py | 6 ++++++ 1 file changed, 6 insertions(+) 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: From ef25d159be6b866cd2f04c67930d9081eef9a2d8 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Mon, 23 Apr 2018 18:12:40 -0400 Subject: [PATCH 3/6] RF: Use name_source for Allineate.inputs.out_file --- nipype/interfaces/afni/preprocess.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 1735caa9d3..fe28a36556 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -218,7 +218,8 @@ 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( @@ -486,16 +487,8 @@ def _format_arg(self, name, trait_spec, value): return arg return super(Allineate, self)._format_arg(name, trait_spec, value) - def _gen_outfilename(self): - out_file = self.inputs.out_file - if not isdefined(out_file) and isdefined(self.inputs.in_file) and not isdefined(self.inputs.allcostx): - out_file = op.abspath(self._gen_fname(self.inputs.in_file,op.dirname(self.inputs.in_file),suffix='_allineate')) - return out_file - def _list_outputs(self): - outputs = self.output_spec().get() - - outputs['out_file'] = self._gen_outfilename() + outputs = super(Allineate, self)._list_outputs() if isdefined(self.inputs.out_weight_file): outputs['out_weight_file'] = op.abspath( @@ -523,11 +516,6 @@ def _list_outputs(self): os.path.join(os.getcwd(), self.inputs.allcostx)) return outputs - def _gen_filename(self, name): - if name == 'out_file': - return self._gen_outfilename() - return None - class AutoTcorrelateInputSpec(AFNICommandInputSpec): in_file = File( From 32cd9b83b0aac7f335af557b5e9929b6ff65dbc4 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Mon, 23 Apr 2018 18:13:18 -0400 Subject: [PATCH 4/6] FIX: Undo defined check, simplify abspath call --- nipype/interfaces/afni/preprocess.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index fe28a36556..7719159e6c 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -490,11 +490,11 @@ def _format_arg(self, name, trait_spec, value): def _list_outputs(self): outputs = super(Allineate, self)._list_outputs() - if isdefined(self.inputs.out_weight_file): + if self.inputs.out_weight_file: outputs['out_weight_file'] = op.abspath( self.inputs.out_weight_file) - if isdefined(self.inputs.out_matrix): + if self.inputs.out_matrix: path, base, ext = split_filename(self.inputs.out_matrix) if ext.lower() not in ['.1d', '.1D']: outputs['out_matrix'] = self._gen_fname( @@ -502,7 +502,7 @@ def _list_outputs(self): else: outputs['out_matrix'] = op.abspath(self.inputs.out_matrix) - if isdefined(self.inputs.out_param_file): + if self.inputs.out_param_file: path, base, ext = split_filename(self.inputs.out_param_file) if ext.lower() not in ['.1d', '.1D']: outputs['out_param_file'] = self._gen_fname( @@ -511,9 +511,8 @@ 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 From 4179f5c3637f556deba25b34ce99cb6ffb3bb633 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Mon, 23 Apr 2018 18:13:48 -0400 Subject: [PATCH 5/6] ENH: Simplify nwarp_fixmot, nwarp_fixdep --- nipype/interfaces/afni/preprocess.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 7719159e6c..9ede8d13e0 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -426,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.') @@ -467,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' @@ -475,18 +474,20 @@ 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 = super(Allineate, self)._list_outputs() From cda56e9b3ea6f0f18d44dbc455e4b508318847bd Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Mon, 23 Apr 2018 18:48:40 -0400 Subject: [PATCH 6/6] make specs --- nipype/interfaces/afni/tests/test_auto_Allineate.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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(