diff --git a/CHANGES b/CHANGES index 5643fb3522..f535d1b5dc 100644 --- a/CHANGES +++ b/CHANGES @@ -5,7 +5,8 @@ Next release * ENH: New interfaces: spm.ResliceToReference, FuzzyOverlap, afni.AFNItoNIFTI spm.DicomImport, P2PDistance * ENH: W3C PROV support with optional RDF export built into Nipype -* ENH: Added support for Simple Linux Utility Resource Management (SLURM) +* ENH: Added support for Simple Linux Utility Resource Management (SLURM) +* ENHL AFNI interfaces refactor, prefix, suffix are replaced by "flexible_%s_templates" * ENH: Several new interfaces related to Camino were added: - camino.SFPICOCalibData diff --git a/nipype/interfaces/afni/base.py b/nipype/interfaces/afni/base.py index 09f0dc7e81..b94b339d60 100644 --- a/nipype/interfaces/afni/base.py +++ b/nipype/interfaces/afni/base.py @@ -6,26 +6,20 @@ import os import warnings -from ...utils.filemanip import fname_presuffix, split_filename +from ...utils.filemanip import split_filename from ..base import ( CommandLine, traits, CommandLineInputSpec, isdefined, File, TraitedSpec) warn = warnings.warn warnings.filterwarnings('always', category=UserWarning) -################################### -# -# NEW_AFNI base class -# -################################### - class Info(object): """Handle afni output type and version information. """ __outputtype = 'AFNI' ftypes = {'NIFTI': '.nii', - 'AFNI': '+orig.BRIK', + 'AFNI': '', 'NIFTI_GZ': '.nii.gz'} @staticmethod @@ -98,25 +92,26 @@ def standard_image(img_name): return os.path.join(basedir, img_name) -class AFNIBaseCommandInputSpec(CommandLineInputSpec): +class AFNICommandInputSpec(CommandLineInputSpec): outputtype = traits.Enum('AFNI', Info.ftypes.keys(), desc='AFNI output filetype') + out_file = File(name_template="%s_afni", desc='output image file name', + argstr='-prefix %s', + name_source=["in_file"]) + +class AFNICommandOutputSpec(TraitedSpec): + out_file = File(desc='output file', + exists=True) -class AFNITraitedSpec(AFNIBaseCommandInputSpec): - pass - - -class AFNIBaseCommand(CommandLine): - """General support for AFNI commands. Every AFNI command accepts 'outputtype' input. For example: - afni.Threedsetup(outputtype='NIFTI_GZ') - """ - input_spec = AFNIBaseCommandInputSpec +class AFNICommand(CommandLine): + + input_spec = AFNICommandInputSpec _outputtype = None def __init__(self, **inputs): - super(AFNIBaseCommand, self).__init__(**inputs) + super(AFNICommand, self).__init__(**inputs) self.inputs.on_trait_change(self._output_update, 'outputtype') if self._outputtype is None: @@ -148,64 +143,19 @@ def set_default_output_type(cls, outputtype): cls._outputtype = outputtype else: raise AttributeError('Invalid AFNI outputtype: %s' % outputtype) - - def _gen_fname(self, basename, cwd=None, suffix='_afni', change_ext=True, prefix=''): - """Generate a filename based on the given parameters. - - The filename will take the form: cwd/basename. - If change_ext is True, it will use the extensions specified in - inputs.outputtype. - - Parameters - ---------- - basename : str - Filename to base the new filename on. - cwd : str - Path to prefix to the new filename. (default is os.getcwd()) - suffix : str - Suffix to add to the `basename`. (default is '_fsl') - change_ext : bool - Flag to change the filename extension to the FSL output type. - (default True) - - Returns - ------- - fname : str - New filename based on given parameters. - - """ - - if basename == '': - msg = 'Unable to generate filename for command %s. ' % self.cmd - msg += 'basename is not set!' - raise ValueError(msg) - if cwd is None: - cwd = os.getcwd() - ext = Info.outputtype_to_ext(self.inputs.outputtype) - if change_ext: - if suffix: - suffix = ''.join((suffix, ext)) - else: - suffix = ext - fname = fname_presuffix(basename, suffix=suffix, - use_ext=False, newpath=cwd, prefix=prefix) - return fname - - -class AFNICommandInputSpec(AFNIBaseCommandInputSpec): - out_file = File("%s_afni", desc='output image file name', - argstr='-prefix %s', xor=['out_file', 'prefix', 'suffix'], - name_source="in_file", usedefault=True) - - -class AFNICommand(AFNIBaseCommand): - input_spec = AFNICommandInputSpec - + def _overload_extension(self, value): path, base, _ = split_filename(value) return os.path.join(path, base + Info.outputtype_to_ext(self.inputs.outputtype)) - -class AFNICommandOutputSpec(TraitedSpec): - out_file = File(desc='output file', - exists=True) + def _list_outputs(self): + outputs = super(AFNICommand, self)._list_outputs() + metadata = dict(name_source=lambda t: t is not None) + out_names = self.inputs.traits(**metadata).keys() + if out_names: + for name in out_names: + if outputs[name]: + _,_,ext = split_filename(outputs[name]) + if ext == "": + outputs[name] = outputs[name] + "+orig.BRIK" + return outputs diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 633257b0fb..503a4441cb 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -12,12 +12,12 @@ import os import re -from .base import AFNIBaseCommandInputSpec, AFNIBaseCommand -from ..base import (Directory, CommandLineInputSpec, CommandLine, TraitedSpec, + +from ..base import (Directory, TraitedSpec, traits, isdefined, File, InputMultiPath, Undefined) from ...utils.filemanip import (load_json, save_json, split_filename) from nipype.utils.filemanip import fname_presuffix -from nipype.interfaces.afni.base import AFNICommand, AFNICommandInputSpec,\ +from .base import AFNICommand, AFNICommandInputSpec,\ AFNICommandOutputSpec warn = warnings.warn @@ -25,25 +25,13 @@ class To3DInputSpec(AFNICommandInputSpec): - out_file = File("%s", desc='output image file name', - argstr='-prefix %s', name_source=["in_folder", "infolder"], - usedefault=True) - in_xor = ["infolder", "in_folder"] + out_file = File(name_template="%s", desc='output image file name', + argstr='-prefix %s', name_source=["in_folder"]) in_folder = Directory(desc='folder with DICOM images to convert', argstr='%s/*.dcm', position=-1, mandatory=True, - exists=True, - xor=in_xor) - - infolder = Directory(desc='folder with DICOM images to convert', - argstr='%s/*.dcm', - position=-1, - mandatory=True, - exists=True, - deprecated='0.8', - new_name="in_folder", - xor=in_xor) + exists=True) filetype = traits.Enum('spgr', 'fse', 'epan', 'anat', 'ct', 'spct', 'pet', 'mra', 'bmap', 'diff', @@ -78,9 +66,8 @@ class To3D(AFNICommand): >>> To3D = afni.To3D() >>> To3D.inputs.datatype = 'float' >>> To3D.inputs.in_folder = '.' - >>> To3D.inputs.out_file = 'dicomdir' + >>> To3D.inputs.out_file = 'dicomdir.nii' >>> To3D.inputs.filetype = "anat" - >>> To3D.inputs.outputtype = "NIFTI" >>> To3D.cmdline #doctest: +ELLIPSIS 'to3d -datum float -anat -prefix dicomdir.nii ./*.dcm' >>> res = To3D.run() #doctest: +SKIP @@ -99,8 +86,8 @@ class TShiftInputSpec(AFNICommandInputSpec): mandatory=True, exists=True) - out_file = File("%s_tshift", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_tshift", desc='output image file name', + argstr='-prefix %s', name_source="in_file") tr = traits.Str(desc='manually set the TR' + 'You can attach suffix "s" for seconds or "ms" for milliseconds.', @@ -151,8 +138,8 @@ class TShift(AFNICommand): >>> tshift.inputs.in_file = 'functional.nii' >>> tshift.inputs.tpattern = 'alt+z' >>> tshift.inputs.tzero = 0.0 - >>> tshift.cmdline #doctest: +ELLIPSIS - '3dTshift -prefix .../functional_tshift+orig.BRIK -tpattern alt+z -tzero 0.0 functional.nii' + >>> tshift.cmdline #doctest: + '3dTshift -prefix functional_tshift -tpattern alt+z -tzero 0.0 functional.nii' >>> res = tshift.run() # doctest: +SKIP """ @@ -170,8 +157,8 @@ class RefitInputSpec(AFNICommandInputSpec): exists=True, copyfile=True) - out_file = File("%s_refit", desc='output image file name, should be the same as input', - argstr='%s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_refit", desc='output image file name, should be the same as input', + argstr='%s', name_source="in_file") deoblique = traits.Bool(desc='replace current transformation' + ' matrix with cardinal matrix', @@ -184,7 +171,6 @@ class RefitInputSpec(AFNICommandInputSpec): argstr='-yorigin %s') zorigin = traits.Str(desc='z distance for edge voxel offset', argstr='-zorigin %s') - suffix = traits.Str('_refit', desc="out_file suffix", usedefault=True) class Refit(AFNICommand): @@ -199,7 +185,10 @@ class Refit(AFNICommand): >>> from nipype.interfaces import afni as afni >>> refit = afni.Refit() >>> refit.inputs.in_file = 'structural.nii' - >>> refit.inputs.deoblique=True + >>> refit.inputs.deoblique = True + >>> refit.inputs.outputtype = "NIFTI_GZ" + >>> refit.cmdline + '3drefit -deoblique structural_refit.nii.gz structural.nii' >>> res = refit.run() # doctest: +SKIP """ @@ -217,8 +206,8 @@ class WarpInputSpec(AFNICommandInputSpec): mandatory=True, exists=True) - out_file = File("%s_warp", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_warp", desc='output image file name', + argstr='-prefix %s', name_source="in_file") tta2mni = traits.Bool(desc='transform dataset from Talairach to MNI152', argstr='-tta2mni') @@ -245,8 +234,6 @@ class WarpInputSpec(AFNICommandInputSpec): " of zero on all sides.", argstr="-zpad %d") - suffix = traits.Str('_warp', desc="out_file suffix", usedefault=True) - class Warp(AFNICommand): """Use 3dWarp for spatially transforming a dataset @@ -261,6 +248,9 @@ class Warp(AFNICommand): >>> warp = afni.Warp() >>> warp.inputs.in_file = 'structural.nii' >>> warp.inputs.deoblique = True + >>> warp.inputs.out_file = "trans.nii.gz" + >>> warp.cmdline + '3dWarp -deoblique -prefix trans.nii.gz structural.nii' >>> res = warp.run() # doctest: +SKIP """ @@ -278,8 +268,8 @@ class ResampleInputSpec(AFNICommandInputSpec): mandatory=True, exists=True) - out_file = File("%s_resample", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_resample", desc='output image file name', + argstr='-prefix %s', name_source="in_file") orientation = traits.Str(desc='new orientation code', argstr='-orient %s') @@ -309,6 +299,9 @@ class Resample(AFNICommand): >>> resample = afni.Resample() >>> resample.inputs.in_file = 'functional.nii' >>> resample.inputs.orientation= 'RPI' + >>> resample.inputs.outputtype = "NIFTI" + >>> resample.cmdline + '3dresample -orient RPI -prefix functional_resample.nii -inset functional.nii' >>> res = resample.run() # doctest: +SKIP """ @@ -341,8 +334,8 @@ class AutoTcorrelateInputSpec(AFNICommandInputSpec): argstr="-mask_source %s", xor=['mask_only_targets']) - out_file = File("%s_similarity_matrix.1D", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_similarity_matrix.1D", desc='output image file name', + argstr='-prefix %s', name_source="in_file") class AutoTcorrelate(AFNICommand): @@ -356,13 +349,12 @@ class AutoTcorrelate(AFNICommand): >>> from nipype.interfaces import afni as afni >>> corr = afni.AutoTcorrelate() >>> corr.inputs.in_file = 'functional.nii' - >>> corr.inputs.out_file = 'my_similarity_matrix.1D' >>> corr.inputs.polort = -1 >>> corr.inputs.eta2 = True >>> corr.inputs.mask = 'mask.nii' >>> corr.inputs.mask_only_targets = True >>> corr.cmdline # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE - '3dAutoTcorrelate -eta2 -mask mask.nii -mask_only_targets -prefix my_similarity_matrix.1D -polort -1 functional.nii' + '3dAutoTcorrelate -eta2 -mask mask.nii -mask_only_targets -prefix functional_similarity_matrix.1D -polort -1 functional.nii' >>> res = corr.run() # doctest: +SKIP """ input_spec = AutoTcorrelateInputSpec @@ -383,8 +375,8 @@ class TStatInputSpec(AFNICommandInputSpec): mandatory=True, exists=True) - out_file = File("%s_tstat", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_tstat", desc='output image file name', + argstr='-prefix %s', name_source="in_file") mask = File(desc='mask file', argstr='-mask %s', @@ -406,6 +398,9 @@ class TStat(AFNICommand): >>> tstat = afni.TStat() >>> tstat.inputs.in_file = 'functional.nii' >>> tstat.inputs.args= '-mean' + >>> tstat.inputs.out_file = "stats" + >>> tstat.cmdline + '3dTstat -mean -prefix stats functional.nii' >>> res = tstat.run() # doctest: +SKIP """ @@ -422,8 +417,8 @@ class DetrendInputSpec(AFNICommandInputSpec): mandatory=True, exists=True) - out_file = File("%s_detrend", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_detrend", desc='output image file name', + argstr='-prefix %s', name_source="in_file") class Detrend(AFNICommand): @@ -440,6 +435,9 @@ class Detrend(AFNICommand): >>> detrend = afni.Detrend() >>> detrend.inputs.in_file = 'functional.nii' >>> detrend.inputs.args = '-polort 2' + >>> detrend.inputs.outputtype = "AFNI" + >>> detrend.cmdline + '3dDetrend -polort 2 -prefix functional_detrend functional.nii' >>> res = detrend.run() # doctest: +SKIP """ @@ -456,8 +454,8 @@ class DespikeInputSpec(AFNICommandInputSpec): mandatory=True, exists=True) - out_file = File("%s_despike", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_despike", desc='output image file name', + argstr='-prefix %s', name_source="in_file") class Despike(AFNICommand): @@ -472,6 +470,8 @@ class Despike(AFNICommand): >>> from nipype.interfaces import afni as afni >>> despike = afni.Despike() >>> despike.inputs.in_file = 'functional.nii' + >>> despike.cmdline + '3dDespike -prefix functional_despike functional.nii' >>> res = despike.run() # doctest: +SKIP """ @@ -488,14 +488,13 @@ class AutomaskInputSpec(AFNICommandInputSpec): mandatory=True, exists=True) - out_file = File("%s_mask", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_mask", desc='output image file name', + argstr='-prefix %s', name_source="in_file") - brain_file = File("%s_masked", + brain_file = File(name_template="%s_masked", desc="output file from 3dAutomask", argstr='-apply_prefix %s', - name_source="in_file", - usedefault=True) + name_source="in_file") clfrac = traits.Float(desc='sets the clip level fraction' + ' (must be 0.1-0.9). ' + @@ -531,7 +530,7 @@ class Automask(AFNICommand): >>> automask.inputs.dilate = 1 >>> automask.inputs.outputtype = "NIFTI" >>> automask.cmdline #doctest: +ELLIPSIS - '3dAutomask -apply_prefix .../functional_masked.nii -dilate 1 -prefix .../functional_mask.nii functional.nii' + '3dAutomask -apply_prefix functional_masked.nii -dilate 1 -prefix functional_mask.nii functional.nii' >>> res = automask.run() # doctest: +SKIP """ @@ -548,8 +547,8 @@ class VolregInputSpec(AFNICommandInputSpec): position=-1, mandatory=True, exists=True) - out_file = File("%s_volreg", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_volreg", desc='output image file name', + argstr='-prefix %s', name_source="in_file") basefile = File(desc='base file for registration', argstr='-base %s', @@ -562,11 +561,10 @@ class VolregInputSpec(AFNICommandInputSpec): md1dfile = File(desc='max displacement output file', argstr='-maxdisp1D %s', position=-4) - oned_file = File('%s.1D', desc='1D movement parameters output file', + oned_file = File(name_template='%s.1D', desc='1D movement parameters output file', argstr='-1Dfile %s', name_source="in_file", - keep_extension=True, - usedefault=True) + keep_extension=True) verbose = traits.Bool(desc='more detailed description of the process', argstr='-verbose') timeshift = traits.Bool(desc='time shift to mean slice time offset', @@ -597,7 +595,7 @@ class Volreg(AFNICommand): >>> volreg.inputs.zpad = 4 >>> volreg.inputs.outputtype = "NIFTI" >>> volreg.cmdline #doctest: +ELLIPSIS - '3dvolreg -Fourier -twopass -1Dfile .../functional.1D -prefix .../functional_volreg.nii -zpad 4 functional.nii' + '3dvolreg -Fourier -twopass -1Dfile functional.1D -prefix functional_volreg.nii -zpad 4 functional.nii' >>> res = volreg.run() # doctest: +SKIP """ @@ -613,8 +611,8 @@ class MergeInputSpec(AFNICommandInputSpec): argstr='%s', position=-1, mandatory=True) - out_file = File("%s_merge", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_merge", desc='output image file name', + argstr='-prefix %s', name_source="in_file") doall = traits.Bool(desc='apply options to all sub-bricks in dataset', argstr='-doall') blurfwhm = traits.Int(desc='FWHM blur value (mm)', @@ -652,8 +650,8 @@ class CopyInputSpec(AFNICommandInputSpec): position=-2, mandatory=True, exists=True) - out_file = File("%s_copy", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_copy", desc='output image file name', + argstr='-prefix %s', name_source="in_file") class Copy(AFNICommand): @@ -685,8 +683,8 @@ class FourierInputSpec(AFNICommandInputSpec): position=-1, mandatory=True, exists=True) - out_file = File("%s_fourier", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_fourier", desc='output image file name', + argstr='-prefix %s', name_source="in_file") lowpass = traits.Float(desc='lowpass', argstr='-lowpass %f', position=0, @@ -730,13 +728,12 @@ class BandpassInputSpec(AFNICommandInputSpec): mandatory=True, exists=True) out_file = File( - '%s_bp', + name_template='%s_bp', desc='output file from 3dBandpass', argstr='-prefix %s', position=1, name_source='in_file', - genfile=True, - usedefault=True) + genfile=True) lowpass = traits.Float( desc='lowpass', argstr='%f', @@ -838,8 +835,8 @@ class ZCutUpInputSpec(AFNICommandInputSpec): position=-1, mandatory=True, exists=True) - out_file = File("%s_zcupup", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_zcupup", desc='output image file name', + argstr='-prefix %s', name_source="in_file") keep = traits.Str(desc='slice range to keep in output', argstr='-keep %s') @@ -884,7 +881,6 @@ class AllineateInputSpec(AFNICommandInputSpec): position=-2, name_source='%s_allineate', genfile=True) - suffix = traits.Str('_allineate', desc="out_file suffix", usedefault=True) out_param_file = File( argstr='-1Dparam_save %s', @@ -1112,10 +1108,9 @@ class MaskaveInputSpec(AFNICommandInputSpec): position=-2, mandatory=True, exists=True) - out_file = File("%s_maskave.1D", desc='output image file name', + out_file = File(name_template="%s_maskave.1D", desc='output image file name', keep_extension=True, - argstr="> %s", name_source="in_file", usedefault=True, - position=-1) + argstr="> %s", name_source="in_file", position=-1) mask = File(desc='matrix to align input file', argstr='-mask %s', position=1, @@ -1141,7 +1136,7 @@ class Maskave(AFNICommand): >>> maskave.inputs.mask= 'seed_mask.nii' >>> maskave.inputs.quiet= True >>> maskave.cmdline #doctest: +ELLIPSIS - '3dmaskave -mask seed_mask.nii -quiet functional.nii > .../functional_maskave.1D' + '3dmaskave -mask seed_mask.nii -quiet functional.nii > functional_maskave.1D' >>> res = maskave.run() # doctest: +SKIP """ @@ -1157,8 +1152,8 @@ class SkullStripInputSpec(AFNICommandInputSpec): position=1, mandatory=True, exists=True) - out_file = File("%s_skullstrip", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_skullstrip", desc='output image file name', + argstr='-prefix %s', name_source="in_file") class SkullStrip(AFNICommand): @@ -1190,8 +1185,8 @@ class TCatInputSpec(AFNICommandInputSpec): argstr=' %s', position=-1, mandatory=True) - out_file = File("%s_tcat", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_tcat", desc='output image file name', + argstr='-prefix %s', name_source="in_file") rlt = traits.Str(desc='options', argstr='-rlt%s', position=1) @@ -1225,8 +1220,8 @@ class FimInputSpec(AFNICommandInputSpec): position=1, mandatory=True, exists=True) - out_file = File("%s_fim", desc='output image file name', - argstr='-bucket %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s_fim", desc='output image file name', + argstr='-bucket %s', name_source="in_file") ideal_file = File(desc='ideal time series file name', argstr='-ideal_file %s', position=2, @@ -1265,7 +1260,7 @@ class Fim(AFNICommand): output_spec = AFNICommandOutputSpec -class TCorrelateInputSpec(AFNIBaseCommandInputSpec): +class TCorrelateInputSpec(AFNICommandInputSpec): xset = File(desc='input xset', argstr=' %s', position=-2, @@ -1276,8 +1271,8 @@ class TCorrelateInputSpec(AFNIBaseCommandInputSpec): position=-1, mandatory=True, exists=True) - out_file = File("%s_tcorr", desc='output image file name', - argstr='-prefix %s', name_source="xset", usedefault=True) + out_file = File(name_template="%s_tcorr", desc='output image file name', + argstr='-prefix %s', name_source="xset") pearson = traits.Bool(desc='Correlation is the normal' + ' Pearson correlation coefficient', argstr='-pearson', @@ -1286,7 +1281,7 @@ class TCorrelateInputSpec(AFNIBaseCommandInputSpec): argstr='-polort %d', position=2) -class TCorrelate(AFNIBaseCommand): +class TCorrelate(AFNICommand): """Computes the correlation coefficient between corresponding voxel time series in two input 3D+time datasets 'xset' and 'yset' @@ -1312,7 +1307,7 @@ class TCorrelate(AFNIBaseCommand): output_spec = AFNICommandOutputSpec -class BrickStatInputSpec(AFNIBaseCommandInputSpec): +class BrickStatInputSpec(AFNICommandInputSpec): in_file = File(desc='input file to 3dmaskave', argstr='%s', position=-1, @@ -1333,7 +1328,7 @@ class BrickStatOutputSpec(TraitedSpec): min_val = traits.Float(desc='output') -class BrickStat(AFNIBaseCommand): +class BrickStat(AFNICommand): """Compute maximum and/or minimum voxel values of an input dataset For complete details, see the `3dBrickStat Documentation. @@ -1383,7 +1378,7 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None): return outputs -class ROIStatsInputSpec(AFNIBaseCommandInputSpec): +class ROIStatsInputSpec(AFNICommandInputSpec): in_file = File(desc='input file to 3dROIstats', argstr='%s', position=-1, @@ -1410,7 +1405,7 @@ class ROIStatsOutputSpec(TraitedSpec): stats = File(desc='output', exists=True) -class ROIStats(AFNIBaseCommand): +class ROIStats(AFNICommand): """Display statistics over masked regions For complete details, see the `3dROIstats Documentation. @@ -1466,22 +1461,13 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None): return outputs -""" -3dcalc -a ${rest}.nii.gz[${TRstart}..${TRend}] -expr 'a' -prefix $ -{rest}_dr.nii.gz - -3dcalc -a ${rest}_mc.nii.gz -b ${rest}_mask.nii.gz -expr 'a*b' -prefix -${rest}_ss.nii.gz -""" - - class CalcInputSpec(AFNICommandInputSpec): in_file_a = File(desc='input file to 3dcalc', argstr='-a %s', position=0, mandatory=True, exists=True) in_file_b = File(desc='operand file to 3dcalc', argstr=' -b %s', position=1, exists=True) - out_file = File("%s_calc", desc='output image file name', - argstr='-prefix %s', name_source="in_file_a", usedefault=True) + out_file = File(name_template="%s_calc", desc='output image file name', + argstr='-prefix %s', name_source="in_file_a") expr = traits.Str(desc='expr', argstr='-expr "%s"', position=2, mandatory=True) start_idx = traits.Int(desc='start index for in_file_a', @@ -1490,7 +1476,6 @@ class CalcInputSpec(AFNICommandInputSpec): requires=['start_idx']) single_idx = traits.Int(desc='volume index for in_file_a') other = File(desc='other options', argstr='') - suffix = traits.Str('_calc', desc="out_file suffix", usedefault=True) class Calc(AFNICommand): @@ -1510,7 +1495,7 @@ class Calc(AFNICommand): >>> calc.inputs.out_file = 'functional_calc.nii.gz' >>> calc.inputs.outputtype = "NIFTI" >>> calc.cmdline #doctest: +ELLIPSIS - '3dcalc -a functional.nii -b functional2.nii -expr "a*b" -prefix functional_calc.nii' + '3dcalc -a functional.nii -b functional2.nii -expr "a*b" -prefix functional_calc.nii.gz' """ @@ -1543,9 +1528,8 @@ class BlurInMaskInputSpec(AFNICommandInputSpec): position=1, mandatory=True, exists=True) - out_file = File('%s_blur', desc='output to the file', argstr='-prefix %s', - name_source='in_file', position=-1, genfile=True, - usedefault=True) + out_file = File(name_template='%s_blur', desc='output to the file', argstr='-prefix %s', + name_source='in_file', position=-1) mask = File( desc='Mask dataset, if desired. Blurring will occur only within the mask. Voxels NOT in the mask will be set to zero in the output.', argstr='-mask %s') @@ -1566,7 +1550,6 @@ class BlurInMaskInputSpec(AFNICommandInputSpec): desc='Save dataset as floats, no matter what the input data type is.', argstr='-float') options = traits.Str(desc='options', argstr='%s', position=2) - suffix = traits.Str('_blurmask', desc="out_file suffix", usedefault=True) class BlurInMask(AFNICommand): @@ -1584,7 +1567,7 @@ class BlurInMask(AFNICommand): >>> bim.inputs.mask = 'mask.nii' >>> bim.inputs.fwhm = 5.0 >>> bim.cmdline #doctest: +ELLIPSIS - '3dBlurInMask -input functional.nii -FWHM 5.000000 -mask mask.nii -prefix .../functional_blur+orig.BRIK' + '3dBlurInMask -input functional.nii -FWHM 5.000000 -mask mask.nii -prefix functional_blur' >>> res = bim.run() # doctest: +SKIP """ @@ -1594,7 +1577,7 @@ class BlurInMask(AFNICommand): output_spec = AFNICommandOutputSpec -class TCorrMapInputSpec(AFNIBaseCommandInputSpec): +class TCorrMapInputSpec(AFNICommandInputSpec): in_file = File(exists=True, argstr='-input %s', mandatory=True) seeds = File(exists=True, argstr='-seed %s', xor=('seeds_width')) mask = File(exists=True, argstr='-mask %s') @@ -1840,8 +1823,8 @@ class AFNItoNIFTIInputSpec(AFNICommandInputSpec): position=-1, mandatory=True, exists=True) - out_file = File("%s.nii", desc='output image file name', - argstr='-prefix %s', name_source="in_file", usedefault=True) + out_file = File(name_template="%s.nii", desc='output image file name', + argstr='-prefix %s', name_source="in_file") hash_files = False class AFNItoNIFTI(AFNICommand): @@ -1858,7 +1841,7 @@ class AFNItoNIFTI(AFNICommand): >>> a2n.inputs.in_file = 'afni_output.3D' >>> a2n.inputs.out_file = 'afni_output.nii' >>> a2n.cmdline - '3dAFNItoNIFTI afni_output.3D' + '3dAFNItoNIFTI -prefix afni_output.nii afni_output.3D' """ diff --git a/nipype/interfaces/afni/tests/test_preprocess.py b/nipype/interfaces/afni/tests/test_preprocess.py index 2d1d7bde93..8b5f310f38 100644 --- a/nipype/interfaces/afni/tests/test_preprocess.py +++ b/nipype/interfaces/afni/tests/test_preprocess.py @@ -106,7 +106,7 @@ def test_to3d(): filetype=dict(argstr='-%s',), funcparams=dict(argstr='-time:zt %s alt+z2',), ignore_exception=dict(usedefault=True,), - infolder=dict(argstr='%s/*.dcm', mandatory=True,), + in_folder=dict(argstr='%s/*.dcm', mandatory=True,), out_file=dict(argstr='-prefix %s'), outputtype=dict(), skipoutliers=dict(argstr='-skip_outliers',),