Skip to content

Afni qwarp output paths #2222

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 2 commits into from
Oct 21, 2017
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
32 changes: 21 additions & 11 deletions nipype/interfaces/afni/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import os
import os.path as op

from ...utils.filemanip import (load_json, save_json, split_filename)
from ...utils.filemanip import (load_json, save_json, split_filename,
fname_presuffix)
from ..base import (
CommandLineInputSpec, CommandLine, TraitedSpec,
traits, isdefined, File, InputMultiPath, Undefined, Str)
Expand Down Expand Up @@ -3131,7 +3132,7 @@ class QwarpInputSpec(AFNICommandInputSpec):
'Note that the source dataset in the second run is the SAME as'
'in the first run. If you don\'t see why this is necessary,'
'then you probably need to seek help from an AFNI guru.',
argstr='-inlev %d',
argstr='-inilev %d',
xor=['duplo'])
minpatch = traits.Int(
desc='* The value of mm should be an odd integer.'
Expand Down Expand Up @@ -3462,7 +3463,7 @@ class Qwarp(AFNICommand):
>>> qwarp2.inputs.inilev = 7
>>> qwarp2.inputs.iniwarp = ['Q25_warp+tlrc.HEAD']
>>> qwarp2.cmdline # doctest: +ALLOW_UNICODE
'3dQwarp -base mni.nii -blur 0.0 2.0 -source structural.nii -inlev 7 -iniwarp Q25_warp+tlrc.HEAD -prefix Q11'
'3dQwarp -base mni.nii -blur 0.0 2.0 -source structural.nii -inilev 7 -iniwarp Q25_warp+tlrc.HEAD -prefix Q11'
>>> res2 = qwarp2.run() # doctest: +SKIP
"""
_cmd = '3dQwarp'
Expand All @@ -3475,29 +3476,38 @@ def _list_outputs(self):
if not isdefined(self.inputs.out_file):
Copy link
Contributor

@oesteban oesteban Oct 9, 2017

Choose a reason for hiding this comment

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

All of this should not be here:

  1. The out_file input spec can only define one of name_source or genfile (currently it defines both). Since we are trying to deprecate genfile, name_source should be preferred.

  2. In theory, name_source should fix this issue.

Copy link
Member

Choose a reason for hiding this comment

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

@oesteban - i'm leaving the afni stuff to @Shotgunosine and others to figure out. right now, because of the way afni works with various kinds of extensions, the straight up namesource can run into issues.

prefix = self._gen_fname(self.inputs.in_file, suffix='_QW')
ext = '.HEAD'
suffix ='+tlrc'
else:
prefix = self.inputs.out_file
ext_ind = max([prefix.lower().rfind('.nii.gz'),
prefix.lower().rfind('.nii.')])
if ext_ind == -1:
ext = '.HEAD'
suffix = '+tlrc'
else:
ext = prefix[ext_ind:]
suffix = ''
print(ext,"ext")
outputs['warped_source'] = os.path.abspath(self._gen_fname(prefix, suffix='+tlrc')+ext)
outputs['warped_source'] = fname_presuffix(prefix, suffix=suffix,
use_ext=False) + ext
if not self.inputs.nowarp:
outputs['source_warp'] = os.path.abspath(self._gen_fname(prefix, suffix='_WARP+tlrc')+ext)
outputs['source_warp'] = fname_presuffix(prefix,
suffix='_WARP' + suffix, use_ext=False) + ext
if self.inputs.iwarp:
outputs['base_warp'] = os.path.abspath(self._gen_fname(prefix, suffix='_WARPINV+tlrc')+ext)
outputs['base_warp'] = fname_presuffix(prefix,
suffix='_WARPINV' + suffix, use_ext=False) + ext
if isdefined(self.inputs.out_weight_file):
outputs['weights'] = os.path.abspath(self.inputs.out_weight_file)

if self.inputs.plusminus:
outputs['warped_source'] = os.path.abspath(self._gen_fname(prefix, suffix='_PLUS+tlrc')+ext)
outputs['warped_base'] = os.path.abspath(self._gen_fname(prefix, suffix='_MINUS+tlrc')+ext)
outputs['source_warp'] = os.path.abspath(self._gen_fname(prefix, suffix='_PLUS_WARP+tlrc')+ext)
outputs['base_warp'] = os.path.abspath(self._gen_fname(prefix, suffix='_MINUS_WARP+tlrc',)+ext)

outputs['warped_source'] = fname_presuffix(prefix,
suffix='_PLUS' + suffix, use_ext=False) + ext
outputs['warped_base'] = fname_presuffix(prefix,
suffix='_MINUS' + suffix, use_ext=False) + ext
outputs['source_warp'] = fname_presuffix(prefix,
suffix='_PLUS_WARP' + suffix, use_ext=False) + ext
outputs['base_warp'] = fname_presuffix(prefix,
suffix='_MINUS_WARP' + suffix, use_ext=False) + ext
return outputs

def _gen_filename(self, name):
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/afni/tests/test_auto_Qwarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_Qwarp_inputs():
copyfile=False,
mandatory=True,
),
inilev=dict(argstr='-inlev %d',
inilev=dict(argstr='-inilev %d',
xor=['duplo'],
),
iniwarp=dict(argstr='-iniwarp %s',
Expand Down