Skip to content

[FIX] fix afni.allineate interface #2502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions nipype/interfaces/afni/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.')
Expand Down Expand Up @@ -465,31 +467,29 @@ 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'
>>> allineate.inputs.allcostx = 'out.allcostX.txt'
>>> 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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question: Is -prefix functional_allineate the correct default, or should it be functional_allineate.nii?
If it should have the extension, we should add keep_extension=True to the out_file trait spec.

@tsalo @salma1601 You might also be good people to chime in here.

>>> 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(
Expand All @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions nipype/interfaces/afni/tests/test_auto_Allineate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions nipype/interfaces/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satra @oesteban Does this constitute a full fix of #2506?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@effigies - this is a good addition, but i'm not sure this addresses #2506, which does not have any xor. isn't it the case in #2506 that out_file should be populated if in_files is defined and set to some default otherwise?

i think this PR is fine, just not sure if it addresses #2506.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. I had it kind of backwards, but a similar fix to this should resolve #2506. I'll merge and propose a quick PR for that one.


if isdefined(retval) and "%s" in retval:
name_template = retval
else:
Expand Down