Repository: nipy/nipype

Issue:
AFNI Qwarp output paths are incorrect
### Summary
output paths are not correct: current directory is always used as parent directory and `+tlrc` is appended even to nifti outputs

### How to replicate the behavior
``` Python
from nipype.interfaces import afni
a = afni.Qwarp()
a.inputs.in_file = '/tmp/in_file.nii.gz'
a.inputs.base_file = '/tmp/base_file.nii.gz'
a.inputs.out_file = '/tmp/warped.nii.gz'
res = a.run()
print(res.outputs.warped_source)
```
prints a wrong path
``` Python
In [20]:  /home/salma/CODE/nipype/warped14+tlrc.nii.gz
```


Discussion:

Resolving patch:
diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py
--- a/nipype/interfaces/afni/preprocess.py
+++ b/nipype/interfaces/afni/preprocess.py
@@ -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)
@@ -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.'
@@ -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'
@@ -3475,29 +3476,38 @@ def _list_outputs(self):
         if not isdefined(self.inputs.out_file):
             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):


Test patch:
diff --git a/nipype/interfaces/afni/tests/test_auto_Qwarp.py b/nipype/interfaces/afni/tests/test_auto_Qwarp.py
--- a/nipype/interfaces/afni/tests/test_auto_Qwarp.py
+++ b/nipype/interfaces/afni/tests/test_auto_Qwarp.py
@@ -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',