diff --git a/nipype/interfaces/afni/preprocess.py b/nipype/interfaces/afni/preprocess.py index 59f80dd6cb..0ade11c94a 100644 --- a/nipype/interfaces/afni/preprocess.py +++ b/nipype/interfaces/afni/preprocess.py @@ -10,16 +10,14 @@ >>> os.chdir(datadir) """ from __future__ import print_function, division, unicode_literals, absolute_import -from builtins import open, str, bytes +from builtins import open import os import os.path as op -import re -import numpy as np from ...utils.filemanip import (load_json, save_json, split_filename) from ..base import ( - CommandLineInputSpec, CommandLine, Directory, TraitedSpec, + CommandLineInputSpec, CommandLine, TraitedSpec, traits, isdefined, File, InputMultiPath, Undefined, Str) from .base import ( @@ -260,17 +258,19 @@ 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.interfaces import afni >>> allineate = afni.Allineate() >>> allineate.inputs.in_file = 'functional.nii' - >>> allineate.inputs.out_file= 'functional_allineate.nii' - >>> allineate.inputs.in_matrix= 'cmatrix.mat' - >>> res = allineate.run() # doctest: +SKIP + >>> allineate.inputs.out_file = 'functional_allineate.nii' + >>> allineate.inputs.in_matrix = 'cmatrix.mat' + >>> allineate.cmdline # doctest: +IGNORE_UNICODE + '3dAllineate -1Dmatrix_apply cmatrix.mat -prefix functional_allineate.nii -source functional.nii' + >>> res = allineate.run() # doctest: +SKIP """ @@ -341,19 +341,22 @@ class AutoTcorrelate(AFNICommand): pair of voxels in the input dataset, and stores the output into a new anatomical bucket dataset [scaled to shorts to save memory space]. + For complete details, see the `3dAutoTcorrelate Documentation. + `_ + Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> corr = afni.AutoTcorrelate() >>> corr.inputs.in_file = 'functional.nii' >>> corr.inputs.polort = -1 >>> corr.inputs.eta2 = True >>> corr.inputs.mask = 'mask.nii' >>> corr.inputs.mask_only_targets = True - >>> corr.cmdline # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE +IGNORE_UNICODE + >>> corr.cmdline # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE +IGNORE_UNICODE '3dAutoTcorrelate -eta2 -mask mask.nii -mask_only_targets -prefix functional_similarity_matrix.1D -polort -1 functional.nii' - >>> res = corr.run() # doctest: +SKIP + >>> res = corr.run() # doctest: +SKIP """ input_spec = AutoTcorrelateInputSpec output_spec = AFNICommandOutputSpec @@ -361,7 +364,7 @@ class AutoTcorrelate(AFNICommand): def _overload_extension(self, value, name=None): path, base, ext = split_filename(value) - if ext.lower() not in ['.1d', '.nii.gz', '.nii']: + if ext.lower() not in ['.1d', '.1D', '.nii.gz', '.nii']: ext = ext + '.1D' return os.path.join(path, base + ext) @@ -409,19 +412,19 @@ class Automask(AFNICommand): """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.interfaces import afni >>> automask = afni.Automask() >>> automask.inputs.in_file = 'functional.nii' >>> automask.inputs.dilate = 1 >>> automask.inputs.outputtype = 'NIFTI' - >>> automask.cmdline #doctest: +ELLIPSIS +IGNORE_UNICODE + >>> automask.cmdline # doctest: +ELLIPSIS +IGNORE_UNICODE '3dAutomask -apply_prefix functional_masked.nii -dilate 1 -prefix functional_mask.nii functional.nii' - >>> res = automask.run() # doctest: +SKIP + >>> res = automask.run() # doctest: +SKIP """ @@ -517,18 +520,20 @@ class Bandpass(AFNICommand): dataset, offering more/different options than Fourier For complete details, see the `3dBandpass Documentation. - `_ + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> from nipype.testing import example_data >>> bandpass = afni.Bandpass() - >>> bandpass.inputs.in_file = example_data('functional.nii') + >>> bandpass.inputs.in_file = 'functional.nii' >>> bandpass.inputs.highpass = 0.005 >>> bandpass.inputs.lowpass = 0.1 - >>> res = bandpass.run() # doctest: +SKIP + >>> bandpass.cmdline # doctest: +IGNORE_UNICODE + '3dBandpass -prefix functional_bp 0.005000 0.100000 functional.nii' + >>> res = bandpass.run() # doctest: +SKIP """ @@ -581,22 +586,22 @@ class BlurInMaskInputSpec(AFNICommandInputSpec): class BlurInMask(AFNICommand): - """ Blurs a dataset spatially inside a mask. That's all. Experimental. + """Blurs a dataset spatially inside a mask. That's all. Experimental. For complete details, see the `3dBlurInMask Documentation. - + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> bim = afni.BlurInMask() >>> bim.inputs.in_file = 'functional.nii' >>> bim.inputs.mask = 'mask.nii' >>> bim.inputs.fwhm = 5.0 - >>> bim.cmdline #doctest: +ELLIPSIS +IGNORE_UNICODE + >>> bim.cmdline # doctest: +ELLIPSIS +IGNORE_UNICODE '3dBlurInMask -input functional.nii -FWHM 5.000000 -mask mask.nii -prefix functional_blur' - >>> res = bim.run() # doctest: +SKIP + >>> res = bim.run() # doctest: +SKIP """ @@ -635,7 +640,7 @@ class BlurToFWHM(AFNICommand): """Blurs a 'master' dataset until it reaches a specified FWHM smoothness (approximately). - For complete details, see the `to3d Documentation + For complete details, see the `3dBlurToFWHM Documentation `_ Examples @@ -645,8 +650,9 @@ class BlurToFWHM(AFNICommand): >>> blur = afni.preprocess.BlurToFWHM() >>> blur.inputs.in_file = 'epi.nii' >>> blur.inputs.fwhm = 2.5 - >>> blur.cmdline #doctest: +ELLIPSIS +IGNORE_UNICODE + >>> blur.cmdline # doctest: +ELLIPSIS +IGNORE_UNICODE '3dBlurToFWHM -FWHM 2.500000 -input epi.nii -prefix epi_afni' + >>> res = blur.run() # doctest: +SKIP """ _cmd = '3dBlurToFWHM' @@ -695,7 +701,9 @@ class ClipLevel(AFNICommandBase): >>> from nipype.interfaces.afni import preprocess >>> cliplevel = preprocess.ClipLevel() >>> cliplevel.inputs.in_file = 'anatomical.nii' - >>> res = cliplevel.run() # doctest: +SKIP + >>> cliplevel.cmdline # doctest: +IGNORE_UNICODE + '3dClipLevel anatomical.nii' + >>> res = cliplevel.run() # doctest: +SKIP """ _cmd = '3dClipLevel' @@ -765,20 +773,21 @@ class DegreeCentrality(AFNICommand): via 3dDegreeCentrality For complete details, see the `3dDegreeCentrality Documentation. - + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> degree = afni.DegreeCentrality() >>> degree.inputs.in_file = 'functional.nii' >>> degree.inputs.mask = 'mask.nii' >>> degree.inputs.sparsity = 1 # keep the top one percent of connections >>> degree.inputs.out_file = 'out.nii' - >>> degree.cmdline # doctest: +IGNORE_UNICODE + >>> degree.cmdline # doctest: +IGNORE_UNICODE '3dDegreeCentrality -mask mask.nii -prefix out.nii -sparsity 1.000000 functional.nii' - >>> res = degree.run() # doctest: +SKIP + >>> res = degree.run() # doctest: +SKIP + """ _cmd = '3dDegreeCentrality' @@ -817,17 +826,17 @@ class Despike(AFNICommand): """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.interfaces import afni >>> despike = afni.Despike() >>> despike.inputs.in_file = 'functional.nii' - >>> despike.cmdline # doctest: +IGNORE_UNICODE + >>> despike.cmdline # doctest: +IGNORE_UNICODE '3dDespike -prefix functional_despike functional.nii' - >>> res = despike.run() # doctest: +SKIP + >>> res = despike.run() # doctest: +SKIP """ @@ -856,19 +865,19 @@ class Detrend(AFNICommand): linear least squares For complete details, see the `3dDetrend Documentation. - `_ + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> detrend = afni.Detrend() >>> detrend.inputs.in_file = 'functional.nii' >>> detrend.inputs.args = '-polort 2' >>> detrend.inputs.outputtype = 'AFNI' >>> detrend.cmdline # doctest: +IGNORE_UNICODE '3dDetrend -polort 2 -prefix functional_detrend functional.nii' - >>> res = detrend.run() # doctest: +SKIP + >>> res = detrend.run() # doctest: +SKIP """ @@ -927,20 +936,21 @@ class ECM(AFNICommand): via the 3dECM command For complete details, see the `3dECM Documentation. - + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> ecm = afni.ECM() >>> ecm.inputs.in_file = 'functional.nii' >>> ecm.inputs.mask = 'mask.nii' >>> ecm.inputs.sparsity = 0.1 # keep top 0.1% of connections >>> ecm.inputs.out_file = 'out.nii' - >>> ecm.cmdline # doctest: +IGNORE_UNICODE + >>> ecm.cmdline # doctest: +IGNORE_UNICODE '3dECM -mask mask.nii -prefix out.nii -sparsity 0.100000 functional.nii' - >>> res = ecm.run() # doctest: +SKIP + >>> res = ecm.run() # doctest: +SKIP + """ _cmd = '3dECM' @@ -951,7 +961,7 @@ class ECM(AFNICommand): class FimInputSpec(AFNICommandInputSpec): in_file = File( desc='input file to 3dfim+', - argstr=' -input %s', + argstr='-input %s', position=1, mandatory=True, exists=True, @@ -978,24 +988,25 @@ class FimInputSpec(AFNICommandInputSpec): 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.interfaces import afni >>> fim = afni.Fim() >>> fim.inputs.in_file = 'functional.nii' >>> fim.inputs.ideal_file= 'seed.1D' >>> fim.inputs.out_file = 'functional_corr.nii' >>> fim.inputs.out = 'Correlation' >>> fim.inputs.fim_thr = 0.0009 - >>> res = fim.run() # doctest: +SKIP + >>> fim.cmdline # doctest: +IGNORE_UNICODE + '3dfim+ -input functional.nii -ideal_file seed.1D -fim_thr 0.000900 -out Correlation -bucket functional_corr.nii' + >>> res = fim.run() # doctest: +SKIP """ @@ -1020,13 +1031,15 @@ class FourierInputSpec(AFNICommandInputSpec): lowpass = traits.Float( desc='lowpass', argstr='-lowpass %f', - position=0, mandatory=True) highpass = traits.Float( desc='highpass', argstr='-highpass %f', - position=1, mandatory=True) + retrend = traits.Bool( + desc='Any mean and linear trend are removed before filtering. This ' + 'will restore the trend after filtering.', + argstr='-retrend') class Fourier(AFNICommand): @@ -1034,18 +1047,20 @@ class Fourier(AFNICommand): dataset, via the FFT For complete details, see the `3dFourier Documentation. - `_ + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> fourier = afni.Fourier() >>> fourier.inputs.in_file = 'functional.nii' - >>> fourier.inputs.args = '-retrend' + >>> fourier.inputs.retrend = True >>> fourier.inputs.highpass = 0.005 >>> fourier.inputs.lowpass = 0.1 - >>> res = fourier.run() # doctest: +SKIP + >>> fourier.cmdline # doctest: +IGNORE_UNICODE + '3dFourier -highpass 0.005000 -lowpass 0.100000 -prefix functional_fourier -retrend functional.nii' + >>> res = fourier.run() # doctest: +SKIP """ @@ -1108,17 +1123,17 @@ class Hist(AFNICommandBase): which satisfy the criterion in the options list For complete details, see the `3dHist Documentation. - `_ + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> hist = afni.Hist() >>> hist.inputs.in_file = 'functional.nii' >>> hist.cmdline # doctest: +IGNORE_UNICODE '3dHist -input functional.nii -prefix functional_hist' - >>> res = hist.run() # doctest: +SKIP + >>> res = hist.run() # doctest: +SKIP """ @@ -1169,20 +1184,20 @@ class LFCD(AFNICommand): via the 3dLFCD command For complete details, see the `3dLFCD Documentation. - + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> lfcd = afni.LFCD() >>> lfcd.inputs.in_file = 'functional.nii' >>> lfcd.inputs.mask = 'mask.nii' >>> lfcd.inputs.thresh = 0.8 # keep all connections with corr >= 0.8 >>> lfcd.inputs.out_file = 'out.nii' - >>> lfcd.cmdline # doctest: +IGNORE_UNICODE + >>> lfcd.cmdline # doctest: +IGNORE_UNICODE '3dLFCD -mask mask.nii -prefix out.nii -thresh 0.800000 functional.nii' - >>> res = lfcd.run() # doctest: +SKIP + >>> res = lfcd.run() # doctest: +SKIP """ _cmd = '3dLFCD' @@ -1221,19 +1236,19 @@ class Maskave(AFNICommand): 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.interfaces import afni >>> maskave = afni.Maskave() >>> maskave.inputs.in_file = 'functional.nii' >>> maskave.inputs.mask= 'seed_mask.nii' >>> maskave.inputs.quiet= True - >>> maskave.cmdline #doctest: +ELLIPSIS +IGNORE_UNICODE + >>> maskave.cmdline # doctest: +ELLIPSIS +IGNORE_UNICODE '3dmaskave -mask seed_mask.nii -quiet functional.nii > functional_maskave.1D' - >>> res = maskave.run() # doctest: +SKIP + >>> res = maskave.run() # doctest: +SKIP """ @@ -1288,18 +1303,20 @@ class MeansInputSpec(AFNICommandInputSpec): class Means(AFNICommand): """Takes the voxel-by-voxel mean of all input datasets using 3dMean - see AFNI Documentation: + For complete details, see the `3dMean Documentation. + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> means = afni.Means() >>> means.inputs.in_file_a = 'im1.nii' >>> means.inputs.in_file_b = 'im2.nii' >>> means.inputs.out_file = 'output.nii' >>> means.cmdline # doctest: +IGNORE_UNICODE '3dMean im1.nii im2.nii -prefix output.nii' + >>> res = means.run() # doctest: +SKIP """ @@ -1404,11 +1421,11 @@ class OutlierCount(CommandLine): >>> from nipype.interfaces import afni >>> toutcount = afni.OutlierCount() >>> toutcount.inputs.in_file = 'functional.nii' - >>> toutcount.cmdline #doctest: +ELLIPSIS +IGNORE_UNICODE + >>> toutcount.cmdline # doctest: +ELLIPSIS +IGNORE_UNICODE '3dToutcount functional.nii > functional_outliers' - >>> res = toutcount.run() #doctest: +SKIP + >>> res = toutcount.run() # doctest: +SKIP - """ + """ _cmd = '3dToutcount' input_spec = OutlierCountInputSpec @@ -1503,9 +1520,9 @@ class QualityIndex(CommandLine): >>> from nipype.interfaces import afni >>> tqual = afni.QualityIndex() >>> tqual.inputs.in_file = 'functional.nii' - >>> tqual.cmdline #doctest: +ELLIPSIS +IGNORE_UNICODE + >>> tqual.cmdline # doctest: +ELLIPSIS +IGNORE_UNICODE '3dTqual functional.nii > functional_tqual' - >>> res = tqual.run() #doctest: +SKIP + >>> res = tqual.run() # doctest: +SKIP """ _cmd = '3dTqual' @@ -1553,17 +1570,19 @@ class ROIStats(AFNICommandBase): """Display statistics over masked regions For complete details, see the `3dROIstats Documentation. - `_ + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> roistats = afni.ROIStats() >>> roistats.inputs.in_file = 'functional.nii' >>> roistats.inputs.mask = 'skeleton_mask.nii.gz' - >>> roistats.inputs.quiet=True - >>> res = roistats.run() # doctest: +SKIP + >>> roistats.inputs.quiet = True + >>> roistats.cmdline # doctest: +IGNORE_UNICODE + '3dROIstats -quiet -mask skeleton_mask.nii.gz functional.nii' + >>> res = roistats.run() # doctest: +SKIP """ _cmd = '3dROIstats' @@ -1645,11 +1664,11 @@ class Retroicor(AFNICommand): motion correction). For complete details, see the `3dretroicor Documentation. - `_ + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> ret = afni.Retroicor() >>> ret.inputs.in_file = 'functional.nii' >>> ret.inputs.card = 'mask.1D' @@ -1657,7 +1676,8 @@ class Retroicor(AFNICommand): >>> ret.inputs.outputtype = 'NIFTI' >>> ret.cmdline # doctest: +IGNORE_UNICODE '3dretroicor -prefix functional_retroicor.nii -resp resp.1D -card mask.1D functional.nii' - >>> res = ret.run() # doctest: +SKIP + >>> res = ret.run() # doctest: +SKIP + """ _cmd = '3dretroicor' @@ -1724,11 +1744,11 @@ class SegInputSpec(CommandLineInputSpec): class Seg(AFNICommandBase): """3dSeg segments brain volumes into tissue classes. The program allows - for adding a variety of global and voxelwise priors. However for the - moment, only mixing fractions and MRF are documented. + for adding a variety of global and voxelwise priors. However for the + moment, only mixing fractions and MRF are documented. For complete details, see the `3dSeg Documentation. - + `_ Examples ======== @@ -1737,7 +1757,9 @@ class Seg(AFNICommandBase): >>> seg = preprocess.Seg() >>> seg.inputs.in_file = 'structural.nii' >>> seg.inputs.mask = 'AUTO' - >>> res = seg.run() # doctest: +SKIP + >>> seg.cmdline # doctest: +IGNORE_UNICODE + '3dSeg -mask AUTO -anat structural.nii' + >>> res = seg.run() # doctest: +SKIP """ @@ -1777,20 +1799,23 @@ class SkullStripInputSpec(AFNICommandInputSpec): 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. + TODO Add optional arguments. For complete details, see the `3dSkullStrip Documentation. - `_ + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> skullstrip = afni.SkullStrip() >>> skullstrip.inputs.in_file = 'functional.nii' >>> skullstrip.inputs.args = '-o_ply' - >>> res = skullstrip.run() # doctest: +SKIP + >>> skullstrip.cmdline # doctest: +IGNORE_UNICODE + '3dSkullStrip -input functional.nii -o_ply -prefix functional_skullstrip' + >>> res = skullstrip.run() # doctest: +SKIP """ _cmd = '3dSkullStrip' @@ -1858,16 +1883,18 @@ class TCorr1DOutputSpec(TraitedSpec): class TCorr1D(AFNICommand): """Computes the correlation coefficient between each voxel time series in the input 3D+time dataset. + For complete details, see the `3dTcorr1D Documentation. - `_ + `_ - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> tcorr1D = afni.TCorr1D() >>> tcorr1D.inputs.xset= 'u_rc1s1_Template.nii' >>> tcorr1D.inputs.y_1d = 'seed.1D' >>> tcorr1D.cmdline # doctest: +IGNORE_UNICODE '3dTcorr1D -prefix u_rc1s1_Template_correlation.nii.gz u_rc1s1_Template.nii seed.1D' - >>> res = tcorr1D.run() # doctest: +SKIP + >>> res = tcorr1D.run() # doctest: +SKIP + """ _cmd = '3dTcorr1D' @@ -1991,22 +2018,24 @@ class TCorrMapOutputSpec(TraitedSpec): class TCorrMap(AFNICommand): - """ For each voxel time series, computes the correlation between it + """For each voxel time series, computes the correlation between it and all other voxels, and combines this set of values into the output dataset(s) in some way. For complete details, see the `3dTcorrMap Documentation. - + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> tcm = afni.TCorrMap() >>> tcm.inputs.in_file = 'functional.nii' >>> tcm.inputs.mask = 'mask.nii' - >>> tcm.mean_file = '%s_meancorr.nii' - >>> res = tcm.run() # doctest: +SKIP + >>> tcm.mean_file = 'functional_meancorr.nii' + >>> tcm.cmdline # doctest: +IGNORE_UNICODE +SKIP + '3dTcorrMap -input functional.nii -mask mask.nii -Mean functional_meancorr.nii' + >>> res = tcm.run() # doctest: +SKIP """ @@ -2049,12 +2078,10 @@ class TCorrelateInputSpec(AFNICommandInputSpec): name_source='xset') pearson = traits.Bool( desc='Correlation is the normal Pearson correlation coefficient', - argstr='-pearson', - position=1) + argstr='-pearson') polort = traits.Int( desc='Remove polynomical trend of order m', - argstr='-polort %d', - position=2) + argstr='-polort %d') class TCorrelate(AFNICommand): @@ -2062,19 +2089,21 @@ class TCorrelate(AFNICommand): 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.interfaces import afni >>> tcorrelate = afni.TCorrelate() >>> tcorrelate.inputs.xset= 'u_rc1s1_Template.nii' >>> tcorrelate.inputs.yset = '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 + >>> tcorrelate.cmdline # doctest: +IGNORE_UNICODE + '3dTcorrelate -prefix functional_tcorrelate.nii.gz -pearson -polort -1 u_rc1s1_Template.nii u_rc1s2_Template.nii' + >>> res = tcarrelate.run() # doctest: +SKIP """ @@ -2129,24 +2158,23 @@ class TShiftInputSpec(AFNICommandInputSpec): class TShift(AFNICommand): - """Shifts voxel time series from input - so that seperate slices are aligned to the same - temporal origin + """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.interfaces import afni >>> tshift = afni.TShift() >>> tshift.inputs.in_file = 'functional.nii' >>> tshift.inputs.tpattern = 'alt+z' >>> tshift.inputs.tzero = 0.0 - >>> tshift.cmdline #doctest: +IGNORE_UNICODE + >>> tshift.cmdline # doctest: +IGNORE_UNICODE '3dTshift -prefix functional_tshift -tpattern alt+z -tzero 0.0 functional.nii' - >>> res = tshift.run() # doctest: +SKIP + >>> res = tshift.run() # doctest: +SKIP """ _cmd = '3dTshift' @@ -2225,20 +2253,20 @@ 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.interfaces import afni >>> volreg = afni.Volreg() >>> volreg.inputs.in_file = 'functional.nii' >>> volreg.inputs.args = '-Fourier -twopass' >>> volreg.inputs.zpad = 4 >>> volreg.inputs.outputtype = 'NIFTI' - >>> volreg.cmdline #doctest: +ELLIPSIS +IGNORE_UNICODE + >>> volreg.cmdline # doctest: +ELLIPSIS +IGNORE_UNICODE '3dvolreg -Fourier -twopass -1Dfile functional.1D -1Dmatrix_save functional.aff12.1D -prefix functional_volreg.nii -zpad 4 -maxdisp1D functional_md.1D functional.nii' - >>> res = volreg.run() # doctest: +SKIP + >>> res = volreg.run() # doctest: +SKIP """ @@ -2293,18 +2321,19 @@ class Warp(AFNICommand): """Use 3dWarp for spatially transforming a dataset For complete details, see the `3dWarp Documentation. - `_ + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> warp = afni.Warp() >>> warp.inputs.in_file = 'structural.nii' >>> warp.inputs.deoblique = True >>> warp.inputs.out_file = 'trans.nii.gz' - >>> warp.cmdline # doctest: +IGNORE_UNICODE + >>> warp.cmdline # doctest: +IGNORE_UNICODE '3dWarp -deoblique -prefix trans.nii.gz structural.nii' + >>> res = warp.run() # doctest: +SKIP >>> warp_2 = afni.Warp() >>> warp_2.inputs.in_file = 'structural.nii' @@ -2312,6 +2341,7 @@ class Warp(AFNICommand): >>> warp_2.inputs.out_file = 'trans.nii.gz' >>> warp_2.cmdline # doctest: +IGNORE_UNICODE '3dWarp -newgrid 1.000000 -prefix trans.nii.gz structural.nii' + >>> res = warp_2.run() # doctest: +SKIP """ _cmd = '3dWarp' diff --git a/nipype/interfaces/afni/svm.py b/nipype/interfaces/afni/svm.py index e3a361850e..e9ea02a57b 100644 --- a/nipype/interfaces/afni/svm.py +++ b/nipype/interfaces/afni/svm.py @@ -72,7 +72,7 @@ class SVMTrain(AFNICommand): """Temporally predictive modeling with the support vector machine SVM Train Only For complete details, see the `3dsvm Documentation. - `_ + `_ Examples ======== @@ -128,7 +128,7 @@ class SVMTest(AFNICommand): """Temporally predictive modeling with the support vector machine SVM Test Only For complete details, see the `3dsvm Documentation. - `_ + `_ Examples ======== diff --git a/nipype/interfaces/afni/tests/test_auto_BrickStat.py b/nipype/interfaces/afni/tests/test_auto_BrickStat.py index 6c91fcf69f..739663ab3e 100644 --- a/nipype/interfaces/afni/tests/test_auto_BrickStat.py +++ b/nipype/interfaces/afni/tests/test_auto_BrickStat.py @@ -22,11 +22,6 @@ def test_BrickStat_inputs(): min=dict(argstr='-min', position=1, ), - out_file=dict(argstr='-prefix %s', - name_source=[u'in_file'], - name_template='%s_afni', - ), - outputtype=dict(), terminal_output=dict(nohash=True, ), ) diff --git a/nipype/interfaces/afni/tests/test_auto_Fim.py b/nipype/interfaces/afni/tests/test_auto_Fim.py index 60aa963b28..bc139aac34 100644 --- a/nipype/interfaces/afni/tests/test_auto_Fim.py +++ b/nipype/interfaces/afni/tests/test_auto_Fim.py @@ -19,7 +19,7 @@ def test_Fim_inputs(): ignore_exception=dict(nohash=True, usedefault=True, ), - in_file=dict(argstr=' -input %s', + in_file=dict(argstr='-input %s', copyfile=False, mandatory=True, position=1, diff --git a/nipype/interfaces/afni/tests/test_auto_Fourier.py b/nipype/interfaces/afni/tests/test_auto_Fourier.py index 0bc9e03b6c..6d8e42b1cd 100644 --- a/nipype/interfaces/afni/tests/test_auto_Fourier.py +++ b/nipype/interfaces/afni/tests/test_auto_Fourier.py @@ -11,7 +11,6 @@ def test_Fourier_inputs(): ), highpass=dict(argstr='-highpass %f', mandatory=True, - position=1, ), ignore_exception=dict(nohash=True, usedefault=True, @@ -23,13 +22,14 @@ def test_Fourier_inputs(): ), lowpass=dict(argstr='-lowpass %f', mandatory=True, - position=0, ), out_file=dict(argstr='-prefix %s', name_source='in_file', name_template='%s_fourier', ), outputtype=dict(), + retrend=dict(argstr='-retrend', + ), terminal_output=dict(nohash=True, ), ) diff --git a/nipype/interfaces/afni/tests/test_auto_TCorrelate.py b/nipype/interfaces/afni/tests/test_auto_TCorrelate.py index 729aa54a54..af4c6c6f77 100644 --- a/nipype/interfaces/afni/tests/test_auto_TCorrelate.py +++ b/nipype/interfaces/afni/tests/test_auto_TCorrelate.py @@ -18,10 +18,8 @@ def test_TCorrelate_inputs(): ), outputtype=dict(), pearson=dict(argstr='-pearson', - position=1, ), polort=dict(argstr='-polort %d', - position=2, ), terminal_output=dict(nohash=True, ), diff --git a/nipype/interfaces/afni/utils.py b/nipype/interfaces/afni/utils.py index 06ff530a04..ac53c3a458 100644 --- a/nipype/interfaces/afni/utils.py +++ b/nipype/interfaces/afni/utils.py @@ -13,7 +13,7 @@ >>> os.chdir(datadir) """ from __future__ import print_function, division, unicode_literals, absolute_import -from builtins import open, str, bytes +from builtins import str, bytes import os import os.path as op @@ -26,8 +26,7 @@ traits, isdefined, File, InputMultiPath, Undefined, Str) from .base import ( - AFNICommandBase, AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec, - Info, no_afni) + AFNICommandBase, AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec) class AFNItoNIFTIInputSpec(AFNICommandInputSpec): @@ -71,22 +70,22 @@ class AFNItoNIFTIInputSpec(AFNICommandInputSpec): class AFNItoNIFTI(AFNICommand): - """Changes AFNI format files to NIFTI format using 3dAFNItoNIFTI + """Converts AFNI format files to NIFTI format. This can also convert 2D or + 1D data, which you can numpy.squeeze() to remove extra dimensions. - see AFNI Documentation: - - this can also convert 2D or 1D data, which you can numpy.squeeze() to - remove extra dimensions + For complete details, see the `3dAFNItoNIFTI Documentation. + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> a2n = afni.AFNItoNIFTI() >>> a2n.inputs.in_file = 'afni_output.3D' >>> a2n.inputs.out_file = 'afni_output.nii' >>> a2n.cmdline # doctest: +IGNORE_UNICODE '3dAFNItoNIFTI -prefix afni_output.nii afni_output.3D' + >>> res = a2n.run() # doctest: +SKIP """ @@ -138,20 +137,22 @@ class AutoboxOutputSpec(TraitedSpec): # out_file not mandatory class Autobox(AFNICommand): - """ Computes size of a box that fits around the volume. + """Computes size of a box that fits around the volume. Also can be used to crop the volume to that box. For complete details, see the `3dAutobox Documentation. - + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> abox = afni.Autobox() >>> abox.inputs.in_file = 'structural.nii' >>> abox.inputs.padding = 5 - >>> res = abox.run() # doctest: +SKIP + >>> abox.cmdline # doctest: +IGNORE_UNICODE + '3dAutobox -input structural.nii -prefix structural_generated -npad 5' + >>> res = abox.run() # doctest: +SKIP """ @@ -180,7 +181,7 @@ def _gen_filename(self, name): return super(Autobox, self)._gen_filename(name) -class BrickStatInputSpec(AFNICommandInputSpec): +class BrickStatInputSpec(CommandLineInputSpec): in_file = File( desc='input file to 3dmaskave', argstr='%s', @@ -203,21 +204,24 @@ class BrickStatOutputSpec(TraitedSpec): desc='output') -class BrickStat(AFNICommand): - """Compute maximum and/or minimum voxel values of an input dataset +class BrickStat(AFNICommandBase): + """Computes maximum and/or minimum voxel values of an input dataset. + TODO Add optional arguments. For complete details, see the `3dBrickStat Documentation. - `_ + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> brickstat = afni.BrickStat() >>> brickstat.inputs.in_file = 'functional.nii' >>> brickstat.inputs.mask = 'skeleton_mask.nii.gz' >>> brickstat.inputs.min = True - >>> res = brickstat.run() # doctest: +SKIP + >>> brickstat.cmdline # doctest: +IGNORE_UNICODE + '3dBrickStat -min -mask skeleton_mask.nii.gz functional.nii' + >>> res = brickstat.run() # doctest: +SKIP """ _cmd = '3dBrickStat' @@ -294,23 +298,24 @@ class CalcInputSpec(AFNICommandInputSpec): class Calc(AFNICommand): - """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.interfaces import afni >>> calc = afni.Calc() >>> calc.inputs.in_file_a = 'functional.nii' >>> calc.inputs.in_file_b = 'functional2.nii' >>> calc.inputs.expr='a*b' >>> calc.inputs.out_file = 'functional_calc.nii.gz' >>> calc.inputs.outputtype = 'NIFTI' - >>> calc.cmdline #doctest: +ELLIPSIS +IGNORE_UNICODE + >>> calc.cmdline # doctest: +ELLIPSIS +IGNORE_UNICODE '3dcalc -a functional.nii -b functional2.nii -expr "a*b" -prefix functional_calc.nii.gz' + >>> res = calc.run() # doctest: +SKIP """ @@ -357,32 +362,37 @@ class Copy(AFNICommand): or different type using 3dcopy command For complete details, see the `3dcopy Documentation. - `_ + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> copy3d = afni.Copy() >>> copy3d.inputs.in_file = 'functional.nii' >>> copy3d.cmdline # doctest: +IGNORE_UNICODE '3dcopy functional.nii functional_copy' + >>> res = copy3d.run() # doctest: +SKIP >>> from copy import deepcopy >>> copy3d_2 = deepcopy(copy3d) >>> copy3d_2.inputs.outputtype = 'NIFTI' >>> copy3d_2.cmdline # doctest: +IGNORE_UNICODE '3dcopy functional.nii functional_copy.nii' + >>> res = copy3d_2.run() # doctest: +SKIP >>> copy3d_3 = deepcopy(copy3d) >>> copy3d_3.inputs.outputtype = 'NIFTI_GZ' >>> copy3d_3.cmdline # doctest: +IGNORE_UNICODE '3dcopy functional.nii functional_copy.nii.gz' + >>> res = copy3d_3.run() # doctest: +SKIP >>> copy3d_4 = deepcopy(copy3d) >>> copy3d_4.inputs.out_file = 'new_func.nii' >>> copy3d_4.cmdline # doctest: +IGNORE_UNICODE '3dcopy functional.nii new_func.nii' + >>> res = copy3d_4.run() # doctest: +SKIP + """ _cmd = '3dcopy' @@ -434,22 +444,25 @@ class EvalInputSpec(AFNICommandInputSpec): class Eval(AFNICommand): - """Evaluates an expression that may include columns of data from one or more text files + """Evaluates an expression that may include columns of data from one or + more text files. - see AFNI Documentation: + For complete details, see the `1deval Documentation. + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> eval = afni.Eval() >>> eval.inputs.in_file_a = 'seed.1D' >>> eval.inputs.in_file_b = 'resp.1D' - >>> eval.inputs.expr='a*b' + >>> eval.inputs.expr = 'a*b' >>> eval.inputs.out1D = True >>> eval.inputs.out_file = 'data_calc.1D' - >>> calc.cmdline #doctest: +SKIP +IGNORE_UNICODE - '3deval -a timeseries1.1D -b timeseries2.1D -expr "a*b" -1D -prefix data_calc.1D' + >>> eval.cmdline # doctest: +IGNORE_UNICODE + '1deval -a seed.1D -b resp.1D -expr "a*b" -1D -prefix data_calc.1D' + >>> res = eval.run() # doctest: +SKIP """ @@ -472,7 +485,7 @@ def _parse_inputs(self, skip=None): """Skip the arguments without argstr metadata """ return super(Eval, self)._parse_inputs( - skip=('start_idx', 'stop_idx', 'out1D', 'other')) + skip=('start_idx', 'stop_idx', 'other')) class FWHMxInputSpec(CommandLineInputSpec): @@ -589,14 +602,18 @@ class FWHMx(AFNICommandBase): output value indicates something bad happened; e.g., FWHM in z is meaningless for a 2D dataset; the estimation method computed incoherent intermediate results.) + For complete details, see the `3dFWHMx Documentation. + `_ + Examples -------- - >>> from nipype.interfaces import afni as afp - >>> fwhm = afp.FWHMx() + >>> from nipype.interfaces import afni + >>> fwhm = afni.FWHMx() >>> fwhm.inputs.in_file = 'functional.nii' >>> fwhm.cmdline # doctest: +IGNORE_UNICODE '3dFWHMx -input functional.nii -out functional_subbricks.out > functional_fwhmx.out' + >>> res = fwhm.run() # doctest: +SKIP (Classic) METHOD: @@ -807,14 +824,13 @@ class MaskTool(AFNICommand): Examples ======== - >>> from nipype.interfaces import afni as afni - >>> automask = afni.Automask() - >>> automask.inputs.in_file = 'functional.nii' - >>> automask.inputs.dilate = 1 - >>> automask.inputs.outputtype = 'NIFTI' - >>> automask.cmdline #doctest: +ELLIPSIS +IGNORE_UNICODE - '3dAutomask -apply_prefix functional_masked.nii -dilate 1 -prefix functional_mask.nii functional.nii' - >>> res = automask.run() # doctest: +SKIP + >>> from nipype.interfaces import afni + >>> masktool = afni.MaskTool() + >>> masktool.inputs.in_file = 'functional.nii' + >>> masktool.inputs.outputtype = 'NIFTI' + >>> masktool.cmdline # doctest: +IGNORE_UNICODE + '3dmask_tool -prefix functional_mask.nii -input functional.nii' + >>> res = automask.run() # doctest: +SKIP """ @@ -850,18 +866,20 @@ 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.interfaces import afni >>> merge = afni.Merge() >>> merge.inputs.in_files = ['functional.nii', 'functional2.nii'] >>> merge.inputs.blurfwhm = 4 >>> merge.inputs.doall = True >>> merge.inputs.out_file = 'e7.nii' - >>> res = merge.run() # doctest: +SKIP + >>> merge.cmdline # doctest: +IGNORE_UNICODE + '3dmerge -1blur_fwhm 4 -doall -prefix e7.nii functional.nii functional2.nii' + >>> res = merge.run() # doctest: +SKIP """ @@ -901,11 +919,10 @@ class NotesInputSpec(AFNICommandInputSpec): class Notes(CommandLine): - """ - A program to add, delete, and show notes for AFNI datasets. + """A program to add, delete, and show notes for AFNI datasets. For complete details, see the `3dNotes Documentation. - + `_ Examples ======== @@ -915,9 +932,9 @@ class Notes(CommandLine): >>> notes.inputs.in_file = 'functional.HEAD' >>> notes.inputs.add = 'This note is added.' >>> notes.inputs.add_history = 'This note is added to history.' - >>> notes.cmdline #doctest: +IGNORE_UNICODE + >>> notes.cmdline # doctest: +IGNORE_UNICODE '3dNotes -a "This note is added." -h "This note is added to history." functional.HEAD' - >>> res = notes.run() # doctest: +SKIP + >>> res = notes.run() # doctest: +SKIP """ _cmd = '3dNotes' @@ -970,18 +987,18 @@ class Refit(AFNICommandBase): """Changes some of the information inside a 3D dataset's header For complete details, see the `3drefit Documentation. - + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> refit = afni.Refit() >>> refit.inputs.in_file = 'structural.nii' >>> refit.inputs.deoblique = True >>> refit.cmdline # doctest: +IGNORE_UNICODE '3drefit -deoblique structural.nii' - >>> res = refit.run() # doctest: +SKIP + >>> res = refit.run() # doctest: +SKIP """ _cmd = '3drefit' @@ -1030,19 +1047,19 @@ 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.interfaces import afni >>> resample = afni.Resample() >>> resample.inputs.in_file = 'functional.nii' >>> resample.inputs.orientation= 'RPI' >>> resample.inputs.outputtype = 'NIFTI' >>> resample.cmdline # doctest: +IGNORE_UNICODE '3dresample -orient RPI -prefix functional_resample.nii -inset functional.nii' - >>> res = resample.run() # doctest: +SKIP + >>> res = resample.run() # doctest: +SKIP """ @@ -1065,28 +1082,37 @@ class TCatInputSpec(AFNICommandInputSpec): desc='output image file name', argstr='-prefix %s', name_source='in_files') - rlt = Str( - desc='options', + rlt = traits.Enum( + '', '+', '++', argstr='-rlt%s', + desc='Remove linear trends in each voxel time series loaded from each ' + 'input dataset, SEPARATELY. Option -rlt removes the least squares ' + 'fit of \'a+b*t\' to each voxel time series. Option -rlt+ adds ' + 'dataset mean back in. Option -rlt++ adds overall mean of all ' + 'dataset timeseries back in.', position=1) 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. + + TODO Replace InputMultiPath in_files with Traits.List, if possible. Current + version adds extra whitespace. For complete details, see the `3dTcat Documentation. - `_ + `_ Examples ======== - >>> from nipype.interfaces import afni as afni + >>> from nipype.interfaces import afni >>> tcat = afni.TCat() >>> tcat.inputs.in_files = ['functional.nii', 'functional2.nii'] >>> tcat.inputs.out_file= 'functional_tcat.nii' >>> tcat.inputs.rlt = '+' - >>> res = tcat.run() # doctest: +SKIP + >>> tcat.cmdline # doctest: +IGNORE_UNICODE +NORMALIZE_WHITESPACE + '3dTcat -rlt+ -prefix functional_tcat.nii functional.nii functional2.nii' + >>> res = tcat.run() # doctest: +SKIP """ @@ -1121,19 +1147,19 @@ 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.interfaces import afni >>> tstat = afni.TStat() >>> tstat.inputs.in_file = 'functional.nii' - >>> tstat.inputs.args= '-mean' + >>> tstat.inputs.args = '-mean' >>> tstat.inputs.out_file = 'stats' >>> tstat.cmdline # doctest: +IGNORE_UNICODE '3dTstat -mean -prefix stats functional.nii' - >>> res = tstat.run() # doctest: +SKIP + >>> res = tstat.run() # doctest: +SKIP """ @@ -1182,22 +1208,23 @@ class To3D(AFNICommand): """Create a 3D dataset from 2D image files using AFNI to3d command For complete details, see the `to3d Documentation - `_ + `_ Examples ======== >>> from nipype.interfaces import afni - >>> To3D = afni.To3D() - >>> To3D.inputs.datatype = 'float' - >>> To3D.inputs.in_folder = '.' - >>> To3D.inputs.out_file = 'dicomdir.nii' - >>> To3D.inputs.filetype = 'anat' - >>> To3D.cmdline #doctest: +ELLIPSIS +IGNORE_UNICODE + >>> to3d = afni.To3D() + >>> to3d.inputs.datatype = 'float' + >>> to3d.inputs.in_folder = '.' + >>> to3d.inputs.out_file = 'dicomdir.nii' + >>> to3d.inputs.filetype = 'anat' + >>> to3d.cmdline # doctest: +ELLIPSIS +IGNORE_UNICODE 'to3d -datum float -anat -prefix dicomdir.nii ./*.dcm' - >>> res = To3D.run() #doctest: +SKIP + >>> res = to3d.run() # doctest: +SKIP """ + _cmd = 'to3d' input_spec = To3DInputSpec output_spec = AFNICommandOutputSpec @@ -1225,17 +1252,19 @@ class ZCutUp(AFNICommand): """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.interfaces import afni >>> zcutup = afni.ZCutUp() >>> zcutup.inputs.in_file = 'functional.nii' >>> zcutup.inputs.out_file = 'functional_zcutup.nii' >>> zcutup.inputs.keep= '0 10' - >>> res = zcutup.run() # doctest: +SKIP + >>> zcutup.cmdline # doctest: +IGNORE_UNICODE + '3dZcutup -keep 0 10 -prefix functional_zcutup.nii functional.nii' + >>> res = zcutup.run() # doctest: +SKIP """