Skip to content

Commit 78f68ae

Browse files
authored
Merge pull request #1 from effigies/fix_afni_allineate
Suggested changes to #2502
2 parents 234893e + 4179f5c commit 78f68ae

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

nipype/interfaces/afni/preprocess.py

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ class AllineateInputSpec(AFNICommandInputSpec):
218218
out_file = File(
219219
desc='output file from 3dAllineate',
220220
argstr='-prefix %s',
221-
genfile=True,
221+
name_template='%s_allineate',
222+
name_source='in_file',
222223
hash_files=False,
223224
xor=['allcostx'])
224225
out_param_file = File(
@@ -425,11 +426,11 @@ class AllineateInputSpec(AFNICommandInputSpec):
425426
_dirs = ['X', 'Y', 'Z', 'I', 'J', 'K']
426427
nwarp_fixmot = traits.List(
427428
traits.Enum(*_dirs),
428-
argstr='-nwarp_fixmot%s',
429+
argstr='-nwarp_fixmot%s...',
429430
desc='To fix motion along directions.')
430431
nwarp_fixdep = traits.List(
431432
traits.Enum(*_dirs),
432-
argstr='-nwarp_fixdep%s',
433+
argstr='-nwarp_fixdep%s...',
433434
desc='To fix non-linear warp dependency along directions.')
434435
verbose = traits.Bool(
435436
argstr='-verb', desc='Print out verbose progress reports.')
@@ -466,50 +467,43 @@ class Allineate(AFNICommand):
466467
'3dAllineate -source functional.nii -prefix functional_allineate.nii -1Dmatrix_apply cmatrix.mat'
467468
>>> res = allineate.run() # doctest: +SKIP
468469
469-
>>> from nipype.interfaces import afni
470470
>>> allineate = afni.Allineate()
471471
>>> allineate.inputs.in_file = 'functional.nii'
472472
>>> allineate.inputs.reference = 'structural.nii'
473473
>>> allineate.inputs.allcostx = 'out.allcostX.txt'
474474
>>> allineate.cmdline
475475
'3dAllineate -source functional.nii -base structural.nii -allcostx |& tee out.allcostX.txt'
476476
>>> res = allineate.run() # doctest: +SKIP
477+
478+
>>> allineate = afni.Allineate()
479+
>>> allineate.inputs.in_file = 'functional.nii'
480+
>>> allineate.inputs.reference = 'structural.nii'
481+
>>> allineate.inputs.nwarp_fixmot = ['X', 'Y']
482+
>>> allineate.cmdline
483+
'3dAllineate -source functional.nii -nwarp_fixmotX -nwarp_fixmotY -prefix functional_allineate -base structural.nii'
484+
>>> res = allineate.run() # doctest: +SKIP
477485
"""
478486

479487
_cmd = '3dAllineate'
480488
input_spec = AllineateInputSpec
481489
output_spec = AllineateOutputSpec
482490

483-
def _format_arg(self, name, trait_spec, value):
484-
if name == 'nwarp_fixmot' or name == 'nwarp_fixdep':
485-
arg = ' '.join([trait_spec.argstr % v for v in value])
486-
return arg
487-
return super(Allineate, self)._format_arg(name, trait_spec, value)
488-
489-
def _gen_outfilename(self):
490-
out_file = self.inputs.out_file
491-
if not isdefined(out_file) and isdefined(self.inputs.in_file) and not isdefined(self.inputs.allcostx):
492-
out_file = op.abspath(self._gen_fname(self.inputs.in_file,op.dirname(self.inputs.in_file),suffix='_allineate'))
493-
return out_file
494-
495491
def _list_outputs(self):
496-
outputs = self.output_spec().get()
497-
498-
outputs['out_file'] = self._gen_outfilename()
492+
outputs = super(Allineate, self)._list_outputs()
499493

500-
if isdefined(self.inputs.out_weight_file):
494+
if self.inputs.out_weight_file:
501495
outputs['out_weight_file'] = op.abspath(
502496
self.inputs.out_weight_file)
503497

504-
if isdefined(self.inputs.out_matrix):
498+
if self.inputs.out_matrix:
505499
path, base, ext = split_filename(self.inputs.out_matrix)
506500
if ext.lower() not in ['.1d', '.1D']:
507501
outputs['out_matrix'] = self._gen_fname(
508502
self.inputs.out_matrix, suffix='.aff12.1D')
509503
else:
510504
outputs['out_matrix'] = op.abspath(self.inputs.out_matrix)
511505

512-
if isdefined(self.inputs.out_param_file):
506+
if self.inputs.out_param_file:
513507
path, base, ext = split_filename(self.inputs.out_param_file)
514508
if ext.lower() not in ['.1d', '.1D']:
515509
outputs['out_param_file'] = self._gen_fname(
@@ -518,16 +512,10 @@ def _list_outputs(self):
518512
outputs['out_param_file'] = op.abspath(
519513
self.inputs.out_param_file)
520514

521-
if isdefined(self.inputs.allcostx):
522-
outputs['allcostX'] = os.path.abspath(
523-
os.path.join(os.getcwd(), self.inputs.allcostx))
515+
if self.inputs.allcostx:
516+
outputs['allcostX'] = os.path.abspath(self.inputs.allcostx)
524517
return outputs
525518

526-
def _gen_filename(self, name):
527-
if name == 'out_file':
528-
return self._gen_outfilename()
529-
return None
530-
531519

532520
class AutoTcorrelateInputSpec(AFNICommandInputSpec):
533521
in_file = File(

nipype/interfaces/base/core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,12 @@ def _filename_from_source(self, name, chain=None):
10721072
if not isdefined(retval) or "%s" in retval:
10731073
if not trait_spec.name_source:
10741074
return retval
1075+
1076+
# Do not generate filename when excluded by other inputs
1077+
if trait_spec.xor and any(isdefined(getattr(self.inputs, field))
1078+
for field in trait_spec.xor):
1079+
return retval
1080+
10751081
if isdefined(retval) and "%s" in retval:
10761082
name_template = retval
10771083
else:

0 commit comments

Comments
 (0)