From 01d10cb1a464d6e97a3062a1592ef82a95307321 Mon Sep 17 00:00:00 2001 From: ssikka Date: Tue, 24 Jan 2012 18:09:50 -0500 Subject: [PATCH 1/6] BF added New AFNI interfaces with new fixes --- nipype/interfaces/afni/preprocess.py | 1656 +++++++++++++++++++------- 1 file changed, 1196 insertions(+), 460 deletions(-) mode change 100644 => 100755 nipype/interfaces/afni/preprocess.py diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py old mode 100644 new mode 100755 index c632828ad3..93d97b7cf9 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -1,563 +1,1299 @@ -# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- -# vi: set ft=python sts=4 ts=4 sw=4 et: -"""Provide interface to AFNI commands. +__docformat__ = 'restructuredtext' +import warnings +import os +import nibabel as nb +import numpy as np +from string import Template +from nipype.utils.filemanip import split_filename +from nipype.interfaces.matlab import MatlabCommand +from nipype.interfaces.base import BaseInterface, BaseInterfaceInputSpec +from nipype.interfaces.afni.base import AFNITraitedSpec, AFNICommand, Info +from nipype.interfaces.base import Bunch, TraitedSpec, File, Directory, traits, isdefined +from nipype.interfaces.base import (CommandLineInputSpec, CommandLine, TraitedSpec, traits, isdefined, File) +from nipype.utils.filemanip import load_json, save_json, split_filename, fname_presuffix +warn = warnings.warn +warnings.filterwarnings('always', category=UserWarning) - Change directory to provide relative paths for doctests - >>> import os - >>> filepath = os.path.dirname( os.path.realpath( __file__ ) ) - >>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data')) - >>> os.chdir(datadir) -""" -__docformat__ = 'restructuredtext' +class AFNICommandGenFile(AFNICommand): + def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True, ext=None): +"""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. -import warnings +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 '') +change_ext : bool +Flag to change the filename extension to the AFNI output type. +(default True) -from nipype.interfaces.afni.base import AFNITraitedSpec, AFNICommand -from nipype.interfaces.base import Bunch, TraitedSpec, File, Directory, traits +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() + + if ext is None: + ext = Info.outputtype_to_ext(self.inputs.outputtype) + + if change_ext: + if suffix: + suffix = ''.join((suffix, ext)) + else: + suffix = ext + + if suffix is None: + suffix = '' + + fname = fname_presuffix(basename, suffix = suffix, + use_ext = False, newpath = cwd) + + return fname + + def _gen_filename(self, name): + if name == 'out_file': + return self._gen_outfilename() + return None -warn = warnings.warn -warnings.filterwarnings('always', category=UserWarning) class To3dInputSpec(AFNITraitedSpec): - infolder = Directory(desc = 'folder with DICOM images to convert', - argstr = '%s/*.dcm', - position = -1, - mandatory = True, - exists = True) - outfile = File(desc = 'converted image file', - argstr = '-prefix %s', - position = -2, - mandatory = True) - filetype = traits.Enum('spgr', 'fse', 'epan', 'anat', 'ct', 'spct','pet', 'mra', 'bmap', 'diff', - 'omri', 'abuc','fim', 'fith', 'fico', 'fitt', 'fift','fizt', 'fict', 'fibt', - 'fibn','figt','fipt','fbuc', argstr = '-%s', desc='type of datafile being converted') - '''use xor''' - skipoutliers = traits.Bool(desc = 'skip the outliers check', - argstr = '-skip_outliers') - assumemosaic = traits.Bool(desc = 'assume that Siemens image is mosaic', - argstr = '-assume_dicom_mosaic') - datatype = traits.Enum('short', 'float', 'byte', 'complex', desc = 'set output file datatype', - argstr = '-datum %s') - funcparams = traits.Str(desc = 'parameters for functional data', - argstr = '-time:zt %s alt+z2') + infolder = Directory(desc = 'folder with DICOM images to convert', + argstr = '%s/*.dcm', + position = -1, + mandatory = True, + exists = True) + + outfile = File(desc = 'converted image file', + argstr = '-prefix %s', + position = -2, + mandatory = True) -class To3dOutputSpec(TraitedSpec): - out_file = File(desc = 'converted file', - exists = True) + filetype = traits.Enum('spgr', 'fse', 'epan', 'anat', 'ct', 'spct','pet', 'mra', 'bmap', 'diff', + 'omri', 'abuc','fim', 'fith', 'fico', 'fitt', 'fift','fizt', 'fict', 'fibt', + 'fibn','figt','fipt','fbuc', argstr = '-%s', desc='type of datafile being converted') -class To3d(AFNICommand): - """Create a 3D dataset from 2D image files using AFNI to3d command. + '''use xor''' + skipoutliers = traits.Bool(desc = 'skip the outliers check', + argstr = '-skip_outliers') - For complete details, see the `to3d Documentation. - `_ + assumemosaic = traits.Bool(desc = 'assume that Siemens image is mosaic', + argstr = '-assume_dicom_mosaic') + - To print out the command line help, use: - To3d().inputs_help() + datatype = traits.Enum('short', 'float', 'byte', 'complex', desc = 'set output file datatype', + argstr = '-datum %s') - Examples - -------- - >>> from nipype.interfaces import afni - >>> to3d = afni.To3d() - AFNI has no environment variable that sets filetype - Nipype uses NIFTI_GZ as default - >>> to3d.inputs.datatype = 'float' - >>> to3d.inputs.infolder='dicomdir' - >>> to3d.inputs.filetype="anat" - >>> res = to3d.run() #doctest: +SKIP + funcparams = traits.Str(desc = 'parameters for functional data', + argstr = '-time:zt %s alt+z2') - """ - _cmd = 'to3d' - input_spec = To3dInputSpec - output_spec = To3dOutputSpec +class To3dOutputSpec(TraitedSpec): + out_file = File(desc = 'converted file', + exists = True) - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs +class To3d(AFNICommand): +"""Create a 3D dataset from 2D image files using AFNI to3d command. +For complete details, see the `to3d Documentation. +`_ -class ThreedrefitInputSpec(AFNITraitedSpec): - infile = File(desc = 'input file to 3drefit', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - deoblique = traits.Bool(desc = 'replace current transformation matrix with cardinal matrix', - argstr = '-deoblique') - xorigin = traits.Str(desc = 'x distance for edge voxel offset', - argstr = '-xorigin %s') - yorigin = traits.Str(desc = 'y distance for edge voxel offset', - argstr = '-yorigin %s') - zorigin = traits.Str(desc = 'y distance for edge voxel offset', - argstr = '-yorigin %s') +To print out the command line help, use: +To3d().inputs_help() -class ThreedrefitOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'Same file as original infile with modified matrix', - exists = True) +Examples +-------- +>>> from nipype.interfaces import afni +>>> to3d = afni.To3d() +AFNI has no environment variable that sets filetype +Nipype uses NIFTI_GZ as default +>>> to3d.inputs.datatype = 'float' +>>> to3d.inputs.infolder='dicomdir' +>>> to3d.inputs.filetype="anat" +>>> res = to3d.run() #doctest: +SKIP -class Threedrefit(AFNICommand): - """ Use 3drefit for altering header info. +""" - NOTES - ----- - The original file is returned but it is CHANGED - """ + _cmd = 'to3d' + input_spec = To3dInputSpec + output_spec = To3dOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.outfile + return outputs + + +class ThreedTshiftInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dTShift', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + out_file = File(desc = 'output file from 3dTshift', + argstr = '-prefix %s', + position = 0, + genfile = True) + + tr = traits.Str(desc = 'manually set the TR instead of looking in the header. ' + + 'You can attach suffix "s" for seconds or "ms" for milliseconds.', + argstr = '-TR %s') + + tzero = traits.Float(desc = 'align each slice to given time offset', + argstr = '-tzero %s', + xor = ['tslice']) + + tslice = traits.Int(desc = 'align each slice to time offset of given slice', + argstr = '-slice %s', + xor = ['tzero']) + + ignore = traits.Int(desc = 'ignore the first set of points specified', + argstr = '-ignore %s') + + interp = traits.Enum(('Fourier', 'linear', 'cubic', 'quintic', 'heptic'), + desc='different interpolation methods (see 3dTShift for details)' + + ' default=Fourier', argstr='-%s') + + tpattern = traits.Enum(('alt+z', 'alt+z2', 'alt-z', 'alt-z2', 'seq+z', 'seq-z'), + desc='use specified slice time pattern rather than one in header', + argstr='-tpattern %s') + + rlt = traits.Bool(desc='Before shifting, remove the mean and linear trend', + argstr="-rlt") + + rltplus = traits.Bool(desc='Before shifting, remove the mean and linear trend and ' + + 'later put back the mean', + argstr="-rlt+") + + suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value + + +class ThreedTshiftOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'post slice time shifted 4D image') + + +class ThreedTshift(AFNICommand): +"""Shifts voxel time series from input so that seperate slices are aligned to the same +temporal origin. +For complete details, see the `3dTshift Documentation. +`_ +""" + + _cmd = '3dTshift' + input_spec = ThreedTshiftInputSpec + output_spec = ThreedTshiftOutputSpec + + def _gen_filename(self, name): + if name == 'out_file': + return self._list_outputs()[name] + return None + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.out_file + if not isdefined(outputs['out_file']): + + if isdefined(self.inputs.suffix): + suffix = self.inputs.suffix + else: + suffix = "_tshift" + outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix) + return outputs + - _cmd = '3drefit' - input_spec = ThreedrefitInputSpec - output_spec = ThreedrefitOutputSpec +class ThreedrefitInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3drefit', + argstr = '%s', + position = -1, + mandatory = True, + exists = True, + copyfile = True) + + deoblique = traits.Bool(desc = 'replace current transformation matrix with cardinal matrix', + argstr = '-deoblique') + + xorigin = traits.Str(desc = 'x distance for edge voxel offset', + argstr = '-xorigin %s') + + yorigin = traits.Str(desc = 'y distance for edge voxel offset', + argstr = '-yorigin %s') + zorigin = traits.Str(desc = 'z distance for edge voxel offset', + argstr = '-zorigin %s') - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.infile - return outputs +class ThreedrefitOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'Same file as original infile with modified matrix', + exists = True) +class Threedrefit(AFNICommand): +""" Use 3drefit for altering header info. +NOTES +----- +The original file is returned but it is CHANGED +""" + + _cmd = '3drefit' + input_spec = ThreedrefitInputSpec + output_spec = ThreedrefitOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.in_file + return outputs + + +class ThreedWarpInputSpec(AFNITraitedSpec): + + in_file = File(desc = 'input file to 3dWarp', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + + out_file = File(desc = 'output file from 3dWarp', + argstr = '-prefix %s', + position = 0, + genfile = True) + + tta2mni = traits.Bool(desc = 'transform dataset from Talairach to MNI152', + argstr = '-tta2mni') + + mni2tta = traits.Bool(desc = 'transform dataset from MNI152 to Talaraich', + argstr = '-mni2tta') + + matparent = File(desc = "apply transformation from 3dWarpDrive", + argstr = "-matparent %s", + exists = True) + + deoblique = traits.Bool(desc = 'transform dataset from oblique to cardinal', + argstr = '-deoblique') + + interp = traits.Enum(('linear', 'cubic', 'NN', 'quintic'), + desc='spatial interpolation methods [default=linear]', + argstr='-%s') + + gridset = File(desc = "copy grid of specified dataset", + argstr = "-gridset %s", + exists = True) + + zpad = traits.Int(desc="pad input dataset with N planes of zero on all sides.", + argstr="-zpad %s") + + suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value + +class ThreedWarpOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'spatially transformed input image', exists=True) + +class ThreedWarp(AFNICommand): +""" Use 3dWarp for spatially transforming a dataset +For complete details, see the `3dTshift Documentation. +`_ +""" + + _cmd = '3dWarp' + input_spec = ThreedWarpInputSpec + output_spec = ThreedWarpOutputSpec + + def _gen_filename(self, name): + if name == 'out_file': + return self._list_outputs()[name] + return None + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.out_file + if not isdefined(outputs['out_file']): + if isdefined(self.inputs.suffix): + suffix = self.inputs.suffix + else: + suffix = "_warp" + outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix) + return outputs + + class ThreedresampleInputSpec(AFNITraitedSpec): - infile = File(desc = 'input file to 3dresample', - argstr = '-inset %s', - position = -1, - mandatory = True, - exists = True) - outfile = File(desc = 'output file from 3dresample', - argstr = '-prefix %s', - position = -2, - mandatory = True) - orientation = traits.Str(desc = 'new orientation code', - argstr = '-orient %s') + + in_file = File(desc = 'input file to 3dresample', + argstr = '-inset %s', + position = -1, + mandatory = True, + exists = True) + + out_file = File(desc = 'output file from 3dresample', + argstr = '-prefix %s', + position = -2, + genfile = True) + + orientation = traits.Str(desc = 'new orientation code', + argstr = '-orient %s') + + suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value class ThreedresampleOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'reoriented or resampled file', - exists = True) + out_file = File(desc = 'reoriented or resampled file', + exists = True) class Threedresample(AFNICommand): """Resample or reorient an image using AFNI 3dresample command. +For complete details, see the `3dresample Documentation. +`_ +""" + + _cmd = '3dresample' + input_spec = ThreedresampleInputSpec + output_spec = ThreedresampleOutputSpec + + def _gen_filename(self, name): + if name == 'out_file': + return self._list_outputs()[name] + return None + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.out_file + if not isdefined(outputs['out_file']): + if isdefined(self.inputs.suffix): + suffix = self.inputs.suffix + else: + suffix = [] # allow for resampling command later! + if self.inputs.orientation: + suffix.append("_RPI") + suffix = "".join(suffix) + outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix) + return outputs + - For complete details, see the `3dresample Documentation. - `_ - """ - - _cmd = '3dresample' - input_spec = ThreedresampleInputSpec - output_spec = ThreedresampleOutputSpec - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs +class ThreedTstatInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dTstat', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + out_file = File(desc = 'output file from 3dTstat', + argstr = '-prefix %s', + position = -2, + genfile = True) -class ThreedTstatInputSpec(AFNITraitedSpec): - infile = File(desc = 'input file to 3dTstat', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - outfile = File(desc = 'output file from 3dTstat', - argstr = '-prefix %s', - position = -2, - mandatory = True) - options = traits.Str(desc = 'selected statistical output', - argstr = '%s') + options = traits.Str(desc = 'selected statistical output', + argstr = '%s') class ThreedTstatOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'statistical file', - exists = True) + out_file = File(desc = 'statistical file', + exists = True) class ThreedTstat(AFNICommand): - """Compute voxel-wise statistics using AFNI 3dTstat command. +"""Compute voxel-wise statistics using AFNI 3dTstat command. - For complete details, see the `3dTstat Documentation. - `_ - """ +For complete details, see the `3dTstat Documentation. +`_ +""" - _cmd = '3dTstat' - input_spec = ThreedTstatInputSpec - output_spec = ThreedTstatOutputSpec + _cmd = '3dTstat' + input_spec = ThreedTstatInputSpec + output_spec = ThreedTstatOutputSpec + + def _gen_filename(self, name): + """Generate output file name + """ + + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dT',ext))) + + + def _list_outputs(self): + outputs = self.output_spec().get() + #outputs['out_file'] = os.path.abspath(self.inputs.out_file) + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + return outputs + + +class ThreedDetrendInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dDetrend', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + out_file = File(desc = 'output file from 3dTstat', + argstr = '-prefix %s', + position = -2, + genfile = True) + options = traits.Str(desc = 'selected statistical output', + argstr = '%s') + +class ThreedDetrendOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'statistical file', + exists = True) + +class ThreedDetrend(AFNICommand): +"""Compute voxel-wise statistics using AFNI 3dTstat command. + +For complete details, see the `3dTstat Documentation. +`_ +""" - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs + _cmd = '3dDetrend' + input_spec = ThreedDetrendInputSpec + output_spec = ThreedDetrendOutputSpec -class ThreedAutomaskInputSpec(AFNITraitedSpec): - infile = File(desc = 'input file to 3dAutomask', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - outfile = File(desc = 'output file from 3dAutomask', - argstr = '-prefix %s', - position = -2, - mandatory = True) - options = traits.Str(desc = 'automask settings', - argstr = '%s') + def _gen_filename(self, name): + """Generate output file name + """ + + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dD',ext))) -class ThreedAutomaskOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'mask file', - exists = True) -class ThreedAutomask(AFNICommand): - """Create a brain-only mask of the image using AFNI 3dAutomask command. + def _list_outputs(self): + outputs = self.output_spec().get() + #outputs['out_file'] = os.path.abspath(self.inputs.out_file) + + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + return outputs + + +class ThreedDespikeInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dDespike', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + + out_file = File(desc = 'output file from 3dDespike', + argstr = '-prefix %s', + position = -2, + genfile = True) + + options = traits.Str(desc = 'additional args', + argstr = '%s') + +class ThreedDespikeOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'despiked img', + exists = True) + +class ThreedDespike(AFNICommand): +"""Compute voxel-wise statistics using AFNI 3dTstat command. + +For complete details, see the `3dDespike Documentation. +`_ +""" + + _cmd = '3dDespike' + input_spec = ThreedDespikeInputSpec + output_spec = ThreedDespikeOutputSpec - For complete details, see the `3dAutomask Documentation. - `_ - """ + def _gen_filename(self, name): + """Generate output file name + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dDe',ext))) - _cmd = '3dAutomask' - input_spec = ThreedAutomaskInputSpec - output_spec = ThreedAutomaskOutputSpec + def _list_outputs(self): + outputs = self.output_spec().get() + #outputs['out_file'] = os.path.abspath(self.inputs.out_file) - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + return outputs +class ThreedAutomaskInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dAutomask', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + + out_file = File(desc = 'output file from 3dAutomask (a brain mask)', + argstr = '-prefix %s', + position = -2, + genfile = True) + + apply_mask = File(desc = "output file from 3dAutomask (masked version of input dataset)", + argstr = '-apply_prefix %s') + + clfrac = traits.Float(desc = 'sets the clip level fraction (must be 0.1-0.9). ' + + 'A small value will tend to make the mask larger [default=0.5].', + argstr = "-dilate %s") + + dilate = traits.Int(desc = 'dilate the mask outwards', + argstr = "-dilate %s") + + erode = traits.Int(desc = 'erode the mask inwards', + argstr = "-erode %s") + + options = traits.Str(desc = 'automask settings', + argstr = '%s') + + suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value + +class ThreedAutomaskOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'mask file', + exists = True) + + brain_file = File(desc = 'brain file (skull stripped)', + exists = True) + +class ThreedAutomask(AFNICommand): +"""Create a brain-only mask of the image using AFNI 3dAutomask command. +For complete details, see the `3dAutomask Documentation. +`_ +""" + + _cmd = '3dAutomask' + input_spec = ThreedAutomaskInputSpec + output_spec = ThreedAutomaskOutputSpec + + def _gen_filename(self, name): + if name == 'out_file': + return self._list_outputs()[name] + return None + + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['brain_file'] = self.inputs.apply_mask + outputs['out_file'] = self.inputs.out_file + + if not isdefined(outputs['out_file']): + if isdefined(self.inputs.suffix): + suffix = self.inputs.suffix + else: + suffix = "_automask" + + outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix) + return outputs + class ThreedvolregInputSpec(AFNITraitedSpec): - infile = File(desc = 'input file to 3dvolreg', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - outfile = File(desc = 'output file from 3dvolreg', - argstr = '-prefix %s', - position = -2, - mandatory = True) - basefile = File(desc = 'base file for registration', - argstr = '-base %s', - position = -5) - md1dfile = File(desc = 'max displacement output file', - argstr = '-maxdisp1D %s', - position = -4) - onedfile = File(desc = '1D movement parameters output file', - argstr = '-1Dfile %s', - position = -3) - verbose = traits.Bool(desc = 'more detailed description of the process', - argstr = '-verbose') - timeshift = traits.Bool(desc = 'time shift to mean slice time offset', - argstr = '-tshift 0') - copyorigin = traits.Bool(desc = 'copy base file origin coords to output', - argstr = '-twodup') - other = traits.Str(desc = 'other options', - argstr = '%s') + + in_file = File(desc = 'input file to 3dvolreg', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + out_file = File(desc = 'output file from 3dvolreg', + argstr = '-prefix %s', + position = -2, + genfile = True) + basefile = File(desc = 'base file for registration', + argstr = '-base %s', + position = -6) + zpad = File(desc = 'Zeropad around the edges by \'n\' voxels during rotations', + argstr = '-zpad %s', + position = -5) + md1dfile = File(desc = 'max displacement output file', + argstr = '-maxdisp1D %s', + position = -4) + oned_file = File(desc = '1D movement parameters output file', + argstr = '-1Dfile %s', + position = -3, + genfile = True) + verbose = traits.Bool(desc = 'more detailed description of the process', + argstr = '-verbose') + timeshift = traits.Bool(desc = 'time shift to mean slice time offset', + argstr = '-tshift 0') + copyorigin = traits.Bool(desc = 'copy base file origin coords to output', + argstr = '-twodup') + other = traits.Str(desc = 'other options', + argstr = '%s') class ThreedvolregOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'registered file', - exists = True) - md1d_file = File(desc = 'max displacement info file') - oned_file = File(desc = 'movement parameters info file') + out_file = File(desc = 'registered file', + exists = True) + md1d_file = File(desc = 'max displacement info file') + oned_file = File(desc = 'movement parameters info file') class Threedvolreg(AFNICommand): - """Register input volumes to a base volume using AFNI 3dvolreg command. +"""Register input volumes to a base volume using AFNI 3dvolreg command. - For complete details, see the `3dvolreg Documentation. - `_ - """ - - _cmd = '3dvolreg' - input_spec = ThreedvolregInputSpec - output_spec = ThreedvolregOutputSpec +For complete details, see the `3dvolreg Documentation. +`_ +""" - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs + _cmd = '3dvolreg' + input_spec = ThreedvolregInputSpec + output_spec = ThreedvolregOutputSpec + + def _gen_filename(self, name): + """Generate output file name + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dv',ext))) + + + if name == 'oned_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dv1D','.1D'))) + + + def _list_outputs(self): + outputs = self.output_spec().get() +# outputs['out_file'] = os.path.abspath(self.inputs.out_file) +# outputs['oned_file'] = os.path.abspath(self.inputs.oned_file) + + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + + + if not isdefined(self.inputs.oned_file): + outputs['oned_file'] = self._gen_filename('oned_file') + else: + outputs['oned_file'] = os.path.abspath(self.inputs.oned_file) + + return outputs class ThreedmergeInputSpec(AFNITraitedSpec): - infile = File(desc = 'input file to 3dvolreg', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - outfile = File(desc = 'output file from 3dvolreg', - argstr = '-prefix %s', - position = -2, - mandatory = True) - doall = traits.Bool(desc = 'apply options to all sub-bricks in dataset', - argstr = '-doall') - blurfwhm = traits.Int(desc = 'FWHM blur value (mm)', - argstr = '-1blur_fwhm %d', - units = 'mm') - other = traits.Str(desc = 'other options', - argstr = '%s') + infile = File(desc = 'input file to 3dvolreg', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + outfile = File(desc = 'output file from 3dvolreg', + argstr = '-prefix %s', + position = -2, + mandatory = True) + doall = traits.Bool(desc = 'apply options to all sub-bricks in dataset', + argstr = '-doall') + blurfwhm = traits.Int(desc = 'FWHM blur value (mm)', + argstr = '-1blur_fwhm %d', + units = 'mm') + other = traits.Str(desc = 'other options', + argstr = '%s') class ThreedmergeOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'smoothed file', - exists = True) + out_file = File(desc = 'smoothed file', + exists = True) class Threedmerge(AFNICommand): - """Merge or edit volumes using AFNI 3dmerge command. +"""Merge or edit volumes using AFNI 3dmerge command. + +For complete details, see the `3dmerge Documentation. +`_ +""" + + _cmd = '3dmerge' + input_spec = ThreedmergeInputSpec + output_spec = ThreedmergeOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.outfile + return outputs + + +class ThreedcopyInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dcopy', + argstr = '%s', + position = -2, + mandatory = True, + exists = True) + out_file = File(desc = 'output file from 3dcopy', + argstr = '%s', + position = -1, + genfile = True) + +class ThreedcopyOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'copied file') + +class Threedcopy(AFNICommandGenFile): +"""Copies an image of one type to an image of the same or different type +using 3dcopy command.""" + + _cmd = '3dcopy' + input_spec = ThreedcopyInputSpec + output_spec = ThreedcopyOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self._gen_outfilename() + return outputs + + def _gen_outfilename(self): + out_file = self.inputs.out_file + if not isdefined(out_file) and isdefined(self.inputs.in_file): + out_file = self._gen_fname(self.inputs.in_file, suffix="_copy") + return out_file + + + +class ThreedFourierInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dFourier', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + out_file = File(desc = 'output file from 3dFourier', + argstr = '-prefix %s', + position = -2, + genfile = True) + lowpass = traits.Float(desc = 'lowpass', + argstr = '-lowpass %f', + position = 0, + mandatory = True) + highpass = traits.Float(desc = 'highpass', + argstr = '-highpass %f', + position = 1, + mandatory = True) + other = traits.Str(desc = 'other options', + argstr = '%s') + +class ThreedFourierOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'band-pass filtered file', + exists = True) + +class ThreedFourier(AFNICommand): +"""Merge or edit volumes using AFNI 3dmerge command. + +For complete details, see the `3dmerge Documentation. +`_ +""" - For complete details, see the `3dmerge Documentation. - `_ - """ + _cmd = '3dFourier' + input_spec = ThreedFourierInputSpec + output_spec = ThreedFourierOutputSpec - _cmd = '3dmerge' - input_spec = ThreedmergeInputSpec - output_spec = ThreedmergeOutputSpec + def _gen_filename(self, name): + """Generate output file name + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dF',ext))) + def _list_outputs(self): + outputs = self.output_spec().get() + #outputs['out_file'] = os.path.abspath(self.inputs.out_file) - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + return outputs class ThreedZcutupInputSpec(AFNITraitedSpec): - infile = File(desc = 'input file to 3dZcutup', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - outfile = File(desc = 'output file from 3dZcutup', - argstr = '-prefix %s', - position = -2, - mandatory = True) - keep = traits.Str(desc = 'slice range to keep in output', - argstr = '-keep %s') - other = traits.Str(desc = 'other options', - argstr = '%s') + infile = File(desc = 'input file to 3dZcutup', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + outfile = File(desc = 'output file from 3dZcutup', + argstr = '-prefix %s', + position = -2, + mandatory = True) + keep = traits.Str(desc = 'slice range to keep in output', + argstr = '-keep %s') + other = traits.Str(desc = 'other options', + argstr = '%s') class ThreedZcutupOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'cut file', - exists = True) + out_file = File(desc = 'cut file', + exists = True) class ThreedZcutup(AFNICommand): - """Cut z-slices from a volume using AFNI 3dZcutup command. +"""Cut z-slices from a volume using AFNI 3dZcutup command. - For complete details, see the `3dZcutup Documentation. - `_ - """ +For complete details, see the `3dZcutup Documentation. +`_ +""" - _cmd = '3dZcutup' - input_spec = ThreedZcutupInputSpec - output_spec = ThreedZcutupOutputSpec + _cmd = '3dZcutup' + input_spec = ThreedZcutupInputSpec + output_spec = ThreedZcutupOutputSpec - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.outfile + return outputs class ThreedAllineateInputSpec(AFNITraitedSpec): - infile = File(desc = 'input file to 3dAllineate', - argstr = '-source %s', - position = -1, - mandatory = True, - exists = True) - outfile = File(desc = 'output file from 3dAllineate', - argstr = '-prefix %s', - position = -2, - mandatory = True) - matrix = File(desc = 'matrix to align input file', - argstr = '-1dmatrix_apply %s', - position = -3) + infile = File(desc = 'input file to 3dAllineate', + argstr = '-source %s', + position = -1, + mandatory = True, + exists = True) + outfile = File(desc = 'output file from 3dAllineate', + argstr = '-prefix %s', + position = -2, + mandatory = True) + matrix = File(desc = 'matrix to align input file', + argstr = '-1dmatrix_apply %s', + position = -3) class ThreedAllineateOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'cut file', - exists = True) + out_file = File(desc = 'cut file', + exists = True) class ThreedAllineate(AFNICommand): - """ - For complete details, see the `3dAllineate Documentation. - `_ - """ +""" +For complete details, see the `3dAllineate Documentation. +`_ +""" - _cmd = '3dAllineate' - input_spec = ThreedAllineateInputSpec - output_spec = ThreedAllineateOutputSpec + _cmd = '3dAllineate' + input_spec = ThreedAllineateInputSpec + output_spec = ThreedAllineateOutputSpec - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.outfile + return outputs -class ThreedSkullStrip(AFNICommand): - """ - For complete details, see the `3dSkullStrip Documentation. - `_ - """ +class ThreedMaskaveInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dmaskave', + argstr = '%s', + position = -2, + mandatory = True, + exists = True) + out_file = File(desc = 'output to the file', + argstr = '> %s', + position = -1, + genfile = True) + mask = File(desc = 'matrix to align input file', + argstr = '-mask %s', + position = 1) - @property - def cmd(self): - """Base command for ThreedSkullStrip""" - return '3dSkullStrip' + quiet = traits.Bool(desc = 'matrix to align input file', + argstr = '-quiet', + position = 2) - def inputs_help(self): - doc = """ - """ - print doc - def _populate_inputs(self): - """Initialize the inputs attribute.""" +class ThreedMaskaveOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'outfile', + exists = True) - self.inputs = Bunch(outfile=None, - infile=None) +class ThreedMaskave(AFNICommand): +""" +For complete details, see the `3dmaskave Documentation. +`_ +""" - def _parseinputs(self): - """Parse valid input options for ThreedSkullStrip command. + _cmd = '3dmaskave' + input_spec = ThreedMaskaveInputSpec + output_spec = ThreedMaskaveOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + if not isdefined(self.inputs.out_file): + out_file = self._gen_filename('out_file') + else: + out_file = os.path.abspath(self.inputs.out_file) + outputs['out_file'] = out_file + return outputs + + def _gen_filename(self, name): + """Generate output file name + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dm','.1D'))) + +class ThreedSkullStripInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dSkullStrip', + argstr = '-input %s', + position = 1, + mandatory = True, + exists = True) + out_file = File(desc = 'output to the file', + argstr = '%s', + position = -1, + genfile = True) + options = traits.Str(desc = 'options', argstr = '%s', position = 2) + + + +class ThreedSkullStripOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'outfile', + exists = True) + +class ThreedSkullStrip(AFNICommandGenFile): + + _cmd = '3dSkullStrip' + input_spec = ThreedSkullStripInputSpec + output_spec = ThreedSkullStripOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self._gen_outfilename() + return outputs + + def _gen_outfilename(self): + out_file = self.inputs.out_file + + if not isdefined(out_file) and isdefined(self.inputs.in_file): + out_file = self._gen_fname(self.inputs.in_file, suffix="_surf") + #out_file = self._gen_fname(self.inputs.in_file, suffix="_surf") + return out_file + + +class ThreedTcatInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dTcat', + argstr = ' %s', + position = -1, + mandatory = True, + exists = True) + out_file = File(desc = 'output to the file', + argstr = '-prefix %s', + position = -2, + genfile = True) + rlt = traits.Str(desc = 'options', argstr = '-rlt%s', position = 1) + + + +class ThreedTcatOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'outfile', + exists = True) + +class ThreedTcat(AFNICommand): +""" +For complete details, see the `3dTcat Documentation. +`_ +""" + + _cmd = '3dTcat' + input_spec = ThreedTcatInputSpec + output_spec = ThreedTcatOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + if not isdefined(self.inputs.out_file): + out_file = self._gen_filename('out_file') + else: + out_file = os.path.abspath(self.inputs.out_file) + + outputs['out_file'] = out_file + return outputs - Ignore options set to None. - """ + def _gen_filename(self, name): + """Generate output file name + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dT',ext))) - out_inputs = [] - inputs = {} - [inputs.update({k:v}) for k, v in self.inputs.items() \ - if v is not None] - if inputs.has_key('outfile'): - val = inputs.pop('outfile') - out_inputs.append('-prefix %s' % val) - if inputs.has_key('infile'): - val = inputs.pop('infile') - out_inputs.append('-input %s' % val) +class ThreedfimInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dfim+', + argstr = ' -input %s', + position = 1, + mandatory = True, + exists = True) + ideal_file = File(desc = 'output to the file', + argstr = '-ideal_file %s', + position = 2, + mandatory = True) + fim_thr = traits.Float(desc = 'fim internal mask threshold value', argstr = '-fim_thr %f', position = 3) - if len(inputs) > 0: - print '%s: unsupported options: %s' % ( - self.__class__.__name__, inputs.keys()) + out = traits.Str(desc = 'Flag to output the specified parameter', argstr = '-out %s', position = 4) - return out_inputs + out_file = File(desc = 'output file from 3dfim+', argstr = '-bucket %s', + position = -1, genfile=True) +class ThreedfimOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'outfile', + exists = True) + +class Threedfim(AFNICommand): +""" +For complete details, see the `3dfim+ Documentation. +`_ +""" + + _cmd = '3dfim+' + input_spec = ThreedfimInputSpec + output_spec = ThreedfimOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + + if not isdefined(self.inputs.out_file): + out_file = self._gen_filename('out_file') + else: + out_file = os.path.abspath(self.inputs.out_file) + + outputs['out_file'] = out_file + return outputs + + def _gen_filename(self, name): + """Generate output file name + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3df',ext))) + + + +class ThreedTcorrelateInputSpec(AFNITraitedSpec): + xset = File(desc = 'input xset', + argstr = ' %s', + position = -2, + mandatory = True, + exists = True) + yset = File(desc = 'input yset', + argstr = ' %s', + position = -1, + mandatory = True, + exists = True) + pearson = traits.Bool(desc = 'Correlation is the normal Pearson correlation coefficient', + argstr = '-pearson', + position = 1) + polort = traits.Int(desc = 'Remove polynomical trend of order m', argstr = '-polort %d', position = 2) + + out_file = File(desc = 'Save output into dataset with prefix ', argstr = '-prefix %s', + position = 3, genfile=True) + + options = traits.Str(desc = 'other options', + argstr = '%s', position = 4) + + +class ThreedTcorrelateOutputSpec(AFNITraitedSpec): + out_file = File(desc = 'outfile', + exists = True) + +class ThreedTcorrelate(AFNICommand): +""" +For complete details, see the `3dfim+ Documentation. +`_ +""" + + _cmd = '3dTcorrelate' + input_spec = ThreedTcorrelateInputSpec + output_spec = ThreedTcorrelateOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + if not isdefined(outputs['out_file']): + outputs['out_file'] = self._gen_filename('out_file') + return outputs + + def _gen_filename(self, name): + """Generate output file name + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.xset) + return os.path.join(os.getcwd(), ''.join((fname, '_3dTcor',ext))) + + + +class ThreedBrickStatInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dmaskave', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + + mask = File(desc = '-mask dset = use dset as mask to include/exclude voxels', + argstr = '-mask %s', + position = 2) + + min = traits.Bool(desc = 'print the minimum value in dataset', + argstr = '-min', + position = 1) + + +class ThreedBrickStatOutputSpec(AFNITraitedSpec): + min_val = traits.Float(desc = 'output') + class ThreedBrickStat(AFNICommand): - """ - For complete details, see the `3dBrickStat Documentation. - `_ - """ - - @property - def cmd(self): - """Base command for ThreedBrickStat""" - return '3dBrickStat' - - def inputs_help(self): - doc = """ - """ - print doc - - def _populate_inputs(self): - """Initialize the inputs attribute.""" - - self.inputs = Bunch(automask=None, - percentile=None, - infile=None) - - def _parseinputs(self): - """Parse valid input options for ThreedBrickStat command. - - Ignore options set to None. - - """ - - out_inputs = [] - inputs = {} - [inputs.update({k:v}) for k, v in self.inputs.items() \ - if v is not None] - - if inputs.has_key('automask'): - val = inputs.pop('automask') - out_inputs.append('-automask') - if inputs.has_key('percentile'): - val = inputs.pop('percentile') - inputssub = {} - [inputssub.update({k:v}) for k, v in val.items() \ - if v is not None] - - if inputssub.has_key('p0'): - valsub = inputssub.pop('p0') - out_inputs.append('-percentile %s' % str(valsub)) - else: - valsub=None - print('Warning: value \'p0\' required for percentile') - if inputssub.has_key('pstep'): - valsub = inputssub.pop('pstep') - out_inputs.append('%s' % str(valsub)) - else: - valsub=None - print('Warning: value \'pstep\' required for percentile') - if inputssub.has_key('p1'): - valsub = inputssub.pop('p1') - out_inputs.append('%s' % str(valsub)) - else: - valsub=None - print('Warning: value \'p1\' required for percentile') - - if inputs.has_key('infile'): - val = inputs.pop('infile') - out_inputs.append('%s' % val) - - if len(inputs) > 0: - print '%s: unsupported options: %s' % ( - self.__class__.__name__, inputs.keys()) - - return out_inputs - - -class Threedcalc(AFNICommand): - """ - For complete details, see the `3dcalc Documentation. - `_ - """ - - @property - def cmd(self): - """Base command for Threedcalc""" - return '3dcalc' - - def inputs_help(self): - doc = """ - """ - print doc - - def _populate_inputs(self): - """Initialize the inputs attribute.""" - - self.inputs = Bunch( - infile_a=None, - expr=None, - session=None, - datum=None, - outfile=None, - ) - - def _parseinputs(self): - """Parse valid input options for Threedcalc command. - - Ignore options set to None. - - """ - - out_inputs = [] - inputs = {} - [inputs.update({k:v}) for k, v in self.inputs.items() \ - if v is not None] - - if inputs.has_key('infile_a'): - val = inputs.pop('infile_a') - out_inputs.append('-a %s' % val) - if inputs.has_key('expr'): - val = inputs.pop('expr') - out_inputs.append('-expr %s' % val) - if inputs.has_key('session'): - val = inputs.pop('session') - out_inputs.append('-session %s' % val) - if inputs.has_key('datum'): - val = inputs.pop('datum') - out_inputs.append('-datum %s' % val) - if inputs.has_key('outfile'): - val = inputs.pop('outfile') - out_inputs.append('-prefix %s' % val) - - if len(inputs) > 0: - print '%s: unsupported options: %s' % ( - self.__class__.__name__, inputs.keys()) - - return out_inputs + _cmd = '3dBrickStat' + input_spec = ThreedBrickStatInputSpec + output_spec = ThreedBrickStatOutputSpec + + def aggregate_outputs(self,runtime = None, needed_outputs=None): + + outputs = self._outputs() + + outfile = os.path.join(os.getcwd(),'stat_result.json') + + if runtime is None: + try: + min_val = load_json(outfile)['stat'] + except IOError: + return self.run().outputs + else: + min_val = [] + for line in runtime.stdout.split('\n'): + if line: + values = line.split() + if len(values) > 1: + min_val.append([float(val) for val in values]) + else: + min_val.extend([float(val) for val in values]) + + if len(min_val) == 1: + min_val = min_val[0] + save_json(outfile,dict(stat=min_val)) + outputs.min_val = min_val + + return outputs + + + +class ThreedROIstatsInputSpec(AFNITraitedSpec): + in_file = File(desc = 'input file to 3dROIstats', + argstr = '%s', + position = -1, + mandatory = True, + exists = True) + + mask = File(desc = 'input mask', + argstr = '-mask %s', + position = 3) + + mask_f2short = traits.Bool(desc = 'Tells the program to convert a float mask to short integers, by simple rounding.', + argstr = '-mask_f2short', + position = 2) + + quiet = traits.Bool(desc = 'execute quietly', + argstr = '-quiet', + position = 1) + + +class ThreedROIstatsOutputSpec(AFNITraitedSpec): + stats = File(desc = 'output') + +class ThreedROIstats(AFNICommand): + _cmd = '3dROIstats' + input_spec = ThreedROIstatsInputSpec + output_spec = ThreedROIstatsOutputSpec + + def aggregate_outputs(self,runtime = None, needed_outputs=None): + + outputs = self._outputs() + + outfile = os.path.join(os.getcwd(),'stat_result.json') + + if runtime is None: + try: + stats = load_json(outfile)['stat'] + except IOError: + return self.run().outputs + else: + stats = [] + for line in runtime.stdout.split('\n'): + if line: + values = line.split() + if len(values) > 1: + stats.append([float(val) for val in values]) + else: + stats.extend([float(val) for val in values]) + + if len(stats) == 1: + stats = stats[0] + of = os.path.join(os.getcwd(),'TS.1D') + f = open(of,'w') + + for st in stats: + f.write(str(st) + '\n') + f.close() + save_json(outfile,dict(stat=of)) + outputs.stats =of + + 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 ThreedcalcInputSpec(CommandLineInputSpec): + infile_a = File(desc = 'input file to 3dcalc', + argstr = '-a %s', position = 0, mandatory = True) + infile_b = File(desc = 'operand file to 3dcalc', + argstr = ' -b %s', position = 1) + infile_b_prime = traits.Str(desc = 'operand file to 3dcalc', + argstr = ' -b %s', position = 1) + expr = traits.Str(desc = 'expr', argstr = '-expr %s', position = 2, + mandatory = True) + out_file = File(desc = 'output file from 3dFourier', argstr = '-prefix %s', + position = -1, genfile=True) + start_idx = traits.Int(desc='start index for infile_a', + requires=['stop_idx']) + stop_idx = traits.Int(desc='stop index for infile_a', + requires=['start_idx']) + single_idx = traits.Int(desc='volume index for infile_a') + other = File(desc = 'other options', argstr = '') + +class ThreedcalcOutputSpec(TraitedSpec): + out_file = File(desc = ' output file', exists = True) + +class Threedcalc(CommandLine): +"""Merge or edit volumes using AFNI 3dmerge command. + +For complete details, see the `3dcalc Documentation. +`_ +""" + _cmd = '3dcalc' + input_spec = ThreedcalcInputSpec + output_spec = ThreedcalcOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + + return outputs + + def _format_arg(self, name, trait_spec, value): + if name == 'infile_a': + arg = trait_spec.argstr%value + if isdefined(self.inputs.start_idx): + arg += '[%d..%d]'%(self.inputs.start_idx, self.inputs.stop_idx) + if isdefined(self.inputs.single_idx): + arg += '[%d]'%(self.inputs.single_idx) + return arg + return super(Threedcalc, self)._format_arg(name, trait_spec, value) + + def _parse_inputs(self, skip=None): + """Skip the arguments without argstr metadata + """ + return super(Threedcalc, self)._parse_inputs(skip=('start_idx','stop_idx','other')) + + def _gen_filename(self, name): + """Generate output file name + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.infile_a) + return os.path.join(os.getcwd(), ''.join((fname, '_3dc',ext))) From 845ff3d5ee88e42770f6752d8525231dd7180385 Mon Sep 17 00:00:00 2001 From: ssikka Date: Mon, 27 Feb 2012 15:41:29 -0500 Subject: [PATCH 2/6] BF - pep8 compatible formatting --- nipype/interfaces/afni/preprocess.py | 2252 +++++++++++++------------- 1 file changed, 1128 insertions(+), 1124 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 93d97b7cf9..a660485933 100755 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -1,3 +1,5 @@ +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- +# vi: set ft = python sts = 4 ts = 4 sw = 4 et: __docformat__ = 'restructuredtext' import warnings import os @@ -8,108 +10,55 @@ from nipype.interfaces.matlab import MatlabCommand from nipype.interfaces.base import BaseInterface, BaseInterfaceInputSpec from nipype.interfaces.afni.base import AFNITraitedSpec, AFNICommand, Info -from nipype.interfaces.base import Bunch, TraitedSpec, File, Directory, traits, isdefined -from nipype.interfaces.base import (CommandLineInputSpec, CommandLine, TraitedSpec, traits, isdefined, File) -from nipype.utils.filemanip import load_json, save_json, split_filename, fname_presuffix +from nipype.interfaces.base import Bunch, TraitedSpec, +File, Directory, traits, isdefined +from nipype.interfaces.base import (CommandLineInputSpec, +CommandLine, TraitedSpec, traits, isdefined, File) +from nipype.utils.filemanip import load_json, save_json, +split_filename, fname_presuffix warn = warnings.warn warnings.filterwarnings('always', category=UserWarning) -class AFNICommandGenFile(AFNICommand): - def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True, ext=None): -"""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 '') -change_ext : bool -Flag to change the filename extension to the AFNI 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() - - if ext is None: - ext = Info.outputtype_to_ext(self.inputs.outputtype) - - if change_ext: - if suffix: - suffix = ''.join((suffix, ext)) - else: - suffix = ext - - if suffix is None: - suffix = '' - - fname = fname_presuffix(basename, suffix = suffix, - use_ext = False, newpath = cwd) - - return fname - - def _gen_filename(self, name): - if name == 'out_file': - return self._gen_outfilename() - return None - - class To3dInputSpec(AFNITraitedSpec): - infolder = Directory(desc = 'folder with DICOM images to convert', - argstr = '%s/*.dcm', - position = -1, - mandatory = True, - exists = True) - - outfile = File(desc = 'converted image file', - argstr = '-prefix %s', - position = -2, - mandatory = True) + infolder = Directory(desc='folder with DICOM images to convert', + argstr='%s/*.dcm', + position=-1, + mandatory=True, + exists=True) - filetype = traits.Enum('spgr', 'fse', 'epan', 'anat', 'ct', 'spct','pet', 'mra', 'bmap', 'diff', - 'omri', 'abuc','fim', 'fith', 'fico', 'fitt', 'fift','fizt', 'fict', 'fibt', - 'fibn','figt','fipt','fbuc', argstr = '-%s', desc='type of datafile being converted') + outfile = File(desc='converted image file', + argstr='-prefix %s', + position=-2, + mandatory=True) - '''use xor''' - skipoutliers = traits.Bool(desc = 'skip the outliers check', - argstr = '-skip_outliers') + filetype = traits.Enum('spgr', 'fse', 'epan', 'anat', 'ct', 'spct', + 'pet', 'mra', 'bmap', 'diff', + 'omri', 'abuc', 'fim', 'fith', 'fico', 'fitt', 'fift', + 'fizt', 'fict', 'fibt', + 'fibn', 'figt', 'fipt', + 'fbuc', argstr='-%s', desc='type of datafile being converted') - assumemosaic = traits.Bool(desc = 'assume that Siemens image is mosaic', - argstr = '-assume_dicom_mosaic') - + skipoutliers = traits.Bool(desc='skip the outliers check', + argstr='-skip_outliers') - datatype = traits.Enum('short', 'float', 'byte', 'complex', desc = 'set output file datatype', - argstr = '-datum %s') + assumemosaic = traits.Bool(desc='assume that Siemens image is mosaic', + argstr='-assume_dicom_mosaic') - funcparams = traits.Str(desc = 'parameters for functional data', - argstr = '-time:zt %s alt+z2') + datatype = traits.Enum('short', 'float', 'byte', 'complex', + desc='set output file datatype', argstr='-datum %s') + + funcparams = traits.Str(desc='parameters for functional data', + argstr='-time:zt %s alt+z2') class To3dOutputSpec(TraitedSpec): - out_file = File(desc = 'converted file', - exists = True) + out_file = File(desc='converted file', + exists=True) + class To3d(AFNICommand): -"""Create a 3D dataset from 2D image files using AFNI to3d command. + """Create a 3D dataset from 2D image files using AFNI to3d command. For complete details, see the `to3d Documentation. `_ @@ -124,1107 +73,1156 @@ class To3d(AFNICommand): AFNI has no environment variable that sets filetype Nipype uses NIFTI_GZ as default >>> to3d.inputs.datatype = 'float' ->>> to3d.inputs.infolder='dicomdir' ->>> to3d.inputs.filetype="anat" +>>> to3d.inputs.infolder = 'dicomdir' +>>> to3d.inputs.filetype = "anat" >>> res = to3d.run() #doctest: +SKIP -""" + """ + + _cmd = 'to3d' + input_spec = To3dInputSpec + output_spec = To3dOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.outfile + return outputs + + +class TshiftInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dTShift', + argstr='%s', + position=-1, + mandatory=True, + exists=True) + out_file = File(desc='output file from 3dTshift', + argstr='-prefix %s', + position=0, + genfile=True) - _cmd = 'to3d' - input_spec = To3dInputSpec - output_spec = To3dOutputSpec - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs - - -class ThreedTshiftInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dTShift', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - out_file = File(desc = 'output file from 3dTshift', - argstr = '-prefix %s', - position = 0, - genfile = True) - - tr = traits.Str(desc = 'manually set the TR instead of looking in the header. ' + - 'You can attach suffix "s" for seconds or "ms" for milliseconds.', - argstr = '-TR %s') - - tzero = traits.Float(desc = 'align each slice to given time offset', - argstr = '-tzero %s', - xor = ['tslice']) - - tslice = traits.Int(desc = 'align each slice to time offset of given slice', - argstr = '-slice %s', - xor = ['tzero']) - - ignore = traits.Int(desc = 'ignore the first set of points specified', - argstr = '-ignore %s') - - interp = traits.Enum(('Fourier', 'linear', 'cubic', 'quintic', 'heptic'), - desc='different interpolation methods (see 3dTShift for details)' + - ' default=Fourier', argstr='-%s') - - tpattern = traits.Enum(('alt+z', 'alt+z2', 'alt-z', 'alt-z2', 'seq+z', 'seq-z'), - desc='use specified slice time pattern rather than one in header', - argstr='-tpattern %s') - - rlt = traits.Bool(desc='Before shifting, remove the mean and linear trend', - argstr="-rlt") - - rltplus = traits.Bool(desc='Before shifting, remove the mean and linear trend and ' + - 'later put back the mean', - argstr="-rlt+") - - suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value - - -class ThreedTshiftOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'post slice time shifted 4D image') - - -class ThreedTshift(AFNICommand): -"""Shifts voxel time series from input so that seperate slices are aligned to the same + tr = traits.Str(desc='manually set the TR' + + 'You can attach suffix "s" for seconds or "ms" for milliseconds.', + argstr='-TR %s') + + tzero = traits.Float(desc='align each slice to given time offset', + argstr='-tzero %s', + xor=['tslice']) + + tslice = traits.Int(desc='align each slice to time offset of given slice', + argstr='-slice %s', + xor=['tzero']) + + ignore = traits.Int(desc='ignore the first set of points specified', + argstr='-ignore %s') + + interp = traits.Enum(('Fourier', 'linear', 'cubic', 'quintic', 'heptic'), + desc='different interpolation methods (see 3dTShift for details)' + + ' default = Fourier', argstr='-%s') + + tpattern = traits.Enum(('alt+z', 'alt+z2', 'alt-z', + 'alt-z2', 'seq+z', 'seq-z'), + desc='use specified slice time pattern rather than one in header', + argstr='-tpattern %s') + + rlt = traits.Bool(desc='Before shifting, remove the mean and linear trend', + argstr="-rlt") + + rltplus = traits.Bool(desc='Before shifting,' + + ' remove the mean and linear trend and ' + + 'later put back the mean', + argstr="-rlt+") + + suffix = traits.Str(desc="out_file suffix") + # todo: give it a default-value + + +class TshiftOutputSpec(AFNITraitedSpec): + out_file = File(desc='post slice time shifted 4D image') + + +class Tshift(AFNICommand): + """Shifts voxel time series from input +so that seperate slices are aligned to the same temporal origin. For complete details, see the `3dTshift Documentation. `_ -""" - - _cmd = '3dTshift' - input_spec = ThreedTshiftInputSpec - output_spec = ThreedTshiftOutputSpec - - def _gen_filename(self, name): - if name == 'out_file': - return self._list_outputs()[name] - return None - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(outputs['out_file']): - - if isdefined(self.inputs.suffix): - suffix = self.inputs.suffix - else: - suffix = "_tshift" - outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix) - return outputs - - -class ThreedrefitInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3drefit', - argstr = '%s', - position = -1, - mandatory = True, - exists = True, - copyfile = True) - - deoblique = traits.Bool(desc = 'replace current transformation matrix with cardinal matrix', - argstr = '-deoblique') - - xorigin = traits.Str(desc = 'x distance for edge voxel offset', - argstr = '-xorigin %s') - - yorigin = traits.Str(desc = 'y distance for edge voxel offset', - argstr = '-yorigin %s') - zorigin = traits.Str(desc = 'z distance for edge voxel offset', - argstr = '-zorigin %s') - -class ThreedrefitOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'Same file as original infile with modified matrix', - exists = True) - -class Threedrefit(AFNICommand): -""" Use 3drefit for altering header info. + """ + + _cmd = '3dTshift' + input_spec = TshiftInputSpec + output_spec = TshiftOutputSpec + + def _gen_filename(self, name): + if name == 'out_file': + return self._list_outputs()[name] + return None + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.out_file + if not isdefined(outputs['out_file']): + + if isdefined(self.inputs.suffix): + suffix = self.inputs.suffix + else: + suffix = "_tshift" + outputs['out_file'] = self._gen_fname(self.inputs.in_file, + suffix=suffix) + return outputs + + +class refitInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3drefit', + argstr='%s', + position=-1, + mandatory=True, + exists=True, + copyfile=True) + + deoblique = traits.Bool(desc='replace current transformation' + + ' matrix with cardinal matrix', + argstr='-deoblique') + + xorigin = traits.Str(desc='x distance for edge voxel offset', + argstr='-xorigin %s') + + yorigin = traits.Str(desc='y distance for edge voxel offset', + argstr='-yorigin %s') + zorigin = traits.Str(desc='z distance for edge voxel offset', + argstr='-zorigin %s') + + +class refitOutputSpec(AFNITraitedSpec): + out_file = File(desc='Same file as original infile with modified matrix', + exists=True) + + +class refit(AFNICommand): + """ Use 3drefit for altering header info. NOTES ----- The original file is returned but it is CHANGED -""" - - _cmd = '3drefit' - input_spec = ThreedrefitInputSpec - output_spec = ThreedrefitOutputSpec - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.in_file - return outputs - - -class ThreedWarpInputSpec(AFNITraitedSpec): - - in_file = File(desc = 'input file to 3dWarp', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - - out_file = File(desc = 'output file from 3dWarp', - argstr = '-prefix %s', - position = 0, - genfile = True) - - tta2mni = traits.Bool(desc = 'transform dataset from Talairach to MNI152', - argstr = '-tta2mni') - - mni2tta = traits.Bool(desc = 'transform dataset from MNI152 to Talaraich', - argstr = '-mni2tta') - - matparent = File(desc = "apply transformation from 3dWarpDrive", - argstr = "-matparent %s", - exists = True) - - deoblique = traits.Bool(desc = 'transform dataset from oblique to cardinal', - argstr = '-deoblique') - - interp = traits.Enum(('linear', 'cubic', 'NN', 'quintic'), - desc='spatial interpolation methods [default=linear]', - argstr='-%s') - - gridset = File(desc = "copy grid of specified dataset", - argstr = "-gridset %s", - exists = True) - - zpad = traits.Int(desc="pad input dataset with N planes of zero on all sides.", - argstr="-zpad %s") - - suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value - -class ThreedWarpOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'spatially transformed input image', exists=True) - -class ThreedWarp(AFNICommand): -""" Use 3dWarp for spatially transforming a dataset + """ + + _cmd = '3drefit' + input_spec = refitInputSpec + output_spec = refitOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.in_file + return outputs + + +class WarpInputSpec(AFNITraitedSpec): + + in_file = File(desc='input file to 3dWarp', + argstr='%s', + position=-1, + mandatory=True, + exists=True) + + out_file = File(desc='output file from 3dWarp', + argstr='-prefix %s', + position=0, + genfile=True) + + tta2mni = traits.Bool(desc='transform dataset from Talairach to MNI152', + argstr='-tta2mni') + + mni2tta = traits.Bool(desc='transform dataset from MNI152 to Talaraich', + argstr='-mni2tta') + + matparent = File(desc="apply transformation from 3dWarpDrive", + argstr="-matparent %s", + exists=True) + + deoblique = traits.Bool(desc='transform dataset from oblique to cardinal', + argstr='-deoblique') + + interp = traits.Enum(('linear', 'cubic', 'NN', 'quintic'), + desc='spatial interpolation methods [default = linear]', + argstr='-%s') + + gridset = File(desc="copy grid of specified dataset", + argstr="-gridset %s", + exists=True) + + zpad = traits.Int(desc="pad input dataset with N planes" + + " of zero on all sides.", + argstr="-zpad %s") + + suffix = traits.Str(desc="out_file suffix") + # todo: give it a default-value + + +class WarpOutputSpec(AFNITraitedSpec): + out_file = File(desc='spatially transformed input image', exists=True) + + +class Warp(AFNICommand): + """ Use 3dWarp for spatially transforming a dataset For complete details, see the `3dTshift Documentation. `_ -""" - - _cmd = '3dWarp' - input_spec = ThreedWarpInputSpec - output_spec = ThreedWarpOutputSpec - - def _gen_filename(self, name): - if name == 'out_file': - return self._list_outputs()[name] - return None - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(outputs['out_file']): - if isdefined(self.inputs.suffix): - suffix = self.inputs.suffix - else: - suffix = "_warp" - outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix) - return outputs - - - -class ThreedresampleInputSpec(AFNITraitedSpec): - - in_file = File(desc = 'input file to 3dresample', - argstr = '-inset %s', - position = -1, - mandatory = True, - exists = True) - - out_file = File(desc = 'output file from 3dresample', - argstr = '-prefix %s', - position = -2, - genfile = True) - - orientation = traits.Str(desc = 'new orientation code', - argstr = '-orient %s') - - suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value - -class ThreedresampleOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'reoriented or resampled file', - exists = True) - -class Threedresample(AFNICommand): + """ + + _cmd = '3dWarp' + input_spec = WarpInputSpec + output_spec = WarpOutputSpec + + def _gen_filename(self, name): + if name == 'out_file': + return self._list_outputs()[name] + return None + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.out_file + if not isdefined(outputs['out_file']): + if isdefined(self.inputs.suffix): + suffix = self.inputs.suffix + else: + suffix = "_warp" + outputs['out_file'] = self._gen_fname( + self.inputs.in_file, suffix=suffix) + return outputs + + +class resampleInputSpec(AFNITraitedSpec): + + in_file = File(desc='input file to 3dresample', + argstr='-inset %s', + position=-1, + mandatory=True, + exists=True) + + out_file = File(desc='output file from 3dresample', + argstr='-prefix %s', + position=-2, + genfile=True) + + orientation = traits.Str(desc='new orientation code', + argstr='-orient %s') + + suffix = traits.Str(desc="out_file suffix") + # todo: give it a default-value + + +class resampleOutputSpec(AFNITraitedSpec): + out_file = File(desc='reoriented or resampled file', + exists=True) + + +class resample(AFNICommand): """Resample or reorient an image using AFNI 3dresample command. For complete details, see the `3dresample Documentation. `_ -""" - - _cmd = '3dresample' - input_spec = ThreedresampleInputSpec - output_spec = ThreedresampleOutputSpec - - def _gen_filename(self, name): - if name == 'out_file': - return self._list_outputs()[name] - return None - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(outputs['out_file']): - if isdefined(self.inputs.suffix): - suffix = self.inputs.suffix - else: - suffix = [] # allow for resampling command later! - if self.inputs.orientation: - suffix.append("_RPI") - suffix = "".join(suffix) - outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix) - return outputs - - -class ThreedTstatInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dTstat', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - - out_file = File(desc = 'output file from 3dTstat', - argstr = '-prefix %s', - position = -2, - genfile = True) - - options = traits.Str(desc = 'selected statistical output', - argstr = '%s') - -class ThreedTstatOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'statistical file', - exists = True) - -class ThreedTstat(AFNICommand): -"""Compute voxel-wise statistics using AFNI 3dTstat command. + """ + + _cmd = '3dresample' + input_spec = resampleInputSpec + output_spec = resampleOutputSpec + + def _gen_filename(self, name): + if name == 'out_file': + return self._list_outputs()[name] + return None + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.out_file + if not isdefined(outputs['out_file']): + if isdefined(self.inputs.suffix): + suffix = self.inputs.suffix + else: + suffix = [] # allow for resampling command later! + if self.inputs.orientation: + suffix.append("_RPI") + suffix = "".join(suffix) + outputs['out_file'] = self._gen_fname( + self.inputs.in_file, suffix=suffix) + return outputs + + +class TstatInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dTstat', + argstr='%s', + position=-1, + mandatory=True, + exists=True) + + out_file = File(desc='output file from 3dTstat', + argstr='-prefix %s', + position=-2, + genfile=True) + + options = traits.Str(desc='selected statistical output', + argstr='%s') + + +class TstatOutputSpec(AFNITraitedSpec): + out_file = File(desc='statistical file', + exists=True) + + +class Tstat(AFNICommand): + """Compute voxel-wise statistics using AFNI 3dTstat command. For complete details, see the `3dTstat Documentation. `_ -""" + """ + + _cmd = '3dTstat' + input_spec = TstatInputSpec + output_spec = TstatOutputSpec + + def _gen_filename(self, name): + """Generate output file name + """ + + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dT', ext))) + + def _list_outputs(self): + outputs = self.output_spec().get() + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + return outputs + + +class DetrendInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dDetrend', + argstr='%s', + position=-1, + mandatory=True, + exists=True) + out_file = File(desc='output file from 3dTstat', + argstr='-prefix %s', + position=-2, + genfile=True) + options = traits.Str(desc='selected statistical output', + argstr='%s') + + +class DetrendOutputSpec(AFNITraitedSpec): + out_file = File(desc='statistical file', + exists=True) - _cmd = '3dTstat' - input_spec = ThreedTstatInputSpec - output_spec = ThreedTstatOutputSpec - - def _gen_filename(self, name): - """Generate output file name - """ - - if name == 'out_file': - _, fname, ext = split_filename(self.inputs.in_file) - return os.path.join(os.getcwd(), ''.join((fname, '_3dT',ext))) - - - def _list_outputs(self): - outputs = self.output_spec().get() - #outputs['out_file'] = os.path.abspath(self.inputs.out_file) - if not isdefined(self.inputs.out_file): - outputs['out_file'] = self._gen_filename('out_file') - else: - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs - - -class ThreedDetrendInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dDetrend', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - out_file = File(desc = 'output file from 3dTstat', - argstr = '-prefix %s', - position = -2, - genfile = True) - options = traits.Str(desc = 'selected statistical output', - argstr = '%s') - -class ThreedDetrendOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'statistical file', - exists = True) - -class ThreedDetrend(AFNICommand): -"""Compute voxel-wise statistics using AFNI 3dTstat command. + +class Detrend(AFNICommand): + """Compute voxel-wise statistics using AFNI 3dTstat command. For complete details, see the `3dTstat Documentation. `_ -""" + """ - _cmd = '3dDetrend' - input_spec = ThreedDetrendInputSpec - output_spec = ThreedDetrendOutputSpec + _cmd = '3dDetrend' + input_spec = DetrendInputSpec + output_spec = DetrendOutputSpec - - def _gen_filename(self, name): + def _gen_filename(self, name): """Generate output file name - """ - - if name == 'out_file': - _, fname, ext = split_filename(self.inputs.in_file) - return os.path.join(os.getcwd(), ''.join((fname, '_3dD',ext))) - - - def _list_outputs(self): - outputs = self.output_spec().get() - #outputs['out_file'] = os.path.abspath(self.inputs.out_file) - - if not isdefined(self.inputs.out_file): - outputs['out_file'] = self._gen_filename('out_file') - else: - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs - - -class ThreedDespikeInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dDespike', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - - out_file = File(desc = 'output file from 3dDespike', - argstr = '-prefix %s', - position = -2, - genfile = True) - - options = traits.Str(desc = 'additional args', - argstr = '%s') - -class ThreedDespikeOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'despiked img', - exists = True) - -class ThreedDespike(AFNICommand): -"""Compute voxel-wise statistics using AFNI 3dTstat command. + """ + + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dD', ext))) + + def _list_outputs(self): + outputs = self.output_spec().get() + + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + return outputs + + +class DespikeInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dDespike', + argstr='%s', + position=-1, + mandatory=True, + exists=True) + + out_file = File(desc='output file from 3dDespike', + argstr='-prefix %s', + position=-2, + genfile=True) + + options = traits.Str(desc='additional args', + argstr='%s') + + +class DespikeOutputSpec(AFNITraitedSpec): + out_file = File(desc='despiked img', + exists=True) + + +class Despike(AFNICommand): + """Compute voxel-wise statistics using AFNI 3dTstat command. For complete details, see the `3dDespike Documentation. `_ -""" + """ - _cmd = '3dDespike' - input_spec = ThreedDespikeInputSpec - output_spec = ThreedDespikeOutputSpec + _cmd = '3dDespike' + input_spec = DespikeInputSpec + output_spec = DespikeOutputSpec - def _gen_filename(self, name): + def _gen_filename(self, name): """Generate output file name - """ - if name == 'out_file': - _, fname, ext = split_filename(self.inputs.in_file) - return os.path.join(os.getcwd(), ''.join((fname, '_3dDe',ext))) - - def _list_outputs(self): - outputs = self.output_spec().get() - #outputs['out_file'] = os.path.abspath(self.inputs.out_file) - - if not isdefined(self.inputs.out_file): - outputs['out_file'] = self._gen_filename('out_file') - else: - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs - -class ThreedAutomaskInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dAutomask', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - - out_file = File(desc = 'output file from 3dAutomask (a brain mask)', - argstr = '-prefix %s', - position = -2, - genfile = True) - - apply_mask = File(desc = "output file from 3dAutomask (masked version of input dataset)", - argstr = '-apply_prefix %s') - - clfrac = traits.Float(desc = 'sets the clip level fraction (must be 0.1-0.9). ' + - 'A small value will tend to make the mask larger [default=0.5].', - argstr = "-dilate %s") - - dilate = traits.Int(desc = 'dilate the mask outwards', - argstr = "-dilate %s") - - erode = traits.Int(desc = 'erode the mask inwards', - argstr = "-erode %s") - - options = traits.Str(desc = 'automask settings', - argstr = '%s') - - suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value - -class ThreedAutomaskOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'mask file', - exists = True) - - brain_file = File(desc = 'brain file (skull stripped)', - exists = True) - -class ThreedAutomask(AFNICommand): -"""Create a brain-only mask of the image using AFNI 3dAutomask command. + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dDe', ext))) + + def _list_outputs(self): + outputs = self.output_spec().get() + #outputs['out_file'] = os.path.abspath(self.inputs.out_file) + + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + return outputs + + +class AutomaskInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dAutomask', + argstr='%s', + position=-1, + mandatory=True, + exists=True) + + out_file = File(desc='output file from 3dAutomask (a brain mask)', + argstr='-prefix %s', + position=-2, + genfile=True) + + apply_mask = File(desc="output file from 3dAutomask", + argstr='-apply_prefix %s') + + clfrac = traits.Float(desc='sets the clip level fraction' + + ' (must be 0.1-0.9). ' + + 'A small value will tend to make the mask larger [default = 0.5].', + argstr="-dilate %s") + + dilate = traits.Int(desc='dilate the mask outwards', + argstr="-dilate %s") + + erode = traits.Int(desc='erode the mask inwards', + argstr="-erode %s") + + options = traits.Str(desc='automask settings', + argstr='%s') + + suffix = traits.Str(desc="out_file suffix") + # todo: give it a default-value + + +class AutomaskOutputSpec(AFNITraitedSpec): + out_file = File(desc='mask file', + exists=True) + + brain_file = File(desc='brain file (skull stripped)', + exists=True) + + +class Automask(AFNICommand): + """Create a brain-only mask of the image using AFNI 3dAutomask command. For complete details, see the `3dAutomask Documentation. `_ -""" - - _cmd = '3dAutomask' - input_spec = ThreedAutomaskInputSpec - output_spec = ThreedAutomaskOutputSpec - - def _gen_filename(self, name): - if name == 'out_file': - return self._list_outputs()[name] - return None - - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['brain_file'] = self.inputs.apply_mask - outputs['out_file'] = self.inputs.out_file - - if not isdefined(outputs['out_file']): - if isdefined(self.inputs.suffix): - suffix = self.inputs.suffix - else: - suffix = "_automask" - - outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix) - return outputs - - -class ThreedvolregInputSpec(AFNITraitedSpec): - - in_file = File(desc = 'input file to 3dvolreg', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - out_file = File(desc = 'output file from 3dvolreg', - argstr = '-prefix %s', - position = -2, - genfile = True) - basefile = File(desc = 'base file for registration', - argstr = '-base %s', - position = -6) - zpad = File(desc = 'Zeropad around the edges by \'n\' voxels during rotations', - argstr = '-zpad %s', - position = -5) - md1dfile = File(desc = 'max displacement output file', - argstr = '-maxdisp1D %s', - position = -4) - oned_file = File(desc = '1D movement parameters output file', - argstr = '-1Dfile %s', - position = -3, - genfile = True) - verbose = traits.Bool(desc = 'more detailed description of the process', - argstr = '-verbose') - timeshift = traits.Bool(desc = 'time shift to mean slice time offset', - argstr = '-tshift 0') - copyorigin = traits.Bool(desc = 'copy base file origin coords to output', - argstr = '-twodup') - other = traits.Str(desc = 'other options', - argstr = '%s') - -class ThreedvolregOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'registered file', - exists = True) - md1d_file = File(desc = 'max displacement info file') - oned_file = File(desc = 'movement parameters info file') - -class Threedvolreg(AFNICommand): -"""Register input volumes to a base volume using AFNI 3dvolreg command. + """ + + _cmd = '3dAutomask' + input_spec = AutomaskInputSpec + output_spec = AutomaskOutputSpec + + def _gen_filename(self, name): + if name == 'out_file': + return self._list_outputs()[name] + return None + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['brain_file'] = self.inputs.apply_mask + outputs['out_file'] = self.inputs.out_file + + if not isdefined(outputs['out_file']): + if isdefined(self.inputs.suffix): + suffix = self.inputs.suffix + else: + suffix = "_automask" + + outputs['out_file'] = self._gen_fname(self.inputs.in_file, + suffix=suffix) + return outputs + + +class volregInputSpec(AFNITraitedSpec): + + in_file = File(desc='input file to 3dvolreg', + argstr='%s', + position=-1, + mandatory=True, + exists=True) + out_file = File(desc='output file from 3dvolreg', + argstr='-prefix %s', + position=-2, + genfile=True) + basefile = File(desc='base file for registration', + argstr='-base %s', + position=-6) + zpad = File(desc='Zeropad around the edges' + + ' by \'n\' voxels during rotations', + argstr='-zpad %s', + position=-5) + md1dfile = File(desc='max displacement output file', + argstr='-maxdisp1D %s', + position=-4) + oned_file = File(desc='1D movement parameters output file', + argstr='-1Dfile %s', + position=-3, + genfile=True) + verbose = traits.Bool(desc='more detailed description of the process', + argstr='-verbose') + timeshift = traits.Bool(desc='time shift to mean slice time offset', + argstr='-tshift 0') + copyorigin = traits.Bool(desc='copy base file origin coords to output', + argstr='-twodup') + other = traits.Str(desc='other options', + argstr='%s') + + +class volregOutputSpec(AFNITraitedSpec): + out_file = File(desc='registered file', + exists=True) + md1d_file = File(desc='max displacement info file') + oned_file = File(desc='movement parameters info file') + + +class volreg(AFNICommand): + """Register input volumes to a base volume using AFNI 3dvolreg command. For complete details, see the `3dvolreg Documentation. `_ -""" + """ - _cmd = '3dvolreg' - input_spec = ThreedvolregInputSpec - output_spec = ThreedvolregOutputSpec + _cmd = '3dvolreg' + input_spec = volregInputSpec + output_spec = volregOutputSpec - def _gen_filename(self, name): + def _gen_filename(self, name): """Generate output file name - """ - if name == 'out_file': - _, fname, ext = split_filename(self.inputs.in_file) - return os.path.join(os.getcwd(), ''.join((fname, '_3dv',ext))) - - - if name == 'oned_file': - _, fname, ext = split_filename(self.inputs.in_file) - return os.path.join(os.getcwd(), ''.join((fname, '_3dv1D','.1D'))) - - - def _list_outputs(self): - outputs = self.output_spec().get() -# outputs['out_file'] = os.path.abspath(self.inputs.out_file) -# outputs['oned_file'] = os.path.abspath(self.inputs.oned_file) - - if not isdefined(self.inputs.out_file): - outputs['out_file'] = self._gen_filename('out_file') - else: - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - - - if not isdefined(self.inputs.oned_file): - outputs['oned_file'] = self._gen_filename('oned_file') - else: - outputs['oned_file'] = os.path.abspath(self.inputs.oned_file) - - return outputs - - -class ThreedmergeInputSpec(AFNITraitedSpec): - infile = File(desc = 'input file to 3dvolreg', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - outfile = File(desc = 'output file from 3dvolreg', - argstr = '-prefix %s', - position = -2, - mandatory = True) - doall = traits.Bool(desc = 'apply options to all sub-bricks in dataset', - argstr = '-doall') - blurfwhm = traits.Int(desc = 'FWHM blur value (mm)', - argstr = '-1blur_fwhm %d', - units = 'mm') - other = traits.Str(desc = 'other options', - argstr = '%s') - -class ThreedmergeOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'smoothed file', - exists = True) - -class Threedmerge(AFNICommand): -"""Merge or edit volumes using AFNI 3dmerge command. + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dv', ext))) + + if name == 'oned_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dv1D', '.1D'))) + + def _list_outputs(self): + outputs = self.output_spec().get() + + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + + if not isdefined(self.inputs.oned_file): + outputs['oned_file'] = self._gen_filename('oned_file') + else: + outputs['oned_file'] = os.path.abspath(self.inputs.oned_file) + + return outputs + + +class mergeInputSpec(AFNITraitedSpec): + infile = File(desc='input file to 3dvolreg', + argstr='%s', + position=-1, + mandatory=True, + exists=True) + outfile = File(desc='output file from 3dvolreg', + argstr='-prefix %s', + position=-2, + mandatory=True) + doall = traits.Bool(desc='apply options to all sub-bricks in dataset', + argstr='-doall') + blurfwhm = traits.Int(desc='FWHM blur value (mm)', + argstr='-1blur_fwhm %d', + units='mm') + other = traits.Str(desc='other options', + argstr='%s') + + +class mergeOutputSpec(AFNITraitedSpec): + out_file = File(desc='smoothed file', + exists=True) + + +class merge(AFNICommand): + """Merge or edit volumes using AFNI 3dmerge command. For complete details, see the `3dmerge Documentation. `_ -""" + """ + + _cmd = '3dmerge' + input_spec = mergeInputSpec + output_spec = mergeOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.outfile + return outputs + + +class copyInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dcopy', + argstr='%s', + position=-2, + mandatory=True, + exists=True) + out_file = File(desc='output file from 3dcopy', + argstr='%s', + position=-1, + genfile=True) + + +class copyOutputSpec(AFNITraitedSpec): + out_file = File(desc='copied file') + - _cmd = '3dmerge' - input_spec = ThreedmergeInputSpec - output_spec = ThreedmergeOutputSpec - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs - - -class ThreedcopyInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dcopy', - argstr = '%s', - position = -2, - mandatory = True, - exists = True) - out_file = File(desc = 'output file from 3dcopy', - argstr = '%s', - position = -1, - genfile = True) - -class ThreedcopyOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'copied file') - -class Threedcopy(AFNICommandGenFile): -"""Copies an image of one type to an image of the same or different type -using 3dcopy command.""" - - _cmd = '3dcopy' - input_spec = ThreedcopyInputSpec - output_spec = ThreedcopyOutputSpec - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self._gen_outfilename() - return outputs - - def _gen_outfilename(self): - out_file = self.inputs.out_file - if not isdefined(out_file) and isdefined(self.inputs.in_file): - out_file = self._gen_fname(self.inputs.in_file, suffix="_copy") - return out_file - - - -class ThreedFourierInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dFourier', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - out_file = File(desc = 'output file from 3dFourier', - argstr = '-prefix %s', - position = -2, - genfile = True) - lowpass = traits.Float(desc = 'lowpass', - argstr = '-lowpass %f', - position = 0, - mandatory = True) - highpass = traits.Float(desc = 'highpass', - argstr = '-highpass %f', - position = 1, - mandatory = True) - other = traits.Str(desc = 'other options', - argstr = '%s') - -class ThreedFourierOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'band-pass filtered file', - exists = True) - -class ThreedFourier(AFNICommand): -"""Merge or edit volumes using AFNI 3dmerge command. +class copy(AFNICommand): + """Copies an image of one type to an image of the same +or different type +using 3dcopy command. + """ + + _cmd = '3dcopy' + input_spec = copyInputSpec + output_spec = copyOutputSpec + + def _gen_filename(self, name): + """Generate output file name + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_copy', ext))) + + def _list_outputs(self): + outputs = self.output_spec().get() + + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + return outputs + + +class FourierInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dFourier', + argstr='%s', + position=-1, + mandatory=True, + exists=True) + out_file = File(desc='output file from 3dFourier', + argstr='-prefix %s', + position=-2, + genfile=True) + lowpass = traits.Float(desc='lowpass', + argstr='-lowpass %f', + position=0, + mandatory=True) + highpass = traits.Float(desc='highpass', + argstr='-highpass %f', + position=1, + mandatory=True) + other = traits.Str(desc='other options', + argstr='%s') + + +class FourierOutputSpec(AFNITraitedSpec): + out_file = File(desc='band-pass filtered file', + exists=True) + + +class Fourier(AFNICommand): + """Merge or edit volumes using AFNI 3dmerge command. For complete details, see the `3dmerge Documentation. `_ -""" + """ - _cmd = '3dFourier' - input_spec = ThreedFourierInputSpec - output_spec = ThreedFourierOutputSpec + _cmd = '3dFourier' + input_spec = FourierInputSpec + output_spec = FourierOutputSpec - def _gen_filename(self, name): + def _gen_filename(self, name): """Generate output file name - """ - if name == 'out_file': - _, fname, ext = split_filename(self.inputs.in_file) - return os.path.join(os.getcwd(), ''.join((fname, '_3dF',ext))) - def _list_outputs(self): - outputs = self.output_spec().get() - #outputs['out_file'] = os.path.abspath(self.inputs.out_file) - - if not isdefined(self.inputs.out_file): - outputs['out_file'] = self._gen_filename('out_file') - else: - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs - - -class ThreedZcutupInputSpec(AFNITraitedSpec): - infile = File(desc = 'input file to 3dZcutup', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) - outfile = File(desc = 'output file from 3dZcutup', - argstr = '-prefix %s', - position = -2, - mandatory = True) - keep = traits.Str(desc = 'slice range to keep in output', - argstr = '-keep %s') - other = traits.Str(desc = 'other options', - argstr = '%s') - -class ThreedZcutupOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'cut file', - exists = True) - -class ThreedZcutup(AFNICommand): -"""Cut z-slices from a volume using AFNI 3dZcutup command. + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dF', ext))) + + def _list_outputs(self): + outputs = self.output_spec().get() + + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + return outputs + + +class ZcutupInputSpec(AFNITraitedSpec): + infile = File(desc='input file to 3dZcutup', + argstr='%s', + position=-1, + mandatory=True, + exists=True) + outfile = File(desc='output file from 3dZcutup', + argstr='-prefix %s', + position=-2, + mandatory=True) + keep = traits.Str(desc='slice range to keep in output', + argstr='-keep %s') + other = traits.Str(desc='other options', + argstr='%s') + + +class ZcutupOutputSpec(AFNITraitedSpec): + out_file = File(desc='cut file', + exists=True) + + +class Zcutup(AFNICommand): + """Cut z-slices from a volume using AFNI 3dZcutup command. For complete details, see the `3dZcutup Documentation. `_ -""" + """ - _cmd = '3dZcutup' - input_spec = ThreedZcutupInputSpec - output_spec = ThreedZcutupOutputSpec - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs - - -class ThreedAllineateInputSpec(AFNITraitedSpec): - infile = File(desc = 'input file to 3dAllineate', - argstr = '-source %s', - position = -1, - mandatory = True, - exists = True) - outfile = File(desc = 'output file from 3dAllineate', - argstr = '-prefix %s', - position = -2, - mandatory = True) - matrix = File(desc = 'matrix to align input file', - argstr = '-1dmatrix_apply %s', - position = -3) - -class ThreedAllineateOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'cut file', - exists = True) - -class ThreedAllineate(AFNICommand): -""" + _cmd = '3dZcutup' + input_spec = ZcutupInputSpec + output_spec = ZcutupOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.outfile + return outputs + + +class AllineateInputSpec(AFNITraitedSpec): + infile = File(desc='input file to 3dAllineate', + argstr='-source %s', + position=-1, + mandatory=True, + exists=True) + outfile = File(desc='output file from 3dAllineate', + argstr='-prefix %s', + position=-2, + mandatory=True) + matrix = File(desc='matrix to align input file', + argstr='-1dmatrix_apply %s', + position=-3) + + +class AllineateOutputSpec(AFNITraitedSpec): + out_file = File(desc='cut file', + exists=True) + + +class Allineate(AFNICommand): + """ For complete details, see the `3dAllineate Documentation. `_ -""" + """ - _cmd = '3dAllineate' - input_spec = ThreedAllineateInputSpec - output_spec = ThreedAllineateOutputSpec + _cmd = '3dAllineate' + input_spec = AllineateInputSpec + output_spec = AllineateOutputSpec - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.outfile - return outputs + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = self.inputs.outfile + return outputs -class ThreedMaskaveInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dmaskave', - argstr = '%s', - position = -2, - mandatory = True, - exists = True) - out_file = File(desc = 'output to the file', - argstr = '> %s', - position = -1, - genfile = True) - mask = File(desc = 'matrix to align input file', - argstr = '-mask %s', - position = 1) +class MaskaveInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dmaskave', + argstr='%s', + position=-2, + mandatory=True, + exists=True) + out_file = File(desc='output to the file', + argstr='> %s', + position=-1, + genfile=True) + mask = File(desc='matrix to align input file', + argstr='-mask %s', + position=1) - quiet = traits.Bool(desc = 'matrix to align input file', - argstr = '-quiet', - position = 2) + quiet = traits.Bool(desc='matrix to align input file', + argstr='-quiet', + position=2) -class ThreedMaskaveOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'outfile', - exists = True) +class MaskaveOutputSpec(AFNITraitedSpec): + out_file = File(desc='outfile', + exists=True) -class ThreedMaskave(AFNICommand): -""" + +class Maskave(AFNICommand): + """ For complete details, see the `3dmaskave Documentation. `_ -""" + """ + + _cmd = '3dmaskave' + input_spec = MaskaveInputSpec + output_spec = MaskaveOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + if not isdefined(self.inputs.out_file): + out_file = self._gen_filename('out_file') + else: + out_file = os.path.abspath(self.inputs.out_file) + outputs['out_file'] = out_file + return outputs + + def _gen_filename(self, name): + """Generate output file name + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dm', '.1D'))) - _cmd = '3dmaskave' - input_spec = ThreedMaskaveInputSpec - output_spec = ThreedMaskaveOutputSpec - def _list_outputs(self): - outputs = self.output_spec().get() - if not isdefined(self.inputs.out_file): - out_file = self._gen_filename('out_file') - else: - out_file = os.path.abspath(self.inputs.out_file) - outputs['out_file'] = out_file - return outputs +class SkullStripInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dSkullStrip', + argstr='-input %s', + position=1, + mandatory=True, + exists=True) + out_file = File(desc='output to the file', + argstr='%s', + position=-1, + genfile=True) + options = traits.Str(desc='options', argstr='%s', position=2) - def _gen_filename(self, name): - """Generate output file name - """ - if name == 'out_file': - _, fname, ext = split_filename(self.inputs.in_file) - return os.path.join(os.getcwd(), ''.join((fname, '_3dm','.1D'))) - -class ThreedSkullStripInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dSkullStrip', - argstr = '-input %s', - position = 1, - mandatory = True, - exists = True) - out_file = File(desc = 'output to the file', - argstr = '%s', - position = -1, - genfile = True) - options = traits.Str(desc = 'options', argstr = '%s', position = 2) - - - -class ThreedSkullStripOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'outfile', - exists = True) - -class ThreedSkullStrip(AFNICommandGenFile): - - _cmd = '3dSkullStrip' - input_spec = ThreedSkullStripInputSpec - output_spec = ThreedSkullStripOutputSpec - - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = self._gen_outfilename() - return outputs - - def _gen_outfilename(self): - out_file = self.inputs.out_file - - if not isdefined(out_file) and isdefined(self.inputs.in_file): - out_file = self._gen_fname(self.inputs.in_file, suffix="_surf") - #out_file = self._gen_fname(self.inputs.in_file, suffix="_surf") - return out_file - - -class ThreedTcatInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dTcat', - argstr = ' %s', - position = -1, - mandatory = True, - exists = True) - out_file = File(desc = 'output to the file', - argstr = '-prefix %s', - position = -2, - genfile = True) - rlt = traits.Str(desc = 'options', argstr = '-rlt%s', position = 1) - - - -class ThreedTcatOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'outfile', - exists = True) - -class ThreedTcat(AFNICommand): -""" -For complete details, see the `3dTcat Documentation. -`_ -""" - _cmd = '3dTcat' - input_spec = ThreedTcatInputSpec - output_spec = ThreedTcatOutputSpec +class SkullStripOutputSpec(AFNITraitedSpec): + out_file = File(desc='outfile', + exists=True) + - def _list_outputs(self): - outputs = self.output_spec().get() - if not isdefined(self.inputs.out_file): - out_file = self._gen_filename('out_file') - else: - out_file = os.path.abspath(self.inputs.out_file) - - outputs['out_file'] = out_file - return outputs +class SkullStrip(AFNICommand): + _cmd = '3dSkullStrip' + input_spec = SkullStripInputSpec + output_spec = SkullStripOutputSpec - def _gen_filename(self, name): + def _list_outputs(self): + outputs = self.output_spec().get() + if not isdefined(self.inputs.out_file): + out_file = self._gen_filename('out_file') + else: + out_file = os.path.abspath(self.inputs.out_file) + + outputs['out_file'] = out_file + return outputs + + def _gen_filename(self, name): """Generate output file name - """ - if name == 'out_file': - _, fname, ext = split_filename(self.inputs.in_file) - return os.path.join(os.getcwd(), ''.join((fname, '_3dT',ext))) + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dT', ext))) -class ThreedfimInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dfim+', - argstr = ' -input %s', - position = 1, - mandatory = True, - exists = True) - ideal_file = File(desc = 'output to the file', - argstr = '-ideal_file %s', - position = 2, - mandatory = True) - fim_thr = traits.Float(desc = 'fim internal mask threshold value', argstr = '-fim_thr %f', position = 3) +class TcatInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dTcat', + argstr=' %s', + position=-1, + mandatory=True, + exists=True) + out_file = File(desc='output to the file', + argstr='-prefix %s', + position=-2, + genfile=True) + rlt = traits.Str(desc='options', argstr='-rlt%s', position=1) - out = traits.Str(desc = 'Flag to output the specified parameter', argstr = '-out %s', position = 4) - out_file = File(desc = 'output file from 3dfim+', argstr = '-bucket %s', - position = -1, genfile=True) +class TcatOutputSpec(AFNITraitedSpec): + out_file = File(desc='outfile', + exists=True) -class ThreedfimOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'outfile', - exists = True) +class Tcat(AFNICommand): + """ +For complete details, see the `3dTcat Documentation. +`_ + """ -class Threedfim(AFNICommand): -""" -For complete details, see the `3dfim+ Documentation. -`_ -""" + _cmd = '3dTcat' + input_spec = TcatInputSpec + output_spec = TcatOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + if not isdefined(self.inputs.out_file): + out_file = self._gen_filename('out_file') + else: + out_file = os.path.abspath(self.inputs.out_file) - _cmd = '3dfim+' - input_spec = ThreedfimInputSpec - output_spec = ThreedfimOutputSpec - - def _list_outputs(self): - outputs = self.output_spec().get() - - if not isdefined(self.inputs.out_file): - out_file = self._gen_filename('out_file') - else: - out_file = os.path.abspath(self.inputs.out_file) - - outputs['out_file'] = out_file - return outputs - - def _gen_filename(self, name): + outputs['out_file'] = out_file + return outputs + + def _gen_filename(self, name): """Generate output file name - """ - if name == 'out_file': - _, fname, ext = split_filename(self.inputs.in_file) - return os.path.join(os.getcwd(), ''.join((fname, '_3df',ext))) + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dT', ext))) +class fimInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dfim+', + argstr=' -input %s', + position=1, + mandatory=True, + exists=True) + ideal_file = File(desc='output to the file', + argstr='-ideal_file %s', + position=2, + mandatory=True) + fim_thr = traits.Float(desc='fim internal mask threshold value', + argstr='-fim_thr %f', position=3) -class ThreedTcorrelateInputSpec(AFNITraitedSpec): - xset = File(desc = 'input xset', - argstr = ' %s', - position = -2, - mandatory = True, - exists = True) - yset = File(desc = 'input yset', - argstr = ' %s', - position = -1, - mandatory = True, - exists = True) - pearson = traits.Bool(desc = 'Correlation is the normal Pearson correlation coefficient', - argstr = '-pearson', - position = 1) - polort = traits.Int(desc = 'Remove polynomical trend of order m', argstr = '-polort %d', position = 2) + out = traits.Str(desc='Flag to output the specified parameter', + argstr='-out %s', position=4) - out_file = File(desc = 'Save output into dataset with prefix ', argstr = '-prefix %s', - position = 3, genfile=True) + out_file = File(desc='output file from 3dfim+', argstr='-bucket %s', + position=-1, genfile=True) - options = traits.Str(desc = 'other options', - argstr = '%s', position = 4) +class fimOutputSpec(AFNITraitedSpec): + out_file = File(desc='outfile', + exists=True) -class ThreedTcorrelateOutputSpec(AFNITraitedSpec): - out_file = File(desc = 'outfile', - exists = True) -class ThreedTcorrelate(AFNICommand): -""" +class fim(AFNICommand): + """ For complete details, see the `3dfim+ Documentation. `_ -""" + """ + + _cmd = '3dfim+' + input_spec = fimInputSpec + output_spec = fimOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + + if not isdefined(self.inputs.out_file): + out_file = self._gen_filename('out_file') + else: + out_file = os.path.abspath(self.inputs.out_file) - _cmd = '3dTcorrelate' - input_spec = ThreedTcorrelateInputSpec - output_spec = ThreedTcorrelateOutputSpec + outputs['out_file'] = out_file + return outputs - def _list_outputs(self): - outputs = self.output_spec().get() - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - if not isdefined(outputs['out_file']): - outputs['out_file'] = self._gen_filename('out_file') - return outputs + def _gen_filename(self, name): + """Generate output file name + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3df', ext))) + + +class TcorrelateInputSpec(AFNITraitedSpec): + xset = File(desc='input xset', + argstr=' %s', + position=-2, + mandatory=True, + exists=True) + yset = File(desc='input yset', + argstr=' %s', + position=-1, + mandatory=True, + exists=True) + pearson = traits.Bool(desc='Correlation is the normal' + + ' Pearson correlation coefficient', + argstr='-pearson', + position=1) + polort = traits.Int(desc='Remove polynomical trend of order m', + argstr='-polort %d', position=2) + + out_file = File(desc='Save output into dataset with prefix ', + argstr='-prefix %s', + position=3, genfile=True) + + options = traits.Str(desc='other options', + argstr='%s', position=4) + + +class TcorrelateOutputSpec(AFNITraitedSpec): + out_file = File(desc='outfile', + exists=True) + + +class Tcorrelate(AFNICommand): + """ +For complete details, see the `3dfim+ Documentation. +`_ + """ - def _gen_filename(self, name): - """Generate output file name - """ + _cmd = '3dTcorrelate' + input_spec = TcorrelateInputSpec + output_spec = TcorrelateOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + if not isdefined(outputs['out_file']): + outputs['out_file'] = self._gen_filename('out_file') + return outputs + + def _gen_filename(self, name): + """Generate output file name + """ if name == 'out_file': _, fname, ext = split_filename(self.inputs.xset) - return os.path.join(os.getcwd(), ''.join((fname, '_3dTcor',ext))) + return os.path.join(os.getcwd(), ''.join((fname, '_3dTcor', ext))) +class BrickStatInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dmaskave', + argstr='%s', + position=-1, + mandatory=True, + exists=True) -class ThreedBrickStatInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dmaskave', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) + mask = File(desc='-mask dset = use dset as mask to include/exclude voxels', + argstr='-mask %s', + position=2) - mask = File(desc = '-mask dset = use dset as mask to include/exclude voxels', - argstr = '-mask %s', - position = 2) + min = traits.Bool(desc='print the minimum value in dataset', + argstr='-min', + position=1) - min = traits.Bool(desc = 'print the minimum value in dataset', - argstr = '-min', - position = 1) - - -class ThreedBrickStatOutputSpec(AFNITraitedSpec): - min_val = traits.Float(desc = 'output') -class ThreedBrickStat(AFNICommand): - _cmd = '3dBrickStat' - input_spec = ThreedBrickStatInputSpec - output_spec = ThreedBrickStatOutputSpec +class BrickStatOutputSpec(AFNITraitedSpec): + min_val = traits.Float(desc='output') - def aggregate_outputs(self,runtime = None, needed_outputs=None): - outputs = self._outputs() +class BrickStat(AFNICommand): + _cmd = '3dBrickStat' + input_spec = BrickStatInputSpec + output_spec = BrickStatOutputSpec - outfile = os.path.join(os.getcwd(),'stat_result.json') + def aggregate_outputs(self, runtime=None, needed_outputs=None): - if runtime is None: - try: - min_val = load_json(outfile)['stat'] - except IOError: - return self.run().outputs - else: - min_val = [] - for line in runtime.stdout.split('\n'): - if line: - values = line.split() - if len(values) > 1: - min_val.append([float(val) for val in values]) - else: - min_val.extend([float(val) for val in values]) + outputs = self._outputs() - if len(min_val) == 1: - min_val = min_val[0] - save_json(outfile,dict(stat=min_val)) - outputs.min_val = min_val - - return outputs + outfile = os.path.join(os.getcwd(), 'stat_result.json') + if runtime is None: + try: + min_val = load_json(outfile)['stat'] + except IOError: + return self.run().outputs + else: + min_val = [] + for line in runtime.stdout.split('\n'): + if line: + values = line.split() + if len(values) > 1: + min_val.append([float(val) for val in values]) + else: + min_val.extend([float(val) for val in values]) + if len(min_val) == 1: + min_val = min_val[0] + save_json(outfile, dict(stat=min_val)) + outputs.min_val = min_val -class ThreedROIstatsInputSpec(AFNITraitedSpec): - in_file = File(desc = 'input file to 3dROIstats', - argstr = '%s', - position = -1, - mandatory = True, - exists = True) + return outputs - mask = File(desc = 'input mask', - argstr = '-mask %s', - position = 3) - mask_f2short = traits.Bool(desc = 'Tells the program to convert a float mask to short integers, by simple rounding.', - argstr = '-mask_f2short', - position = 2) +class ROIstatsInputSpec(AFNITraitedSpec): + in_file = File(desc='input file to 3dROIstats', + argstr='%s', + position=-1, + mandatory=True, + exists=True) - quiet = traits.Bool(desc = 'execute quietly', - argstr = '-quiet', - position = 1) + mask = File(desc='input mask', + argstr='-mask %s', + position=3) + mask_f2short = traits.Bool( + desc='Tells the program to convert a float mask ' + + 'to short integers, by simple rounding.', + argstr='-mask_f2short', + position=2) -class ThreedROIstatsOutputSpec(AFNITraitedSpec): - stats = File(desc = 'output') + quiet = traits.Bool(desc='execute quietly', + argstr='-quiet', + position=1) -class ThreedROIstats(AFNICommand): - _cmd = '3dROIstats' - input_spec = ThreedROIstatsInputSpec - output_spec = ThreedROIstatsOutputSpec - def aggregate_outputs(self,runtime = None, needed_outputs=None): +class ROIstatsOutputSpec(AFNITraitedSpec): + stats = File(desc='output') - outputs = self._outputs() - outfile = os.path.join(os.getcwd(),'stat_result.json') +class ROIstats(AFNICommand): + _cmd = '3dROIstats' + input_spec = ROIstatsInputSpec + output_spec = ROIstatsOutputSpec - if runtime is None: - try: - stats = load_json(outfile)['stat'] - except IOError: - return self.run().outputs - else: - stats = [] - for line in runtime.stdout.split('\n'): - if line: - values = line.split() - if len(values) > 1: - stats.append([float(val) for val in values]) - else: - stats.extend([float(val) for val in values]) - - if len(stats) == 1: - stats = stats[0] - of = os.path.join(os.getcwd(),'TS.1D') - f = open(of,'w') - - for st in stats: - f.write(str(st) + '\n') - f.close() - save_json(outfile,dict(stat=of)) - outputs.stats =of - - return outputs + def aggregate_outputs(self, runtime=None, needed_outputs=None): + + outputs = self._outputs() + + outfile = os.path.join(os.getcwd(), 'stat_result.json') + + if runtime is None: + try: + stats = load_json(outfile)['stat'] + except IOError: + return self.run().outputs + else: + stats = [] + for line in runtime.stdout.split('\n'): + if line: + values = line.split() + if len(values) > 1: + stats.append([float(val) for val in values]) + else: + stats.extend([float(val) for val in values]) + + if len(stats) == 1: + stats = stats[0] + of = os.path.join(os.getcwd(), 'TS.1D') + f = open(of, 'w') + + for st in stats: + f.write(str(st) + '\n') + f.close() + save_json(outfile, dict(stat=of)) + outputs.stats = of + + return outputs """ @@ -1235,65 +1233,71 @@ def aggregate_outputs(self,runtime = None, needed_outputs=None): ${rest}_ss.nii.gz """ -class ThreedcalcInputSpec(CommandLineInputSpec): - infile_a = File(desc = 'input file to 3dcalc', - argstr = '-a %s', position = 0, mandatory = True) - infile_b = File(desc = 'operand file to 3dcalc', - argstr = ' -b %s', position = 1) - infile_b_prime = traits.Str(desc = 'operand file to 3dcalc', - argstr = ' -b %s', position = 1) - expr = traits.Str(desc = 'expr', argstr = '-expr %s', position = 2, - mandatory = True) - out_file = File(desc = 'output file from 3dFourier', argstr = '-prefix %s', - position = -1, genfile=True) - start_idx = traits.Int(desc='start index for infile_a', - requires=['stop_idx']) - stop_idx = traits.Int(desc='stop index for infile_a', - requires=['start_idx']) - single_idx = traits.Int(desc='volume index for infile_a') - other = File(desc = 'other options', argstr = '') - -class ThreedcalcOutputSpec(TraitedSpec): - out_file = File(desc = ' output file', exists = True) - -class Threedcalc(CommandLine): -"""Merge or edit volumes using AFNI 3dmerge command. + +class calcInputSpec(CommandLineInputSpec): + infile_a = File(desc='input file to 3dcalc', + argstr='-a %s', position=0, mandatory=True) + infile_b = File(desc='operand file to 3dcalc', + argstr=' -b %s', position=1) + infile_b_prime = traits.Str(desc='operand file to 3dcalc', + argstr=' -b %s', position=1) + expr = traits.Str(desc='expr', argstr='-expr %s', position=2, + mandatory=True) + out_file = File(desc='output file from 3dFourier', argstr='-prefix %s', + position=-1, genfile=True) + start_idx = traits.Int(desc='start index for infile_a', + requires=['stop_idx']) + stop_idx = traits.Int(desc='stop index for infile_a', + requires=['start_idx']) + single_idx = traits.Int(desc='volume index for infile_a') + other = File(desc='other options', argstr='') + + +class calcOutputSpec(TraitedSpec): + out_file = File(desc=' output file', exists=True) + + +class calc(CommandLine): + """Merge or edit volumes using AFNI 3dmerge command. For complete details, see the `3dcalc Documentation. `_ -""" - - _cmd = '3dcalc' - input_spec = ThreedcalcInputSpec - output_spec = ThreedcalcOutputSpec - - def _list_outputs(self): - outputs = self.output_spec().get() - if not isdefined(self.inputs.out_file): - outputs['out_file'] = self._gen_filename('out_file') - else: - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - - return outputs - - def _format_arg(self, name, trait_spec, value): - if name == 'infile_a': - arg = trait_spec.argstr%value - if isdefined(self.inputs.start_idx): - arg += '[%d..%d]'%(self.inputs.start_idx, self.inputs.stop_idx) - if isdefined(self.inputs.single_idx): - arg += '[%d]'%(self.inputs.single_idx) - return arg - return super(Threedcalc, self)._format_arg(name, trait_spec, value) - - def _parse_inputs(self, skip=None): + """ + + _cmd = '3dcalc' + input_spec = calcInputSpec + output_spec = calcOutputSpec + + def _list_outputs(self): + outputs = self.output_spec().get() + if not isdefined(self.inputs.out_file): + outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) + + return outputs + + def _format_arg(self, name, trait_spec, value): + if name == 'infile_a': + arg = trait_spec.argstr % value + if isdefined(self.inputs.start_idx): + arg + = '[%d..%d]' % (self.inputs.start_idx, + self.inputs.stop_idx) + if isdefined(self.inputs.single_idx): + arg + = '[%d]' % (self.inputs.single_idx) + return arg + return super(calc, self)._format_arg(name, trait_spec, value) + + def _parse_inputs(self, skip=None): """Skip the arguments without argstr metadata - """ - return super(Threedcalc, self)._parse_inputs(skip=('start_idx','stop_idx','other')) + """ + return super(calc, self)._parse_inputs(skip=('start_idx', + 'stop_idx', 'other')) - def _gen_filename(self, name): + def _gen_filename(self, name): """Generate output file name - """ - if name == 'out_file': - _, fname, ext = split_filename(self.inputs.infile_a) - return os.path.join(os.getcwd(), ''.join((fname, '_3dc',ext))) + """ + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.infile_a) + return os.path.join(os.getcwd(), + ''.join((fname, '_3dc', ext))) From e7658573a6ee0d74f593b89f509726e8e1b6fc87 Mon Sep 17 00:00:00 2001 From: ssikka Date: Thu, 1 Mar 2012 03:57:57 -0500 Subject: [PATCH 3/6] BF fixed Naming, Added DocStrings --- nipype/interfaces/afni/__init__.py | 5 +- nipype/interfaces/afni/preprocess.py | 542 +++++++++++++++++++-------- 2 files changed, 386 insertions(+), 161 deletions(-) diff --git a/nipype/interfaces/afni/__init__.py b/nipype/interfaces/afni/__init__.py index 94117779ee..f6d962d761 100644 --- a/nipype/interfaces/afni/__init__.py +++ b/nipype/interfaces/afni/__init__.py @@ -13,4 +13,7 @@ from nipype.interfaces.afni.base import Info, AFNICommand, AFNITraitedSpec -from nipype.interfaces.afni.preprocess import (To3d, Threedrefit, Threedresample, ThreedTstat, ThreedAutomask, Threedvolreg, Threedmerge, ThreedZcutup) +from nipype.interfaces.afni.preprocess import (To3D, Refit, Resample, TStat, +Automask, Volreg, Merge, ZCutUp, Calc, TShift, Warp, +Detrend, Despike, Copy, Fourier, Allineate, Maskave, +SkullStrip, TCat, Fim, TCorrelate, BrickStat, ROIStats) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index a660485933..7ac4503f00 100755 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -10,17 +10,16 @@ from nipype.interfaces.matlab import MatlabCommand from nipype.interfaces.base import BaseInterface, BaseInterfaceInputSpec from nipype.interfaces.afni.base import AFNITraitedSpec, AFNICommand, Info -from nipype.interfaces.base import Bunch, TraitedSpec, -File, Directory, traits, isdefined +from nipype.interfaces.base import Bunch, Directory from nipype.interfaces.base import (CommandLineInputSpec, CommandLine, TraitedSpec, traits, isdefined, File) -from nipype.utils.filemanip import load_json, save_json, -split_filename, fname_presuffix +from nipype.utils.filemanip import (load_json, save_json, +split_filename, fname_presuffix) warn = warnings.warn warnings.filterwarnings('always', category=UserWarning) -class To3dInputSpec(AFNITraitedSpec): +class To3DInputSpec(AFNITraitedSpec): infolder = Directory(desc='folder with DICOM images to convert', argstr='%s/*.dcm', position=-1, @@ -52,12 +51,12 @@ class To3dInputSpec(AFNITraitedSpec): argstr='-time:zt %s alt+z2') -class To3dOutputSpec(TraitedSpec): +class To3DOutputSpec(TraitedSpec): out_file = File(desc='converted file', exists=True) -class To3d(AFNICommand): +class To3D(AFNICommand): """Create a 3D dataset from 2D image files using AFNI to3d command. For complete details, see the `to3d Documentation. @@ -69,19 +68,19 @@ class To3d(AFNICommand): Examples -------- >>> from nipype.interfaces import afni ->>> to3d = afni.To3d() +>>> To3D = afni.To3d() AFNI has no environment variable that sets filetype Nipype uses NIFTI_GZ as default ->>> to3d.inputs.datatype = 'float' ->>> to3d.inputs.infolder = 'dicomdir' ->>> to3d.inputs.filetype = "anat" ->>> res = to3d.run() #doctest: +SKIP +>>> To3D.inputs.datatype = 'float' +>>> To3D.inputs.infolder = 'dicomdir' +>>> To3D.inputs.filetype = "anat" +>>> res = To3D.run() #doctest: +SKIP """ _cmd = 'to3d' - input_spec = To3dInputSpec - output_spec = To3dOutputSpec + input_spec = To3DInputSpec + output_spec = To3DOutputSpec def _list_outputs(self): outputs = self.output_spec().get() @@ -89,7 +88,7 @@ def _list_outputs(self): return outputs -class TshiftInputSpec(AFNITraitedSpec): +class TShiftInputSpec(AFNITraitedSpec): in_file = File(desc='input file to 3dTShift', argstr='%s', position=-1, @@ -136,21 +135,32 @@ class TshiftInputSpec(AFNITraitedSpec): # todo: give it a default-value -class TshiftOutputSpec(AFNITraitedSpec): +class TShiftOutputSpec(AFNITraitedSpec): out_file = File(desc='post slice time shifted 4D image') -class Tshift(AFNICommand): - """Shifts voxel time series from input -so that seperate slices are aligned to the same -temporal origin. -For complete details, see the `3dTshift Documentation. -`_ +class TShift(AFNICommand): + """ + Shifts voxel time series from input + so that seperate slices are aligned to the same + temporal origin. + For complete details, see the `3dTshift Documentation. + + Examples + ________ + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> tshift = afni.TShift() + >>> tshift.inputs.in_file = example_data('functional.nii') + >>> tshift.inputs.out_file = 'functional_tshift.nii' + >>> tshift.inputs.tpattern = 'alt+z' + >>> tshift.inputs.tzero = 0.0 + >>> res = tshift.run() # doctest: +SKIP """ _cmd = '3dTshift' - input_spec = TshiftInputSpec - output_spec = TshiftOutputSpec + input_spec = TShiftInputSpec + output_spec = TShiftOutputSpec def _gen_filename(self, name): if name == 'out_file': @@ -171,7 +181,7 @@ def _list_outputs(self): return outputs -class refitInputSpec(AFNITraitedSpec): +class RefitInputSpec(AFNITraitedSpec): in_file = File(desc='input file to 3drefit', argstr='%s', position=-1, @@ -192,21 +202,33 @@ class refitInputSpec(AFNITraitedSpec): argstr='-zorigin %s') -class refitOutputSpec(AFNITraitedSpec): +class RefitOutputSpec(AFNITraitedSpec): out_file = File(desc='Same file as original infile with modified matrix', exists=True) -class refit(AFNICommand): - """ Use 3drefit for altering header info. -NOTES ------ -The original file is returned but it is CHANGED +class Refit(AFNICommand): + """ + Changes some of the information inside a 3D dataset's header + For complete details, see the `3drefit Documentation. + + NOTES + ----- + The original file is returned but it is CHANGED + + Examples + ________ + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> refit = afni.Refit() + >>> refit.inputs.in_file = example_data('structural.nii') + >>> refit.inputs.deoblique=True + >>> res = refit.run() # doctest: +SKIP """ _cmd = '3drefit' - input_spec = refitInputSpec - output_spec = refitOutputSpec + input_spec = RefitInputSpec + output_spec = RefitOutputSpec def _list_outputs(self): outputs = self.output_spec().get() @@ -261,9 +283,18 @@ class WarpOutputSpec(AFNITraitedSpec): class Warp(AFNICommand): - """ Use 3dWarp for spatially transforming a dataset -For complete details, see the `3dTshift Documentation. -`_ + """ + Use 3dWarp for spatially transforming a dataset + For complete details, see the `3dWarp Documentation. + `_ + Examples + ________ + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> warp = afni.Warp() + >>> warp.inputs.in_file = example_data('structural.nii') + >>> warp.inputs.deoblique = True + >>> res = warp.run() # doctest: +SKIP """ _cmd = '3dWarp' @@ -288,7 +319,7 @@ def _list_outputs(self): return outputs -class resampleInputSpec(AFNITraitedSpec): +class ResampleInputSpec(AFNITraitedSpec): in_file = File(desc='input file to 3dresample', argstr='-inset %s', @@ -308,20 +339,29 @@ class resampleInputSpec(AFNITraitedSpec): # todo: give it a default-value -class resampleOutputSpec(AFNITraitedSpec): +class ResampleOutputSpec(AFNITraitedSpec): out_file = File(desc='reoriented or resampled file', exists=True) -class resample(AFNICommand): - """Resample or reorient an image using AFNI 3dresample command. -For complete details, see the `3dresample Documentation. -`_ +class Resample(AFNICommand): + """ + Resample or reorient an image using AFNI 3dresample command. + For complete details, see the `3dresample Documentation. + `_ + Examples + ________ + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> resample = afni.Resample() + >>> resample.inputs.in_file = example_data('functional.nii') + >>> resample.inputs.orientation= 'RPI' + >>> res = resample.run() # doctest: +SKIP """ _cmd = '3dresample' - input_spec = resampleInputSpec - output_spec = resampleOutputSpec + input_spec = ResampleInputSpec + output_spec = ResampleOutputSpec def _gen_filename(self, name): if name == 'out_file': @@ -344,7 +384,7 @@ def _list_outputs(self): return outputs -class TstatInputSpec(AFNITraitedSpec): +class TStatInputSpec(AFNITraitedSpec): in_file = File(desc='input file to 3dTstat', argstr='%s', position=-1, @@ -360,21 +400,30 @@ class TstatInputSpec(AFNITraitedSpec): argstr='%s') -class TstatOutputSpec(AFNITraitedSpec): +class TStatOutputSpec(AFNITraitedSpec): out_file = File(desc='statistical file', exists=True) -class Tstat(AFNICommand): - """Compute voxel-wise statistics using AFNI 3dTstat command. - -For complete details, see the `3dTstat Documentation. -`_ +class TStat(AFNICommand): + """ + Compute voxel-wise statistics using AFNI 3dTstat command. + For complete details, see the `3dTstat Documentation. + `_ + + Examples + ________ + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> tstat = afni.TStat() + >>> tstat.inputs.in_file = example_data('functional.nii') + >>> tstat.inputs.options= '-mean' + >>> res = tstat.run() # doctest: +SKIP """ _cmd = '3dTstat' - input_spec = TstatInputSpec - output_spec = TstatOutputSpec + input_spec = TStatInputSpec + output_spec = TStatOutputSpec def _gen_filename(self, name): """Generate output file name @@ -413,10 +462,19 @@ class DetrendOutputSpec(AFNITraitedSpec): class Detrend(AFNICommand): - """Compute voxel-wise statistics using AFNI 3dTstat command. - -For complete details, see the `3dTstat Documentation. -`_ + """ + This program removes components from voxel time series using + linear least squares. Each voxel is treated independently. + For complete details, see the `3dTstat Documentation. + `_ + Examples + ________ + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> detrend = afni.Detrend() + >>> detrend.inputs.in_file = example_data('functional.nii') + >>> detrend.inputs.options = '-polort 2' + >>> res = detrend.run() # doctest: +SKIP """ _cmd = '3dDetrend' @@ -427,9 +485,9 @@ def _gen_filename(self, name): """Generate output file name """ - if name == 'out_file': - _, fname, ext = split_filename(self.inputs.in_file) - return os.path.join(os.getcwd(), ''.join((fname, '_3dD', ext))) + if name == 'out_file': + _, fname, ext = split_filename(self.inputs.in_file) + return os.path.join(os.getcwd(), ''.join((fname, '_3dD', ext))) def _list_outputs(self): outputs = self.output_spec().get() @@ -463,10 +521,21 @@ class DespikeOutputSpec(AFNITraitedSpec): class Despike(AFNICommand): - """Compute voxel-wise statistics using AFNI 3dTstat command. + """ + Removes 'spikes' from the 3D+time input dataset and writes + a new dataset with the spike values replaced by something + more pleasing to the eye. + For complete details, see the `3dDespike Documentation. + `_ + + Examples + ________ + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> despike = afni.Despike() + >>> despike.inputs.in_file = example_data('functional.nii') + >>> res = despike.run() # doctest: +SKIP -For complete details, see the `3dDespike Documentation. -`_ """ _cmd = '3dDespike' @@ -533,9 +602,18 @@ class AutomaskOutputSpec(AFNITraitedSpec): class Automask(AFNICommand): - """Create a brain-only mask of the image using AFNI 3dAutomask command. -For complete details, see the `3dAutomask Documentation. -`_ + """ + Create a brain-only mask of the image using AFNI 3dAutomask command. + For complete details, see the `3dAutomask Documentation. + `_ + Examples + ______________ + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> automask = afni.Automask() + >>> automask.inputs.in_file = example_data('functional.nii') + >>> automask.inputs.dilate = 1 + >>> res = automask.run() # doctest: +SKIP """ _cmd = '3dAutomask' @@ -558,12 +636,12 @@ def _list_outputs(self): else: suffix = "_automask" - outputs['out_file'] = self._gen_fname(self.inputs.in_file, - suffix=suffix) - return outputs + outputs['out_file'] = self._gen_fname(self.inputs.in_file, + suffix=suffix) + return outputs -class volregInputSpec(AFNITraitedSpec): +class VolregInputSpec(AFNITraitedSpec): in_file = File(desc='input file to 3dvolreg', argstr='%s', @@ -598,23 +676,32 @@ class volregInputSpec(AFNITraitedSpec): argstr='%s') -class volregOutputSpec(AFNITraitedSpec): +class VolregOutputSpec(AFNITraitedSpec): out_file = File(desc='registered file', exists=True) md1d_file = File(desc='max displacement info file') oned_file = File(desc='movement parameters info file') -class volreg(AFNICommand): - """Register input volumes to a base volume using AFNI 3dvolreg command. - -For complete details, see the `3dvolreg Documentation. -`_ +class Volreg(AFNICommand): + """ + Register input volumes to a base volume using AFNI 3dvolreg command. + For complete details, see the `3dvolreg Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> volreg = afni.Volreg() + >>> volreg.inputs.in_file = example_data('functional.nii') + >>> volreg.inputs.other = '-Fourier -twopass' + >>> volreg.inputs.zpad = '4' + >>> res = volreg.run() # doctest: +SKIP """ _cmd = '3dvolreg' - input_spec = volregInputSpec - output_spec = volregOutputSpec + input_spec = VolregInputSpec + output_spec = VolregOutputSpec def _gen_filename(self, name): """Generate output file name @@ -643,7 +730,7 @@ def _list_outputs(self): return outputs -class mergeInputSpec(AFNITraitedSpec): +class MergeInputSpec(AFNITraitedSpec): infile = File(desc='input file to 3dvolreg', argstr='%s', position=-1, @@ -662,21 +749,31 @@ class mergeInputSpec(AFNITraitedSpec): argstr='%s') -class mergeOutputSpec(AFNITraitedSpec): +class MergeOutputSpec(AFNITraitedSpec): out_file = File(desc='smoothed file', exists=True) -class merge(AFNICommand): - """Merge or edit volumes using AFNI 3dmerge command. - -For complete details, see the `3dmerge Documentation. -`_ +class Merge(AFNICommand): + """ + Merge or edit volumes using AFNI 3dmerge command. + For complete details, see the `3dmerge Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> merge = afni.Merge() + >>> merge.inputs.infile = example_data('functional.nii') + >>> merge.inputs.blurfwhm = 4.0 + >>> merge.inputs.doall = True + >>> merge.inputs.outfile = 'e7.nii' + >>> res = merge.run() # doctest: +SKIP """ _cmd = '3dmerge' - input_spec = mergeInputSpec - output_spec = mergeOutputSpec + input_spec = MergeInputSpec + output_spec = MergeOutputSpec def _list_outputs(self): outputs = self.output_spec().get() @@ -684,7 +781,7 @@ def _list_outputs(self): return outputs -class copyInputSpec(AFNITraitedSpec): +class CopyInputSpec(AFNITraitedSpec): in_file = File(desc='input file to 3dcopy', argstr='%s', position=-2, @@ -696,24 +793,32 @@ class copyInputSpec(AFNITraitedSpec): genfile=True) -class copyOutputSpec(AFNITraitedSpec): +class CopyOutputSpec(AFNITraitedSpec): out_file = File(desc='copied file') -class copy(AFNICommand): - """Copies an image of one type to an image of the same -or different type -using 3dcopy command. +class Copy(AFNICommand): + """ + Copies an image of one type to an image of the same + or different type using 3dcopy command. + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> copy = afni.Copy() + >>> copy.inputs.in_file = example_data('functional.nii') + >>> copy.inputs.out_file = 'new_func.nii' + >>> res = copy.run() # doctest: +SKIP """ _cmd = '3dcopy' - input_spec = copyInputSpec - output_spec = copyOutputSpec + input_spec = CopyInputSpec + output_spec = CopyOutputSpec def _gen_filename(self, name): """Generate output file name """ - if name == 'out_file': + if name == 'out_file': _, fname, ext = split_filename(self.inputs.in_file) return os.path.join(os.getcwd(), ''.join((fname, '_copy', ext))) @@ -755,10 +860,19 @@ class FourierOutputSpec(AFNITraitedSpec): class Fourier(AFNICommand): - """Merge or edit volumes using AFNI 3dmerge command. - -For complete details, see the `3dmerge Documentation. -`_ + """ + For complete details, see the `3dFourier Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> fourier = afni.Fourier() + >>> fourier.inputs.in_file = example_data('functional.nii') + >>> fourier.inputs.other = '-retrend' + >>> fourier.inputs.highpass = 0.005 + >>> fourier.inputs.lowpass = 0.1 + >>> res = fourier.run() # doctest: +SKIP """ _cmd = '3dFourier' @@ -768,7 +882,7 @@ class Fourier(AFNICommand): def _gen_filename(self, name): """Generate output file name """ - if name == 'out_file': + if name == 'out_file': _, fname, ext = split_filename(self.inputs.in_file) return os.path.join(os.getcwd(), ''.join((fname, '_3dF', ext))) @@ -782,7 +896,7 @@ def _list_outputs(self): return outputs -class ZcutupInputSpec(AFNITraitedSpec): +class ZCutUpInputSpec(AFNITraitedSpec): infile = File(desc='input file to 3dZcutup', argstr='%s', position=-1, @@ -798,21 +912,29 @@ class ZcutupInputSpec(AFNITraitedSpec): argstr='%s') -class ZcutupOutputSpec(AFNITraitedSpec): +class ZCutUpOutputSpec(AFNITraitedSpec): out_file = File(desc='cut file', exists=True) -class Zcutup(AFNICommand): +class ZCutUp(AFNICommand): """Cut z-slices from a volume using AFNI 3dZcutup command. - -For complete details, see the `3dZcutup Documentation. -`_ + For complete details, see the `3dZcutup Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> zcutup = afni.Zcutup() + >>> zcutup.inputs.infile = example_data('functional.nii') + >>> zcutup.inputs.outfile= 'functional_zcutup.nii' + >>> zcutup.inputs.keep= '0 10' + >>> res = zcutup.run() # doctest: +SKIP """ _cmd = '3dZcutup' - input_spec = ZcutupInputSpec - output_spec = ZcutupOutputSpec + input_spec = ZCutUpInputSpec + output_spec = ZCutUpOutputSpec def _list_outputs(self): outputs = self.output_spec().get() @@ -842,8 +964,17 @@ class AllineateOutputSpec(AFNITraitedSpec): class Allineate(AFNICommand): """ -For complete details, see the `3dAllineate Documentation. -`_ + For complete details, see the `3dAllineate Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> allineate = afni.Allineate() + >>> allineate.inputs.infile = example_data('functional.nii') + >>> allineate.inputs.outfile= 'functional_allineate.nii' + >>> allineate.inputs.matrix= example_data('cmatrix.mat') + >>> res = allineate.run() # doctest: +SKIP """ _cmd = '3dAllineate' @@ -882,8 +1013,18 @@ class MaskaveOutputSpec(AFNITraitedSpec): class Maskave(AFNICommand): """ -For complete details, see the `3dmaskave Documentation. -`_ + For complete details, see the `3dmaskave Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> maskave = afni.Maskave() + >>> maskave.inputs.in_file = example_data('functional.nii') + >>> maskave.inputs.mask= example_data('seed_mask.nii') + >>> maskave.inputs.quiet= True + >>> maskave.inputs.out_file= 'maskave.1D' + >>> res = maskave.run() # doctest: +SKIP """ _cmd = '3dmaskave' @@ -926,7 +1067,18 @@ class SkullStripOutputSpec(AFNITraitedSpec): class SkullStrip(AFNICommand): - + """ + For complete details, see the `3dSkullStrip Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> skullstrip = afni.Skullstrip() + >>> skullstrip.inputs.in_file = example_data('functional.nii') + >>> skullstrip.inputs.options = '-o_ply' + >>> res = skullstrip.run() # doctest: +SKIP + """ _cmd = '3dSkullStrip' input_spec = SkullStripInputSpec output_spec = SkullStripOutputSpec @@ -949,7 +1101,7 @@ def _gen_filename(self, name): return os.path.join(os.getcwd(), ''.join((fname, '_3dT', ext))) -class TcatInputSpec(AFNITraitedSpec): +class TCatInputSpec(AFNITraitedSpec): in_file = File(desc='input file to 3dTcat', argstr=' %s', position=-1, @@ -962,20 +1114,29 @@ class TcatInputSpec(AFNITraitedSpec): rlt = traits.Str(desc='options', argstr='-rlt%s', position=1) -class TcatOutputSpec(AFNITraitedSpec): +class TCatOutputSpec(AFNITraitedSpec): out_file = File(desc='outfile', exists=True) -class Tcat(AFNICommand): +class TCat(AFNICommand): """ -For complete details, see the `3dTcat Documentation. -`_ + For complete details, see the `3dTcat Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> tcat = afni.TCat() + >>> tcat.inputs.in_file = example_data('functional.nii') + >>> tcat.inputs.out_file= 'functional_tcat.nii' + >>> tcat.inputs.rlt = '+' + >>> res = tcat.run() # doctest: +SKIP """ _cmd = '3dTcat' - input_spec = TcatInputSpec - output_spec = TcatOutputSpec + input_spec = TCatInputSpec + output_spec = TCatOutputSpec def _list_outputs(self): outputs = self.output_spec().get() @@ -995,7 +1156,7 @@ def _gen_filename(self, name): return os.path.join(os.getcwd(), ''.join((fname, '_3dT', ext))) -class fimInputSpec(AFNITraitedSpec): +class FimInputSpec(AFNITraitedSpec): in_file = File(desc='input file to 3dfim+', argstr=' -input %s', position=1, @@ -1015,20 +1176,31 @@ class fimInputSpec(AFNITraitedSpec): position=-1, genfile=True) -class fimOutputSpec(AFNITraitedSpec): +class FimOutputSpec(AFNITraitedSpec): out_file = File(desc='outfile', exists=True) -class fim(AFNICommand): +class Fim(AFNICommand): """ -For complete details, see the `3dfim+ Documentation. -`_ + For complete details, see the `3dfim+ Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> fim = afni.Fim() + >>> fim.inputs.in_file = example_data('functional.nii') + >>> fim.inputs.ideal_file= example_data('seed.1D') + >>> fim.inputs.out_file = 'functional_corr.nii' + >>> fim.inputs.out = 'Correlation' + >>> fim.inputs.fim_thr = 0.0009 + >>> res = fim.run() # doctest: +SKIP """ _cmd = '3dfim+' - input_spec = fimInputSpec - output_spec = fimOutputSpec + input_spec = FimInputSpec + output_spec = FimOutputSpec def _list_outputs(self): outputs = self.output_spec().get() @@ -1049,7 +1221,7 @@ def _gen_filename(self, name): return os.path.join(os.getcwd(), ''.join((fname, '_3df', ext))) -class TcorrelateInputSpec(AFNITraitedSpec): +class TCorrelateInputSpec(AFNITraitedSpec): xset = File(desc='input xset', argstr=' %s', position=-2, @@ -1075,20 +1247,35 @@ class TcorrelateInputSpec(AFNITraitedSpec): argstr='%s', position=4) -class TcorrelateOutputSpec(AFNITraitedSpec): +class TCorrelateOutputSpec(AFNITraitedSpec): out_file = File(desc='outfile', exists=True) -class Tcorrelate(AFNICommand): +class TCorrelate(AFNICommand): """ -For complete details, see the `3dfim+ Documentation. -`_ + Computes the correlation coefficient between corresponding voxel + time series in two input 3D+time datasets 'xset' and 'yset', and + stores the output in a new 1 sub-brick dataset. + For complete details, see the `3dfim+ Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> tcorrelate = afni.TCorrelate() + >>> tcorrelate.inputs.in_file = example_data('functional.nii') + >>> tcorrelate.inputs.xset= example_data('u_rc1s1_Template.nii') + >>> tcorrelate.inputs.yset = example_data('u_rc1s2_Template.nii') + >>> tcorrelate.inputs.out_file = 'functional_tcorrelate.nii.gz' + >>> tcorrelate.inputs.polort = -1 + >>> tcorrelate.inputs.pearson = True + >>> res = tcarrelate.run() # doctest: +SKIP """ _cmd = '3dTcorrelate' - input_spec = TcorrelateInputSpec - output_spec = TcorrelateOutputSpec + input_spec = TCorrelateInputSpec + output_spec = TCorrelateOutputSpec def _list_outputs(self): outputs = self.output_spec().get() @@ -1126,6 +1313,19 @@ class BrickStatOutputSpec(AFNITraitedSpec): class BrickStat(AFNICommand): + """ + For complete details, see the `3dfim+ Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> brickstat = afni.BrickStat() + >>> brickstat.inputs.in_file = example_data('functional.nii') + >>> brickstat.inputs.mask = example_data('skeleton_mask.nii.gz') + >>> brickstat.inputs.min = True + >>> res = brickstat.run() # doctest: +SKIP + """ _cmd = '3dBrickStat' input_spec = BrickStatInputSpec output_spec = BrickStatOutputSpec @@ -1159,7 +1359,7 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None): return outputs -class ROIstatsInputSpec(AFNITraitedSpec): +class ROIStatsInputSpec(AFNITraitedSpec): in_file = File(desc='input file to 3dROIstats', argstr='%s', position=-1, @@ -1181,14 +1381,28 @@ class ROIstatsInputSpec(AFNITraitedSpec): position=1) -class ROIstatsOutputSpec(AFNITraitedSpec): +class ROIStatsOutputSpec(AFNITraitedSpec): stats = File(desc='output') -class ROIstats(AFNICommand): +class ROIStats(AFNICommand): + """ + Display statistics over masked regions. + For complete details, see the `3dROIstats Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> roistats = afni.ROIStats() + >>> roistats.inputs.in_file = example_data('functional.nii') + >>> roistats.inputs.mask = example_data('skeleton_mask.nii.gz') + >>> roistats.inputs.quiet=True + >>> res = roistats.run() # doctest: +SKIP + """ _cmd = '3dROIstats' - input_spec = ROIstatsInputSpec - output_spec = ROIstatsOutputSpec + input_spec = ROIStatsInputSpec + output_spec = ROIStatsOutputSpec def aggregate_outputs(self, runtime=None, needed_outputs=None): @@ -1234,7 +1448,7 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None): """ -class calcInputSpec(CommandLineInputSpec): +class CalcInputSpec(CommandLineInputSpec): infile_a = File(desc='input file to 3dcalc', argstr='-a %s', position=0, mandatory=True) infile_b = File(desc='operand file to 3dcalc', @@ -1253,20 +1467,30 @@ class calcInputSpec(CommandLineInputSpec): other = File(desc='other options', argstr='') -class calcOutputSpec(TraitedSpec): +class CalcOutputSpec(TraitedSpec): out_file = File(desc=' output file', exists=True) -class calc(CommandLine): - """Merge or edit volumes using AFNI 3dmerge command. - -For complete details, see the `3dcalc Documentation. -`_ +class Calc(CommandLine): + """ + This program does voxel-by-voxel arithmetic on 3D datasets + For complete details, see the `3dcalc Documentation. + `_ + Examples + ------------- + >>> from nipype.interfaces import afni as afni + >>> from nipype.testing import example_data + >>> calc = afni.Calc() + >>> calc.inputs.infile_a = example_data('functional.nii') + >>> calc.inputs.Infile_b = example_data('functional2.nii.gz') + >>> calc.inputs.expr='a*b' + >>> calc.inputs.out_file = 'functional_calc.nii.gz' + >>> res = calc.run() # doctest: +SKIP """ _cmd = '3dcalc' - input_spec = calcInputSpec - output_spec = calcOutputSpec + input_spec = CalcInputSpec + output_spec = CalcOutputSpec def _list_outputs(self): outputs = self.output_spec().get() @@ -1274,30 +1498,28 @@ def _list_outputs(self): outputs['out_file'] = self._gen_filename('out_file') else: outputs['out_file'] = os.path.abspath(self.inputs.out_file) - return outputs def _format_arg(self, name, trait_spec, value): if name == 'infile_a': arg = trait_spec.argstr % value if isdefined(self.inputs.start_idx): - arg + = '[%d..%d]' % (self.inputs.start_idx, + arg += '[%d..%d]' % (self.inputs.start_idx, self.inputs.stop_idx) if isdefined(self.inputs.single_idx): - arg + = '[%d]' % (self.inputs.single_idx) - return arg - return super(calc, self)._format_arg(name, trait_spec, value) + arg += '[%d]' % (self.inputs.single_idx) + return arg + return super(Calc, self)._format_arg(name, trait_spec, value) def _parse_inputs(self, skip=None): """Skip the arguments without argstr metadata - """ - return super(calc, self)._parse_inputs(skip=('start_idx', - 'stop_idx', 'other')) +""" + return super(Calc, self)._parse_inputs( + skip=('start_idx', 'stop_idx', 'other')) def _gen_filename(self, name): """Generate output file name - """ +""" if name == 'out_file': _, fname, ext = split_filename(self.inputs.infile_a) - return os.path.join(os.getcwd(), - ''.join((fname, '_3dc', ext))) + return os.path.join(os.getcwd(), ''.join((fname, '_3dc', ext))) From 7ff3011299f8dabf3f2f406e995ef82fedc941f4 Mon Sep 17 00:00:00 2001 From: ssikka Date: Fri, 2 Mar 2012 11:12:08 -0500 Subject: [PATCH 4/6] BF numpy docstring format + flake8 test --- nipype/interfaces/afni/preprocess.py | 126 ++++++++++++++------------- 1 file changed, 66 insertions(+), 60 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 7ac4503f00..ed881dbbee 100755 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -3,18 +3,12 @@ __docformat__ = 'restructuredtext' import warnings import os -import nibabel as nb -import numpy as np -from string import Template -from nipype.utils.filemanip import split_filename -from nipype.interfaces.matlab import MatlabCommand -from nipype.interfaces.base import BaseInterface, BaseInterfaceInputSpec -from nipype.interfaces.afni.base import AFNITraitedSpec, AFNICommand, Info -from nipype.interfaces.base import Bunch, Directory +from nipype.interfaces.afni.base import AFNITraitedSpec, AFNICommand +from nipype.interfaces.base import Directory from nipype.interfaces.base import (CommandLineInputSpec, CommandLine, TraitedSpec, traits, isdefined, File) from nipype.utils.filemanip import (load_json, save_json, -split_filename, fname_presuffix) +split_filename) warn = warnings.warn warnings.filterwarnings('always', category=UserWarning) @@ -58,23 +52,22 @@ class To3DOutputSpec(TraitedSpec): class To3D(AFNICommand): """Create a 3D dataset from 2D image files using AFNI to3d command. + For complete details, see the `to3d Documentation. + `_ -For complete details, see the `to3d Documentation. -`_ + To print out the command line help, use: + To3d().inputs_help() -To print out the command line help, use: -To3d().inputs_help() - -Examples --------- ->>> from nipype.interfaces import afni ->>> To3D = afni.To3d() -AFNI has no environment variable that sets filetype -Nipype uses NIFTI_GZ as default ->>> To3D.inputs.datatype = 'float' ->>> To3D.inputs.infolder = 'dicomdir' ->>> To3D.inputs.filetype = "anat" ->>> res = To3D.run() #doctest: +SKIP + Examples + -------- + >>> from nipype.interfaces import afni + >>> To3D = afni.To3d() + AFNI has no environment variable that sets filetype + Nipype uses NIFTI_GZ as default + >>> To3D.inputs.datatype = 'float' + >>> To3D.inputs.infolder = 'dicomdir' + >>> To3D.inputs.filetype = "anat" + >>> res = To3D.run() #doctest: +SKIP """ @@ -215,7 +208,6 @@ class Refit(AFNICommand): NOTES ----- The original file is returned but it is CHANGED - Examples ________ >>> from nipype.interfaces import afni as afni @@ -308,14 +300,15 @@ def _gen_filename(self, name): def _list_outputs(self): outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(outputs['out_file']): + if not isdefined(self.inputs.out_file): if isdefined(self.inputs.suffix): suffix = self.inputs.suffix else: suffix = "_warp" - outputs['out_file'] = self._gen_fname( - self.inputs.in_file, suffix=suffix) + outputs['out_file'] = self._gen_fname( + self.inputs.in_file, suffix=suffix) + else: + outputs['out_file'] = self.inputs.out_file return outputs @@ -370,8 +363,7 @@ def _gen_filename(self, name): def _list_outputs(self): outputs = self.output_spec().get() - outputs['out_file'] = self.inputs.out_file - if not isdefined(outputs['out_file']): + if not isdefined(self.inputs.out_file): if isdefined(self.inputs.suffix): suffix = self.inputs.suffix else: @@ -379,8 +371,10 @@ def _list_outputs(self): if self.inputs.orientation: suffix.append("_RPI") suffix = "".join(suffix) - outputs['out_file'] = self._gen_fname( - self.inputs.in_file, suffix=suffix) + outputs['out_file'] = self._gen_fname( + self.inputs.in_file, suffix=suffix) + else: + outputs['out_file'] = self.inputs.out_file return outputs @@ -410,7 +404,6 @@ class TStat(AFNICommand): Compute voxel-wise statistics using AFNI 3dTstat command. For complete details, see the `3dTstat Documentation. `_ - Examples ________ >>> from nipype.interfaces import afni as afni @@ -527,7 +520,6 @@ class Despike(AFNICommand): more pleasing to the eye. For complete details, see the `3dDespike Documentation. `_ - Examples ________ >>> from nipype.interfaces import afni as afni @@ -535,7 +527,6 @@ class Despike(AFNICommand): >>> despike = afni.Despike() >>> despike.inputs.in_file = example_data('functional.nii') >>> res = despike.run() # doctest: +SKIP - """ _cmd = '3dDespike' @@ -607,7 +598,7 @@ class Automask(AFNICommand): For complete details, see the `3dAutomask Documentation. `_ Examples - ______________ + ________ >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> automask = afni.Automask() @@ -628,9 +619,8 @@ def _gen_filename(self, name): def _list_outputs(self): outputs = self.output_spec().get() outputs['brain_file'] = self.inputs.apply_mask - outputs['out_file'] = self.inputs.out_file - if not isdefined(outputs['out_file']): + if not isdefined(self.inputs.out_file): if isdefined(self.inputs.suffix): suffix = self.inputs.suffix else: @@ -638,6 +628,8 @@ def _list_outputs(self): outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix) + else: + outputs['out_file'] = self.inputs.out_file return outputs @@ -689,7 +681,7 @@ class Volreg(AFNICommand): For complete details, see the `3dvolreg Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> volreg = afni.Volreg() @@ -759,8 +751,8 @@ class Merge(AFNICommand): Merge or edit volumes using AFNI 3dmerge command. For complete details, see the `3dmerge Documentation. `_ - Examples - ------------- + Examples + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> merge = afni.Merge() @@ -802,7 +794,7 @@ class Copy(AFNICommand): Copies an image of one type to an image of the same or different type using 3dcopy command. Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> copy = afni.Copy() @@ -864,7 +856,7 @@ class Fourier(AFNICommand): For complete details, see the `3dFourier Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> fourier = afni.Fourier() @@ -918,11 +910,12 @@ class ZCutUpOutputSpec(AFNITraitedSpec): class ZCutUp(AFNICommand): - """Cut z-slices from a volume using AFNI 3dZcutup command. + """ + Cut z-slices from a volume using AFNI 3dZcutup command. For complete details, see the `3dZcutup Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> zcutup = afni.Zcutup() @@ -964,10 +957,11 @@ class AllineateOutputSpec(AFNITraitedSpec): class Allineate(AFNICommand): """ + Program to align one dataset (the 'source') to a base dataset. For complete details, see the `3dAllineate Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> allineate = afni.Allineate() @@ -1013,10 +1007,13 @@ class MaskaveOutputSpec(AFNITraitedSpec): class Maskave(AFNICommand): """ + Computes average of all voxels in the input dataset + which satisfy the criterion in the options list. + If no options are given, then all voxels are included. For complete details, see the `3dmaskave Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> maskave = afni.Maskave() @@ -1068,10 +1065,12 @@ class SkullStripOutputSpec(AFNITraitedSpec): class SkullStrip(AFNICommand): """ + A program to extract the brain from surrounding + tissue from MRI T1-weighted images. For complete details, see the `3dSkullStrip Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> skullstrip = afni.Skullstrip() @@ -1121,10 +1120,12 @@ class TCatOutputSpec(AFNITraitedSpec): class TCat(AFNICommand): """ + Concatenate sub-bricks from input datasets into + one big 3D+time dataset. For complete details, see the `3dTcat Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> tcat = afni.TCat() @@ -1183,10 +1184,13 @@ class FimOutputSpec(AFNITraitedSpec): class Fim(AFNICommand): """ + Program to calculate the cross-correlation of + an ideal reference waveform + with the measured FMRI time series for each voxel. For complete details, see the `3dfim+ Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> fim = afni.Fim() @@ -1260,7 +1264,7 @@ class TCorrelate(AFNICommand): For complete details, see the `3dfim+ Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> tcorrelate = afni.TCorrelate() @@ -1279,9 +1283,10 @@ class TCorrelate(AFNICommand): def _list_outputs(self): outputs = self.output_spec().get() - outputs['out_file'] = os.path.abspath(self.inputs.out_file) - if not isdefined(outputs['out_file']): + if not isdefined(self.inputs.out_file): outputs['out_file'] = self._gen_filename('out_file') + else: + outputs['out_file'] = os.path.abspath(self.inputs.out_file) return outputs def _gen_filename(self, name): @@ -1314,10 +1319,11 @@ class BrickStatOutputSpec(AFNITraitedSpec): class BrickStat(AFNICommand): """ - For complete details, see the `3dfim+ Documentation. + Compute maximum and/or minimum voxel values of an input dataset. + For complete details, see the `3dBrickStat Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> brickstat = afni.BrickStat() @@ -1391,7 +1397,7 @@ class ROIStats(AFNICommand): For complete details, see the `3dROIstats Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> roistats = afni.ROIStats() @@ -1477,7 +1483,7 @@ class Calc(CommandLine): For complete details, see the `3dcalc Documentation. `_ Examples - ------------- + -------- >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> calc = afni.Calc() @@ -1513,13 +1519,13 @@ def _format_arg(self, name, trait_spec, value): def _parse_inputs(self, skip=None): """Skip the arguments without argstr metadata -""" + """ return super(Calc, self)._parse_inputs( skip=('start_idx', 'stop_idx', 'other')) def _gen_filename(self, name): """Generate output file name -""" + """ if name == 'out_file': _, fname, ext = split_filename(self.inputs.infile_a) return os.path.join(os.getcwd(), ''.join((fname, '_3dc', ext))) From d42d7863f7eef8bb010358f23f90c197f972e793 Mon Sep 17 00:00:00 2001 From: ssikka Date: Fri, 2 Mar 2012 12:59:57 -0500 Subject: [PATCH 5/6] BF numpy docstring format fix --- nipype/interfaces/afni/preprocess.py | 238 +++++++++++++++++---------- 1 file changed, 150 insertions(+), 88 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index ed881dbbee..a8ff8a4763 100755 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -52,14 +52,13 @@ class To3DOutputSpec(TraitedSpec): class To3D(AFNICommand): """Create a 3D dataset from 2D image files using AFNI to3d command. - For complete details, see the `to3d Documentation. - `_ - To print out the command line help, use: - To3d().inputs_help() + For complete details, see the `to3d Documentation + `_ Examples - -------- + ======== + >>> from nipype.interfaces import afni >>> To3D = afni.To3d() AFNI has no environment variable that sets filetype @@ -133,14 +132,16 @@ class TShiftOutputSpec(AFNITraitedSpec): class TShift(AFNICommand): - """ - Shifts voxel time series from input + """Shifts voxel time series from input so that seperate slices are aligned to the same - temporal origin. + temporal origin + For complete details, see the `3dTshift Documentation. + Examples - ________ + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> tshift = afni.TShift() @@ -149,6 +150,7 @@ class TShift(AFNICommand): >>> tshift.inputs.tpattern = 'alt+z' >>> tshift.inputs.tzero = 0.0 >>> res = tshift.run() # doctest: +SKIP + """ _cmd = '3dTshift' @@ -201,21 +203,21 @@ class RefitOutputSpec(AFNITraitedSpec): class Refit(AFNICommand): - """ - Changes some of the information inside a 3D dataset's header + """Changes some of the information inside a 3D dataset's header + For complete details, see the `3drefit Documentation. - NOTES - ----- - The original file is returned but it is CHANGED + Examples - ________ + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> refit = afni.Refit() >>> refit.inputs.in_file = example_data('structural.nii') >>> refit.inputs.deoblique=True >>> res = refit.run() # doctest: +SKIP + """ _cmd = '3drefit' @@ -275,18 +277,21 @@ class WarpOutputSpec(AFNITraitedSpec): class Warp(AFNICommand): - """ - Use 3dWarp for spatially transforming a dataset + """Use 3dWarp for spatially transforming a dataset + For complete details, see the `3dWarp Documentation. `_ + Examples - ________ + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> warp = afni.Warp() >>> warp.inputs.in_file = example_data('structural.nii') >>> warp.inputs.deoblique = True >>> res = warp.run() # doctest: +SKIP + """ _cmd = '3dWarp' @@ -338,18 +343,21 @@ class ResampleOutputSpec(AFNITraitedSpec): class Resample(AFNICommand): - """ - Resample or reorient an image using AFNI 3dresample command. + """Resample or reorient an image using AFNI 3dresample command + For complete details, see the `3dresample Documentation. `_ + Examples - ________ + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> resample = afni.Resample() >>> resample.inputs.in_file = example_data('functional.nii') >>> resample.inputs.orientation= 'RPI' >>> res = resample.run() # doctest: +SKIP + """ _cmd = '3dresample' @@ -400,18 +408,21 @@ class TStatOutputSpec(AFNITraitedSpec): class TStat(AFNICommand): - """ - Compute voxel-wise statistics using AFNI 3dTstat command. + """Compute voxel-wise statistics using AFNI 3dTstat command. + For complete details, see the `3dTstat Documentation. `_ + Examples - ________ + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> tstat = afni.TStat() >>> tstat.inputs.in_file = example_data('functional.nii') >>> tstat.inputs.options= '-mean' >>> res = tstat.run() # doctest: +SKIP + """ _cmd = '3dTstat' @@ -455,19 +466,22 @@ class DetrendOutputSpec(AFNITraitedSpec): class Detrend(AFNICommand): - """ - This program removes components from voxel time series using - linear least squares. Each voxel is treated independently. - For complete details, see the `3dTstat Documentation. + """This program removes components from voxel time series using + linear least squares + + For complete details, see the `3dDetrend Documentation. `_ + Examples - ________ + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> detrend = afni.Detrend() >>> detrend.inputs.in_file = example_data('functional.nii') >>> detrend.inputs.options = '-polort 2' >>> res = detrend.run() # doctest: +SKIP + """ _cmd = '3dDetrend' @@ -514,19 +528,20 @@ class DespikeOutputSpec(AFNITraitedSpec): class Despike(AFNICommand): - """ - Removes 'spikes' from the 3D+time input dataset and writes - a new dataset with the spike values replaced by something - more pleasing to the eye. + """Removes 'spikes' from the 3D+time input dataset + For complete details, see the `3dDespike Documentation. `_ + Examples - ________ + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> despike = afni.Despike() >>> despike.inputs.in_file = example_data('functional.nii') >>> res = despike.run() # doctest: +SKIP + """ _cmd = '3dDespike' @@ -593,18 +608,21 @@ class AutomaskOutputSpec(AFNITraitedSpec): class Automask(AFNICommand): - """ - Create a brain-only mask of the image using AFNI 3dAutomask command. + """Create a brain-only mask of the image using AFNI 3dAutomask command + For complete details, see the `3dAutomask Documentation. `_ + Examples - ________ + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> automask = afni.Automask() >>> automask.inputs.in_file = example_data('functional.nii') >>> automask.inputs.dilate = 1 >>> res = automask.run() # doctest: +SKIP + """ _cmd = '3dAutomask' @@ -676,12 +694,14 @@ class VolregOutputSpec(AFNITraitedSpec): class Volreg(AFNICommand): - """ - Register input volumes to a base volume using AFNI 3dvolreg command. + """Register input volumes to a base volume using AFNI 3dvolreg command + For complete details, see the `3dvolreg Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> volreg = afni.Volreg() @@ -689,6 +709,7 @@ class Volreg(AFNICommand): >>> volreg.inputs.other = '-Fourier -twopass' >>> volreg.inputs.zpad = '4' >>> res = volreg.run() # doctest: +SKIP + """ _cmd = '3dvolreg' @@ -747,12 +768,14 @@ class MergeOutputSpec(AFNITraitedSpec): class Merge(AFNICommand): - """ - Merge or edit volumes using AFNI 3dmerge command. + """Merge or edit volumes using AFNI 3dmerge command + For complete details, see the `3dmerge Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> merge = afni.Merge() @@ -761,6 +784,7 @@ class Merge(AFNICommand): >>> merge.inputs.doall = True >>> merge.inputs.outfile = 'e7.nii' >>> res = merge.run() # doctest: +SKIP + """ _cmd = '3dmerge' @@ -790,17 +814,22 @@ class CopyOutputSpec(AFNITraitedSpec): class Copy(AFNICommand): - """ - Copies an image of one type to an image of the same - or different type using 3dcopy command. + """Copies an image of one type to an image of the same + or different type using 3dcopy command + + For complete details, see the `3dcopy Documentation. + `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> copy = afni.Copy() >>> copy.inputs.in_file = example_data('functional.nii') >>> copy.inputs.out_file = 'new_func.nii' >>> res = copy.run() # doctest: +SKIP + """ _cmd = '3dcopy' @@ -852,11 +881,15 @@ class FourierOutputSpec(AFNITraitedSpec): class Fourier(AFNICommand): - """ + """Program to lowpass and/or highpass each voxel time series in a + dataset, via the FFT + For complete details, see the `3dFourier Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> fourier = afni.Fourier() @@ -865,6 +898,7 @@ class Fourier(AFNICommand): >>> fourier.inputs.highpass = 0.005 >>> fourier.inputs.lowpass = 0.1 >>> res = fourier.run() # doctest: +SKIP + """ _cmd = '3dFourier' @@ -910,12 +944,14 @@ class ZCutUpOutputSpec(AFNITraitedSpec): class ZCutUp(AFNICommand): - """ - Cut z-slices from a volume using AFNI 3dZcutup command. + """Cut z-slices from a volume using AFNI 3dZcutup command + For complete details, see the `3dZcutup Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> zcutup = afni.Zcutup() @@ -923,6 +959,7 @@ class ZCutUp(AFNICommand): >>> zcutup.inputs.outfile= 'functional_zcutup.nii' >>> zcutup.inputs.keep= '0 10' >>> res = zcutup.run() # doctest: +SKIP + """ _cmd = '3dZcutup' @@ -956,12 +993,14 @@ class AllineateOutputSpec(AFNITraitedSpec): class Allineate(AFNICommand): - """ - Program to align one dataset (the 'source') to a base dataset. + """Program to align one dataset (the 'source') to a base dataset + For complete details, see the `3dAllineate Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> allineate = afni.Allineate() @@ -969,6 +1008,7 @@ class Allineate(AFNICommand): >>> allineate.inputs.outfile= 'functional_allineate.nii' >>> allineate.inputs.matrix= example_data('cmatrix.mat') >>> res = allineate.run() # doctest: +SKIP + """ _cmd = '3dAllineate' @@ -1006,14 +1046,15 @@ class MaskaveOutputSpec(AFNITraitedSpec): class Maskave(AFNICommand): - """ - Computes average of all voxels in the input dataset - which satisfy the criterion in the options list. - If no options are given, then all voxels are included. + """Computes average of all voxels in the input dataset + which satisfy the criterion in the options list + For complete details, see the `3dmaskave Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> maskave = afni.Maskave() @@ -1022,6 +1063,7 @@ class Maskave(AFNICommand): >>> maskave.inputs.quiet= True >>> maskave.inputs.out_file= 'maskave.1D' >>> res = maskave.run() # doctest: +SKIP + """ _cmd = '3dmaskave' @@ -1064,19 +1106,22 @@ class SkullStripOutputSpec(AFNITraitedSpec): class SkullStrip(AFNICommand): - """ - A program to extract the brain from surrounding - tissue from MRI T1-weighted images. + """A program to extract the brain from surrounding + tissue from MRI T1-weighted images + For complete details, see the `3dSkullStrip Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> skullstrip = afni.Skullstrip() >>> skullstrip.inputs.in_file = example_data('functional.nii') >>> skullstrip.inputs.options = '-o_ply' >>> res = skullstrip.run() # doctest: +SKIP + """ _cmd = '3dSkullStrip' input_spec = SkullStripInputSpec @@ -1119,13 +1164,15 @@ class TCatOutputSpec(AFNITraitedSpec): class TCat(AFNICommand): - """ - Concatenate sub-bricks from input datasets into - one big 3D+time dataset. + """Concatenate sub-bricks from input datasets into + one big 3D+time dataset + For complete details, see the `3dTcat Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> tcat = afni.TCat() @@ -1133,6 +1180,7 @@ class TCat(AFNICommand): >>> tcat.inputs.out_file= 'functional_tcat.nii' >>> tcat.inputs.rlt = '+' >>> res = tcat.run() # doctest: +SKIP + """ _cmd = '3dTcat' @@ -1183,14 +1231,16 @@ class FimOutputSpec(AFNITraitedSpec): class Fim(AFNICommand): - """ - Program to calculate the cross-correlation of - an ideal reference waveform - with the measured FMRI time series for each voxel. + """Program to calculate the cross-correlation of + an ideal reference waveform with the measured FMRI + time series for each voxel + For complete details, see the `3dfim+ Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> fim = afni.Fim() @@ -1200,6 +1250,7 @@ class Fim(AFNICommand): >>> fim.inputs.out = 'Correlation' >>> fim.inputs.fim_thr = 0.0009 >>> res = fim.run() # doctest: +SKIP + """ _cmd = '3dfim+' @@ -1257,14 +1308,15 @@ class TCorrelateOutputSpec(AFNITraitedSpec): class TCorrelate(AFNICommand): - """ - Computes the correlation coefficient between corresponding voxel - time series in two input 3D+time datasets 'xset' and 'yset', and - stores the output in a new 1 sub-brick dataset. - For complete details, see the `3dfim+ Documentation. + """Computes the correlation coefficient between corresponding voxel + time series in two input 3D+time datasets 'xset' and 'yset' + + For complete details, see the `3dTcorrelate Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> tcorrelate = afni.TCorrelate() @@ -1275,6 +1327,7 @@ class TCorrelate(AFNICommand): >>> tcorrelate.inputs.polort = -1 >>> tcorrelate.inputs.pearson = True >>> res = tcarrelate.run() # doctest: +SKIP + """ _cmd = '3dTcorrelate' @@ -1318,12 +1371,14 @@ class BrickStatOutputSpec(AFNITraitedSpec): class BrickStat(AFNICommand): - """ - Compute maximum and/or minimum voxel values of an input dataset. + """Compute maximum and/or minimum voxel values of an input dataset + For complete details, see the `3dBrickStat Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> brickstat = afni.BrickStat() @@ -1331,6 +1386,7 @@ class BrickStat(AFNICommand): >>> brickstat.inputs.mask = example_data('skeleton_mask.nii.gz') >>> brickstat.inputs.min = True >>> res = brickstat.run() # doctest: +SKIP + """ _cmd = '3dBrickStat' input_spec = BrickStatInputSpec @@ -1392,12 +1448,14 @@ class ROIStatsOutputSpec(AFNITraitedSpec): class ROIStats(AFNICommand): - """ - Display statistics over masked regions. + """Display statistics over masked regions + For complete details, see the `3dROIstats Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> roistats = afni.ROIStats() @@ -1405,6 +1463,7 @@ class ROIStats(AFNICommand): >>> roistats.inputs.mask = example_data('skeleton_mask.nii.gz') >>> roistats.inputs.quiet=True >>> res = roistats.run() # doctest: +SKIP + """ _cmd = '3dROIstats' input_spec = ROIStatsInputSpec @@ -1478,12 +1537,14 @@ class CalcOutputSpec(TraitedSpec): class Calc(CommandLine): - """ - This program does voxel-by-voxel arithmetic on 3D datasets + """This program does voxel-by-voxel arithmetic on 3D datasets + For complete details, see the `3dcalc Documentation. `_ + Examples - -------- + ======== + >>> from nipype.interfaces import afni as afni >>> from nipype.testing import example_data >>> calc = afni.Calc() @@ -1492,6 +1553,7 @@ class Calc(CommandLine): >>> calc.inputs.expr='a*b' >>> calc.inputs.out_file = 'functional_calc.nii.gz' >>> res = calc.run() # doctest: +SKIP + """ _cmd = '3dcalc' From 08001ab1b24e96184962d56d8ed94c1fb6fb060c Mon Sep 17 00:00:00 2001 From: ssikka Date: Fri, 2 Mar 2012 13:03:22 -0500 Subject: [PATCH 6/6] BF numpy docstring format another fix --- nipype/interfaces/afni/preprocess.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index a8ff8a4763..c62f474a15 100755 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -51,7 +51,7 @@ class To3DOutputSpec(TraitedSpec): class To3D(AFNICommand): - """Create a 3D dataset from 2D image files using AFNI to3d command. + """Create a 3D dataset from 2D image files using AFNI to3d command For complete details, see the `to3d Documentation `_ @@ -408,7 +408,7 @@ class TStatOutputSpec(AFNITraitedSpec): class TStat(AFNICommand): - """Compute voxel-wise statistics using AFNI 3dTstat command. + """Compute voxel-wise statistics using AFNI 3dTstat command For complete details, see the `3dTstat Documentation. `_