Skip to content

Commit 452aa54

Browse files
committed
Fixed Deconvolve output mapping
Beefed up AFNICommand Base to include _gen_fname() method (lifted from FSLCommand Base class). Minor bug edits in Deconvolve cmdline code.
1 parent 028ede6 commit 452aa54

File tree

2 files changed

+65
-14
lines changed

2 files changed

+65
-14
lines changed

nipype/interfaces/afni/base.py

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from sys import platform
1111

1212
from ... import logging
13-
from ...utils.filemanip import split_filename
13+
from ...utils.filemanip import split_filename, fname_presuffix
14+
1415
from ..base import (
1516
CommandLine, traits, CommandLineInputSpec, isdefined, File, TraitedSpec)
1617
from ...external.due import BibTeX
@@ -70,7 +71,7 @@ def version():
7071
return tuple(v)
7172

7273
@classmethod
73-
def outputtype_to_ext(cls, outputtype):
74+
def output_type_to_ext(cls, outputtype):
7475
"""Get the file extension for the given output type.
7576
7677
Parameters
@@ -217,7 +218,7 @@ def set_default_output_type(cls, outputtype):
217218

218219
def _overload_extension(self, value, name=None):
219220
path, base, _ = split_filename(value)
220-
return os.path.join(path, base + Info.outputtype_to_ext(self.inputs.outputtype))
221+
return os.path.join(path, base + Info.output_type_to_ext(self.inputs.outputtype))
221222

222223
def _list_outputs(self):
223224
outputs = super(AFNICommand, self)._list_outputs()
@@ -231,6 +232,51 @@ def _list_outputs(self):
231232
outputs[name] = outputs[name] + "+orig.BRIK"
232233
return outputs
233234

235+
def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True,
236+
ext=None):
237+
"""Generate a filename based on the given parameters.
238+
239+
The filename will take the form: cwd/basename<suffix><ext>.
240+
If change_ext is True, it will use the extentions specified in
241+
<instance>intputs.output_type.
242+
243+
Parameters
244+
----------
245+
basename : str
246+
Filename to base the new filename on.
247+
cwd : str
248+
Path to prefix to the new filename. (default is os.getcwd())
249+
suffix : str
250+
Suffix to add to the `basename`. (defaults is '' )
251+
change_ext : bool
252+
Flag to change the filename extension to the FSL output type.
253+
(default True)
254+
255+
Returns
256+
-------
257+
fname : str
258+
New filename based on given parameters.
259+
260+
"""
261+
262+
if basename == '':
263+
msg = 'Unable to generate filename for command %s. ' % self.cmd
264+
msg += 'basename is not set!'
265+
raise ValueError(msg)
266+
if cwd is None:
267+
cwd = os.getcwd()
268+
if ext is None:
269+
ext = Info.output_type_to_ext(self.inputs.outputtype)
270+
if change_ext:
271+
if suffix:
272+
suffix = ''.join((suffix, ext))
273+
else:
274+
suffix = ext
275+
if suffix is None:
276+
suffix = ''
277+
fname = fname_presuffix(basename, suffix=suffix,
278+
use_ext=False, newpath=cwd)
279+
return fname
234280

235281
def no_afni():
236282
""" Checks if AFNI is available """

nipype/interfaces/afni/model.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class DeconvolveInputSpec(AFNICommandInputSpec):
121121
desc='Stop running after writing .xmat.1D file',
122122
argstr='-x1D_stop')
123123
out_file = File(
124-
'bucket.nii',
124+
'Decon.nii',
125125
desc='Output statistics file',
126126
argstr='-bucket %s')
127127
jobs = traits.Int(
@@ -157,7 +157,7 @@ class DeconvolveInputSpec(AFNICommandInputSpec):
157157
Str(desc='model')),
158158
desc='Generate a response model from a set of stimulus times'
159159
' given in file.',
160-
argstr='-stim_times %d %s %s...')
160+
argstr='-stim_times %d %s \'%s\'...')
161161
stim_label = traits.List(
162162
traits.Tuple(traits.Int(desc='k-th input stimulus'),
163163
Str(desc='stimulus label')),
@@ -178,7 +178,7 @@ class DeconvolveInputSpec(AFNICommandInputSpec):
178178
Str(desc='symbolic general linear test'),
179179
desc='General linear tests (i.e., contrasts) using symbolic '
180180
'conventions (e.g., \'+Label1 -Label2\')',
181-
argstr='-gltsym SYM: %s...')
181+
argstr='-gltsym \'SYM: %s\'...')
182182
glt_label = traits.List(
183183
traits.Tuple(traits.Int(desc='k-th general linear test'),
184184
Str(desc='GLT label')),
@@ -187,10 +187,14 @@ class DeconvolveInputSpec(AFNICommandInputSpec):
187187
requires=['gltsym'])
188188

189189

190-
class DeconvolveOutputSpec(AFNICommandOutputSpec):
191-
out_file = File(desc='output statistics file')
192-
reml_script = File(desc='Autogenerated script for 3dREML')
193-
x1D = File(desc='save out X matrix')
190+
class DeconvolveOutputSpec(TraitedSpec):
191+
out_file = File(
192+
desc='output statistics file',
193+
exists=True)
194+
reml_script = File(
195+
desc='Autogenerated script for 3dREML')
196+
x1D = File(
197+
desc='save out X matrix')
194198

195199

196200
class Deconvolve(AFNICommand):
@@ -234,16 +238,17 @@ def _list_outputs(self):
234238
outputs = self.output_spec().get()
235239
if isdefined(self.inputs.x1D):
236240
if not self.inputs.x1D.endswith('.xmat.1D'):
237-
outputs['x1D'] = self.inputs.x1D + '.xmat.1D'
241+
outputs['x1D'] = os.path.abspath(self.inputs.x1D + '.xmat.1D')
238242
else:
239-
outputs['x1D'] = self.inputs.x1D
243+
outputs['x1D'] = os.path.abspath(self.inputs.x1D)
240244

241245
_gen_fname_opts = {}
242246
_gen_fname_opts['basename'] = self.inputs.out_file
243247
_gen_fname_opts['cwd'] = os.getcwd()
248+
_gen_fname_opts['suffix'] = '.REML_cmd'
244249

245-
outputs['reml_script'] = self._gen_fname(suffix='.REML_cmd', **_gen_fname_opts)
246-
outputs['out_file'] = self.inputs.out_file
250+
outputs['reml_script'] = self._gen_fname(**_gen_fname_opts)
251+
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
247252
return outputs
248253

249254

0 commit comments

Comments
 (0)