Skip to content

Commit dbc9715

Browse files
committed
Merge branch 'master' into enh/rapidart
* master: fix: ants workflows setup deprecated version should be a string, added AFNITraitedSpec for backward compatibility docs PEP8 name_source can be a list, make "infolder" a deprecated name Removed unnecessary outputsspecs Renaming Bugfixes, don't overlad extensions by default. fixed AutoTcorrelate and _list_outputs added skeleton AutoTcorrelate turns out some traits don't have "_metadata" fixed hashing PEP8 added prefix/suffix deprecation info All autogenerated inputs should not be hashed. Refactored AFNI. Added new autogenerating input type. Refactor AFNI added "tar.gz" as a unusual extension graph submission fix
2 parents dc5fe25 + 29b09af commit dbc9715

File tree

12 files changed

+445
-669
lines changed

12 files changed

+445
-669
lines changed

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ Next release
22
============
33

44
* ENH: Add basic support for LSF plugin.
5-
* ENH: New interfaces: ICC, Meshfix, ants.Register, C3dAffineTool, ants.JacobianDeterminant
5+
* ENH: New interfaces: ICC, Meshfix, ants.Register, C3dAffineTool, ants.JacobianDeterminant,
6+
afni.AutoTcorrelate
67
* ENH: New workflows: ants template building (both using 'ANTS' and the new 'antsRegistration')
78
* ENH: New examples: how to use ANTS template building workflows (smri_ants_build_tmeplate),
89
how to set SGE specific options (smri_ants_build_template_new)

nipype/interfaces/afni/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
from .preprocess import (To3D, Refit, Resample, TStat, Automask, Volreg, Merge,
1212
ZCutUp, Calc, TShift, Warp, Detrend, Despike, Copy,
1313
Fourier, Allineate, Maskave, SkullStrip, TCat, Fim,
14-
TCorrelate, BrickStat, ROIStats)
14+
TCorrelate, BrickStat, ROIStats, AutoTcorrelate)

nipype/interfaces/afni/base.py

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import os
77
import warnings
88

9-
from ...utils.filemanip import fname_presuffix
10-
from ..base import (CommandLine, traits, CommandLineInputSpec, isdefined)
9+
from ...utils.filemanip import fname_presuffix, split_filename
10+
from ..base import (
11+
CommandLine, traits, CommandLineInputSpec, isdefined, File, TraitedSpec)
1112

1213
warn = warnings.warn
1314
warnings.filterwarnings('always', category=UserWarning)
@@ -18,6 +19,7 @@
1819
#
1920
###################################
2021

22+
2123
class Info(object):
2224
"""Handle afni output type and version information.
2325
"""
@@ -80,7 +82,6 @@ def outputtype(cls):
8082
# 'Nipype uses NIFTI_GZ as default'))
8183
return 'AFNI'
8284

