Skip to content

Commit fd49fd0

Browse files
authored
Merge pull request #2502 from vanandrew/fix_afni_allineate
[FIX] fix afni.allineate interface
2 parents 4cd2e42 + cda56e9 commit fd49fd0

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

nipype/interfaces/afni/preprocess.py

+16-22
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ 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',
223+
hash_files=False,
222224
xor=['allcostx'])
223225
out_param_file = File(
224226
argstr='-1Dparam_save %s',
@@ -424,11 +426,11 @@ class AllineateInputSpec(AFNICommandInputSpec):
424426
_dirs = ['X', 'Y', 'Z', 'I', 'J', 'K']
425427
nwarp_fixmot = traits.List(
426428
traits.Enum(*_dirs),
427-
argstr='-nwarp_fixmot%s',
429+
argstr='-nwarp_fixmot%s...',
428430
desc='To fix motion along directions.')
429431
nwarp_fixdep = traits.List(
430432
traits.Enum(*_dirs),
431-
argstr='-nwarp_fixdep%s',
433+
argstr='-nwarp_fixdep%s...',
432434
desc='To fix non-linear warp dependency along directions.')
433435
verbose = traits.Bool(
434436
argstr='-verb', desc='Print out verbose progress reports.')
@@ -465,31 +467,29 @@ class Allineate(AFNICommand):
465467
'3dAllineate -source functional.nii -prefix functional_allineate.nii -1Dmatrix_apply cmatrix.mat'
466468
>>> res = allineate.run() # doctest: +SKIP
467469
468-
>>> from nipype.interfaces import afni
469470
>>> allineate = afni.Allineate()
470471
>>> allineate.inputs.in_file = 'functional.nii'
471472
>>> allineate.inputs.reference = 'structural.nii'
472473
>>> allineate.inputs.allcostx = 'out.allcostX.txt'
473474
>>> allineate.cmdline
474475
'3dAllineate -source functional.nii -base structural.nii -allcostx |& tee out.allcostX.txt'
475476
>>> 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
476485
"""
477486

478487
_cmd = '3dAllineate'
479488
input_spec = AllineateInputSpec
480489
output_spec = AllineateOutputSpec
481490

482-
def _format_arg(self, name, trait_spec, value):
483-
if name == 'nwarp_fixmot' or name == 'nwarp_fixdep':
484-
arg = ' '.join([trait_spec.argstr % v for v in value])
485-
return arg
486-
return super(Allineate, self)._format_arg(name, trait_spec, value)
487-
488491
def _list_outputs(self):
489-
outputs = self.output_spec().get()
490-
491-
if self.inputs.out_file:
492-
outputs['out_file'] = op.abspath(self.inputs.out_file)
492+
outputs = super(Allineate, self)._list_outputs()
493493

494494
if self.inputs.out_weight_file:
495495
outputs['out_weight_file'] = op.abspath(
@@ -512,16 +512,10 @@ def _list_outputs(self):
512512
outputs['out_param_file'] = op.abspath(
513513
self.inputs.out_param_file)
514514

515-
if isdefined(self.inputs.allcostx):
516-
outputs['allcostX'] = os.path.abspath(
517-
os.path.join(os.getcwd(), self.inputs.allcostx))
515+
if self.inputs.allcostx:
516+
outputs['allcostX'] = os.path.abspath(self.inputs.allcostx)
518517
return outputs
519518

520-
def _gen_filename(self, name):
521-
if name == 'out_file':
522-
return self._list_outputs()[name]
523-
return None
524-
525519

526520
class AutoTcorrelateInputSpec(AFNICommandInputSpec):
527521
in_file = File(

nipype/interfaces/afni/tests/test_auto_Allineate.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ def test_Allineate_inputs():
6161
usedefault=True,
6262
),
6363
nwarp=dict(argstr='-nwarp %s', ),
64-
nwarp_fixdep=dict(argstr='-nwarp_fixdep%s', ),
65-
nwarp_fixmot=dict(argstr='-nwarp_fixmot%s', ),
64+
nwarp_fixdep=dict(argstr='-nwarp_fixdep%s...', ),
65+
nwarp_fixmot=dict(argstr='-nwarp_fixmot%s...', ),
6666
one_pass=dict(argstr='-onepass', ),
6767
out_file=dict(
6868
argstr='-prefix %s',
69-
genfile=True,
69+
hash_files=False,
70+
name_source='in_file',
71+
name_template='%s_allineate',
7072
xor=['allcostx'],
7173
),
7274
out_matrix=dict(

nipype/interfaces/base/core.py

+6
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)