Skip to content

Commit 79e3b46

Browse files
committed
begin aFNI refactor
1 parent 42b5ce2 commit 79e3b46

File tree

2 files changed

+60
-61
lines changed

2 files changed

+60
-61
lines changed

nipype/interfaces/afni/base.py

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Info(object):
2525
"""
2626
__outputtype = 'AFNI'
2727
ftypes = {'NIFTI': '.nii',
28-
'AFNI': '+orig.BRIK',
28+
'AFNI': '',
2929
'NIFTI_GZ': '.nii.gz'}
3030

3131
@staticmethod
@@ -149,62 +149,73 @@ def set_default_output_type(cls, outputtype):
149149
else:
150150
raise AttributeError('Invalid AFNI outputtype: %s' % outputtype)
151151

152-
def _gen_fname(self, basename, cwd=None, suffix='_afni', change_ext=True, prefix=''):
153-
"""Generate a filename based on the given parameters.
154-
155-
The filename will take the form: cwd/basename<suffix><ext>.
156-
If change_ext is True, it will use the extensions specified in
157-
<instance>inputs.outputtype.
158-
159-
Parameters
160-
----------
161-
basename : str
162-
Filename to base the new filename on.
163-
cwd : str
164-
Path to prefix to the new filename. (default is os.getcwd())
165-
suffix : str
166-
Suffix to add to the `basename`. (default is '_fsl')
167-
change_ext : bool
168-
Flag to change the filename extension to the FSL output type.
169-
(default True)
170-
171-
Returns
172-
-------
173-
fname : str
174-
New filename based on given parameters.
175-
176-
"""
177-
178-
if basename == '':
179-
msg = 'Unable to generate filename for command %s. ' % self.cmd
180-
msg += 'basename is not set!'
181-
raise ValueError(msg)
182-
if cwd is None:
183-
cwd = os.getcwd()
184-
ext = Info.outputtype_to_ext(self.inputs.outputtype)
185-
if change_ext:
186-
if suffix:
187-
suffix = ''.join((suffix, ext))
188-
else:
189-
suffix = ext
190-
fname = fname_presuffix(basename, suffix=suffix,
191-
use_ext=False, newpath=cwd, prefix=prefix)
192-
return fname
152+
# def _gen_fname(self, basename, cwd=None, suffix='_afni', change_ext=True, prefix=''):
153+
# """Generate a filename based on the given parameters.
154+
#
155+
# The filename will take the form: cwd/basename<suffix><ext>.
156+
# If change_ext is True, it will use the extensions specified in
157+
# <instance>inputs.outputtype.
158+
#
159+
# Parameters
160+
# ----------
161+
# basename : str
162+
# Filename to base the new filename on.
163+
# cwd : str
164+
# Path to prefix to the new filename. (default is os.getcwd())
165+
# suffix : str
166+
# Suffix to add to the `basename`. (default is '_fsl')
167+
# change_ext : bool
168+
# Flag to change the filename extension to the FSL output type.
169+
# (default True)
170+
#
171+
# Returns
172+
# -------
173+
# fname : str
174+
# New filename based on given parameters.
175+
#
176+
# """
177+
#
178+
# if basename == '':
179+
# msg = 'Unable to generate filename for command %s. ' % self.cmd
180+
# msg += 'basename is not set!'
181+
# raise ValueError(msg)
182+
# if cwd is None:
183+
# cwd = os.getcwd()
184+
# ext = Info.outputtype_to_ext(self.inputs.outputtype)
185+
# if change_ext:
186+
# if suffix:
187+
# suffix = ''.join((suffix, ext))
188+
# else:
189+
# suffix = ext
190+
# fname = fname_presuffix(basename, suffix=suffix,
191+
# use_ext=False, newpath=cwd, prefix=prefix)
192+
# return fname
193193

194194

195195
class AFNICommandInputSpec(AFNIBaseCommandInputSpec):
196-
out_file = File("%s_afni", desc='output image file name',
197-
argstr='-prefix %s', xor=['out_file', 'prefix', 'suffix'],
198-
name_source="in_file", usedefault=True)
196+
out_file = File(name_template="%s_afni", desc='output image file name',
197+
argstr='-prefix %s',
198+
name_source=["in_file"])
199199

200200

201201
class AFNICommand(AFNIBaseCommand):
202202
input_spec = AFNICommandInputSpec
203-
203+
204204
def _overload_extension(self, value):
205205
path, base, _ = split_filename(value)
206206
return os.path.join(path, base + Info.outputtype_to_ext(self.inputs.outputtype))
207207

208+
def _list_outputs(self):
209+
outputs = super(AFNICommand, self)._list_outputs()
210+
metadata = dict(name_source=lambda t: t is not None)
211+
out_names = self.inputs.traits(**metadata).keys()
212+
if out_names:
213+
for name in out_names:
214+
if outputs[name]:
215+
_,_,ext = split_filename(outputs[name])
216+
if ext == "":
217+
outputs[name] = outputs[name] + "+orig.BRIK"
218+
return outputs
208219

209220
class AFNICommandOutputSpec(TraitedSpec):
210221
out_file = File(desc='output file',

nipype/interfaces/afni/preprocess.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,13 @@
2525

2626

2727
class To3DInputSpec(AFNICommandInputSpec):
28-
out_file = File("%s", desc='output image file name',
29-
argstr='-prefix %s', name_source=["in_folder", "infolder"],
30-
usedefault=True)
31-
in_xor = ["infolder", "in_folder"]
28+
out_file = File(name_template="%s", desc='output image file name',
29+
argstr='-prefix %s', name_source=["in_folder"])
3230
in_folder = Directory(desc='folder with DICOM images to convert',
3331
argstr='%s/*.dcm',
3432
position=-1,
3533
mandatory=True,
36-
exists=True,
37-
xor=in_xor)
38-
39-
infolder = Directory(desc='folder with DICOM images to convert',
40-
argstr='%s/*.dcm',
41-
position=-1,
42-
mandatory=True,
43-
exists=True,
44-
deprecated='0.8',
45-
new_name="in_folder",
46-
xor=in_xor)
34+
exists=True)
4735

4836
filetype = traits.Enum('spgr', 'fse', 'epan', 'anat', 'ct', 'spct',
4937
'pet', 'mra', 'bmap', 'diff',

0 commit comments

Comments
 (0)