83-
8485
@staticmethod
8586
def standard_image(img_name):
8687
'''Grab an image from the standard location.
@@ -95,23 +96,27 @@ def standard_image(img_name):
9596
return os.path.join(basedir, img_name)
9697

9798

98-
class AFNITraitedSpec(CommandLineInputSpec):
99-
outputtype = traits.Enum('AFNI', Info.ftypes.keys(),
100-
desc = 'AFNI output filetype')
99+
class AFNIBaseCommandInputSpec(CommandLineInputSpec):
100+
outputtype = traits.Enum('AFNI', Info.ftypes.keys(),
101+
desc='AFNI output filetype')
102+
103+
class AFNITraitedSpec(AFNIBaseCommandInputSpec):
104+
pass
101105

102106

103-
class AFNICommand(CommandLine):
107+
class AFNIBaseCommand(CommandLine):
104108
"""General support for AFNI commands. Every AFNI command accepts 'outputtype' input. For example:
105109
afni.Threedsetup(outputtype='NIFTI_GZ')
106110
"""
107111

108-
input_spec = AFNITraitedSpec
112+
input_spec = AFNIBaseCommandInputSpec
109113
_outputtype = None
114+
110115

111116
def __init__(self, **inputs):
112-
super(AFNICommand, self).__init__(**inputs)
117+
super(AFNIBaseCommand, self).__init__(**inputs)
113118
self.inputs.on_trait_change(self._output_update, 'outputtype')
114-
119+
115120
if self._outputtype is None:
116121
self._outputtype = Info.outputtype()
117122

@@ -127,7 +132,6 @@ def _output_update(self):
127132
"""
128133
self._outputtype = self.inputs.outputtype
129134

130-
131135
@classmethod
132136
def set_default_outputtype(cls, outputtype):
133137
"""Set the default output type for AFNI classes.
@@ -143,7 +147,7 @@ def set_default_outputtype(cls, outputtype):
143147
else:
144148
raise AttributeError('Invalid AFNI outputtype: %s' % outputtype)
145149

146-
def _gen_fname(self, basename, cwd=None, suffix='_afni', change_ext=True):
150+
def _gen_fname(self, basename, cwd=None, suffix='_afni', change_ext=True, prefix=''):
147151
"""Generate a filename based on the given parameters.
148152
149153
The filename will take the form: cwd/basename<suffix><ext>.
@@ -181,9 +185,54 @@ def _gen_fname(self, basename, cwd=None, suffix='_afni', change_ext=True):
181185
suffix = ''.join((suffix, ext))
182186
else:
183187
suffix = ext
184-
fname = fname_presuffix(basename, suffix = suffix,
185-
use_ext = False, newpath = cwd)
188+
fname = fname_presuffix(basename, suffix=suffix,
189+
use_ext=False, newpath=cwd, prefix=prefix)
186190
return fname
187191

188192

193+
class AFNICommandInputSpec(AFNIBaseCommandInputSpec):
194+
out_file = File("%s_afni", desc='output image file name',
195+
argstr='-prefix %s', xor=['out_file', 'prefix', 'suffix'], name_source="in_file", usedefault=True)
196+
prefix = traits.Str(
197+
desc='output image prefix', deprecated='0.8', new_name="out_file")
198+
suffix = traits.Str(
199+
desc='output image suffix', deprecated='0.8', new_name="out_file")
189200

201+
202+
class AFNICommand(AFNIBaseCommand):
203+
input_spec = AFNICommandInputSpec
204+
205+
def _gen_filename(self, name):
206+
trait_spec = self.inputs.trait(name)
207+
if name == "out_file" and (isdefined(self.inputs.prefix) or isdefined(self.inputs.suffix)):
208+
suffix = ''
209+
prefix = ''
210+
if isdefined(self.inputs.prefix):
211+
prefix = self.inputs.prefix
212+
if isdefined(self.inputs.suffix):
213+
suffix = self.inputs.suffix
214+
215+
_, base, _ = split_filename(
216+
getattr(self.inputs, trait_spec.name_source))
217+
return self._gen_fname(basename=base, prefix=prefix, suffix=suffix, cwd='')
218+
else:
219+
return super(AFNICommand, self)._gen_filename(name)
220+
221+
def _overload_extension(self, value):
222+
path, base, _ = split_filename(value)
223+
return os.path.join(path, base + Info.outputtype_to_ext(self.inputs.outputtype))
224+
225+
def _list_outputs(self):
226+
metadata = dict(name_source=lambda t: t is not None)
227+
out_names = self.inputs.traits(**metadata).keys()
228+
if out_names:
229+
outputs = self.output_spec().get()
230+
for name in out_names:
231+
out = self._gen_filename(name)
232+
outputs[name] = os.path.abspath(out)
233+
return outputs
234+
235+
236+
class AFNICommandOutputSpec(TraitedSpec):
237+
out_file = File(desc='output file',
238+
exists=True)

0 commit comments

Comments
 (0)