diff --git a/nipype/interfaces/fsl/base.py b/nipype/interfaces/fsl/base.py index 548ef53e92..3457541664 100644 --- a/nipype/interfaces/fsl/base.py +++ b/nipype/interfaces/fsl/base.py @@ -22,7 +22,7 @@ Examples -------- -See the docstrings of the individual classes for examples. +See the docstrings of the individual classes for examples. """ from __future__ import print_function, division, unicode_literals, absolute_import @@ -263,4 +263,5 @@ def no_fsl(): def no_fsl_course_data(): """check if fsl_course data is present""" - return not ('FSL_COURSE_DATA' in os.environ and os.path.isdir(os.path.abspath(os.environ['FSL_COURSE_DATA']))) + return not ('FSL_COURSE_DATA' in os.environ and + os.path.isdir(os.path.abspath(os.environ['FSL_COURSE_DATA']))) diff --git a/nipype/interfaces/fsl/dti.py b/nipype/interfaces/fsl/dti.py index ade78ac576..8e394392b7 100644 --- a/nipype/interfaces/fsl/dti.py +++ b/nipype/interfaces/fsl/dti.py @@ -26,7 +26,8 @@ class DTIFitInputSpec(FSLCommandInputSpec): dwi = File(exists=True, desc='diffusion weighted image data file', argstr='-k %s', position=0, mandatory=True) - base_name = traits.Str("dtifit_", desc='base_name that all output files will start with', + base_name = traits.Str("dtifit_", desc=('base_name that all output files ' + 'will start with'), argstr='-o %s', position=1, usedefault=True) mask = File(exists=True, desc='bet binary mask file', argstr='-m %s', position=2, mandatory=True) @@ -43,7 +44,8 @@ class DTIFitInputSpec(FSLCommandInputSpec): save_tensor = traits.Bool(desc='save the elements of the tensor', argstr='--save_tensor') sse = traits.Bool(desc='output sum of squared errors', argstr='--sse') - cni = File(exists=True, desc='input counfound regressors', argstr='--cni=%s') + cni = File(exists=True, desc='input counfound regressors', + argstr='--cni=%s') little_bit = traits.Bool(desc='only process small area of brain', argstr='--littlebit') gradnonlin = File(exists=True, argstr='--gradnonlin=%s', @@ -58,11 +60,15 @@ class DTIFitOutputSpec(TraitedSpec): L2 = File(exists=True, desc='path/name of file with the 2nd eigenvalue') L3 = File(exists=True, desc='path/name of file with the 3rd eigenvalue') MD = File(exists=True, desc='path/name of file with the mean diffusivity') - FA = File(exists=True, desc='path/name of file with the fractional anisotropy') - MO = File(exists=True, desc='path/name of file with the mode of anisotropy') - S0 = File(exists=True, desc='path/name of file with the raw T2 signal with no ' + - 'diffusion weighting') - tensor = File(exists=True, desc='path/name of file with the 4D tensor volume') + FA = File(exists=True, + desc='path/name of file with the fractional anisotropy') + MO = File(exists=True, + desc='path/name of file with the mode of anisotropy') + S0 = File(exists=True, + desc=('path/name of file with the raw T2 signal with no ' + 'diffusion weighting')) + tensor = File(exists=True, + desc='path/name of file with the 4D tensor volume') class DTIFit(FSLCommand): @@ -94,7 +100,8 @@ def _list_outputs(self): if k not in ('outputtype', 'environ', 'args'): if k != 'tensor' or (isdefined(self.inputs.save_tensor) and self.inputs.save_tensor): - outputs[k] = self._gen_fname(self.inputs.base_name, suffix='_' + k) + outputs[k] = self._gen_fname( + self.inputs.base_name, suffix='_' + k) return outputs @@ -168,16 +175,22 @@ class FSLXCommandOutputSpec(TraitedSpec): dyads = OutputMultiPath(File(exists=True), desc=('Mean of PDD distribution' ' in vector form.')) fsamples = OutputMultiPath(File(exists=True), desc=('Samples from the ' - 'distribution on f anisotropy')) - mean_dsamples = File(exists=True, desc='Mean of distribution on diffusivity d') - mean_fsamples = OutputMultiPath(File(exists=True), desc=('Mean of ' - 'distribution on f anisotropy')) + 'distribution on f ' + 'anisotropy')) + mean_dsamples = File(exists=True, + desc='Mean of distribution on diffusivity d') + mean_fsamples = OutputMultiPath(File(exists=True), + desc=('Mean of distribution on f ' + 'anisotropy')) mean_S0samples = File(exists=True, desc=('Mean of distribution on T2w' 'baseline signal intensity S0')) mean_tausamples = File(exists=True, desc=('Mean of distribution on ' - 'tau samples (only with rician noise)')) - phsamples = OutputMultiPath(File(exists=True), desc=('phi samples, per fiber')) - thsamples = OutputMultiPath(File(exists=True), desc=('theta samples, per fiber')) + 'tau samples (only with rician ' + 'noise)')) + phsamples = OutputMultiPath(File(exists=True), + desc=('phi samples, per fiber')) + thsamples = OutputMultiPath(File(exists=True), + desc=('theta samples, per fiber')) class FSLXCommand(FSLCommand): @@ -220,8 +233,8 @@ def _list_outputs(self, out_dir=None): for i in range(1, n_fibres + 1): outputs['fsamples'].append(self._gen_fname('f%dsamples' % i, cwd=out_dir)) - outputs['mean_fsamples'].append(self._gen_fname(('mean_f%d' - 'samples') % i, cwd=out_dir)) + outputs['mean_fsamples'].append( + self._gen_fname('mean_f%dsamples' % i, cwd=out_dir)) for i in range(1, n_fibres + 1): outputs['dyads'].append(self._gen_fname('dyads%d' % i, @@ -259,31 +272,37 @@ class BEDPOSTX5InputSpec(FSLXCommandInputSpec): desc='Num of jumps for each sample (MCMC)') out_dir = Directory('bedpostx', mandatory=True, desc='output directory', usedefault=True, position=1, argstr='%s') - gradnonlin = traits.Bool(False, argstr='-g', desc=('consider gradient ' - 'nonlinearities, default off')) - grad_dev = File(exists=True, desc='grad_dev file, if gradnonlin, -g is True') + gradnonlin = traits.Bool(False, argstr='-g', + desc=('consider gradient nonlinearities, ' + 'default off')) + grad_dev = File(exists=True, + desc='grad_dev file, if gradnonlin, -g is True') use_gpu = traits.Bool(False, desc='Use the GPU version of bedpostx') class BEDPOSTX5OutputSpec(TraitedSpec): - mean_dsamples = File(exists=True, desc='Mean of distribution on diffusivity d') - mean_fsamples = OutputMultiPath(File(exists=True), desc=('Mean of ' - 'distribution on f anisotropy')) + mean_dsamples = File(exists=True, + desc='Mean of distribution on diffusivity d') + mean_fsamples = OutputMultiPath(File(exists=True), + desc=('Mean of distribution on f ' + 'anisotropy')) mean_S0samples = File(exists=True, desc=('Mean of distribution on T2w' 'baseline signal intensity S0')) - mean_phsamples = OutputMultiPath(File(exists=True), desc=('Mean of ' - 'distribution on phi')) - mean_thsamples = OutputMultiPath(File(exists=True), desc=('Mean of ' - 'distribution on theta')) - merged_thsamples = OutputMultiPath(File(exists=True), desc=('Samples from ' - 'the distribution on theta')) - merged_phsamples = OutputMultiPath(File(exists=True), desc=('Samples from ' - 'the distribution on phi')) + mean_phsamples = OutputMultiPath(File(exists=True), + desc='Mean of distribution on phi') + mean_thsamples = OutputMultiPath(File(exists=True), + desc='Mean of distribution on theta') + merged_thsamples = OutputMultiPath(File(exists=True), + desc=('Samples from the distribution ' + 'on theta')) + merged_phsamples = OutputMultiPath(File(exists=True), + desc=('Samples from the distribution ' + 'on phi')) merged_fsamples = OutputMultiPath(File(exists=True), desc=('Samples from the distribution on ' 'anisotropic volume fraction')) - dyads = OutputMultiPath(File(exists=True), desc=('Mean of PDD distribution' - ' in vector form.')) + dyads = OutputMultiPath(File(exists=True), + desc='Mean of PDD distribution in vector form.') dyads_dispersion = OutputMultiPath(File(exists=True), desc=('Dispersion')) @@ -373,23 +392,22 @@ def _list_outputs(self): outputs[k] = [] for i in range(1, n_fibres + 1): - outputs['merged_thsamples'].append(self._gen_fname('merged_th%dsamples' % i, - cwd=self._out_dir)) - outputs['merged_fsamples'].append(self._gen_fname('merged_f%dsamples' % i, - cwd=self._out_dir)) - outputs['merged_phsamples'].append(self._gen_fname('merged_ph%dsamples' % i, - cwd=self._out_dir)) - - outputs['mean_thsamples'].append(self._gen_fname('mean_th%dsamples' % i, - cwd=self._out_dir)) - outputs['mean_phsamples'].append(self._gen_fname('mean_ph%dsamples' % i, - cwd=self._out_dir)) - outputs['mean_fsamples'].append(self._gen_fname('mean_f%dsamples' % i, - cwd=self._out_dir)) - outputs['dyads'].append(self._gen_fname('dyads%d' % i, - cwd=self._out_dir)) - outputs['dyads_dispersion'].append(self._gen_fname('dyads%d_dispersion' % i, - cwd=self._out_dir)) + outputs['merged_thsamples'].append( + self._gen_fname('merged_th%dsamples' % i, cwd=self._out_dir)) + outputs['merged_fsamples'].append( + self._gen_fname('merged_f%dsamples' % i, cwd=self._out_dir)) + outputs['merged_phsamples'].append( + self._gen_fname('merged_ph%dsamples' % i, cwd=self._out_dir)) + outputs['mean_thsamples'].append( + self._gen_fname('mean_th%dsamples' % i, cwd=self._out_dir)) + outputs['mean_phsamples'].append( + self._gen_fname('mean_ph%dsamples' % i, cwd=self._out_dir)) + outputs['mean_fsamples'].append( + self._gen_fname('mean_f%dsamples' % i, cwd=self._out_dir)) + outputs['dyads'].append( + self._gen_fname('dyads%d' % i, cwd=self._out_dir)) + outputs['dyads_dispersion'].append( + self._gen_fname('dyads%d_dispersion' % i, cwd=self._out_dir)) return outputs @@ -415,94 +433,141 @@ class ProbTrackXBaseInputSpec(FSLCommandInputSpec): thsamples = InputMultiPath(File(exists=True), mandatory=True) phsamples = InputMultiPath(File(exists=True), mandatory=True) fsamples = InputMultiPath(File(exists=True), mandatory=True) - samples_base_name = traits.Str("merged", desc='the rootname/base_name for samples files', + samples_base_name = traits.Str("merged", + desc=('the rootname/base_name for samples ' + 'files'), argstr='--samples=%s', usedefault=True) mask = File(exists=True, desc='bet binary mask file in diffusion space', argstr='-m %s', mandatory=True) seed = traits.Either(File(exists=True), traits.List(File(exists=True)), - traits.List(traits.List(traits.Int(), minlen=3, maxlen=3)), - desc='seed volume(s), or voxel(s)' + - 'or freesurfer label file', + traits.List(traits.List(traits.Int(), + minlen=3, maxlen=3)), + desc=('seed volume(s), or voxel(s) or freesurfer ' + 'label file'), argstr='--seed=%s', mandatory=True) - target_masks = InputMultiPath(File(exits=True), desc='list of target masks - ' + - 'required for seeds_to_targets classification', argstr='--targetmasks=%s') - waypoints = File(exists=True, desc='waypoint mask or ascii list of waypoint masks - ' + - 'only keep paths going through ALL the masks', argstr='--waypoints=%s') - network = traits.Bool(desc='activate network mode - only keep paths going through ' + - 'at least one seed mask (required if multiple seed masks)', + target_masks = InputMultiPath(File(exits=True), + desc=('list of target masks - required for ' + 'seeds_to_targets classification'), + argstr='--targetmasks=%s') + waypoints = File(exists=True, + desc=('waypoint mask or ascii list of waypoint masks - ' + 'only keep paths going through ALL the masks'), + argstr='--waypoints=%s') + network = traits.Bool(desc=('activate network mode - only keep paths ' + 'going through at least one seed mask ' + '(required if multiple seed masks)'), argstr='--network') - seed_ref = File(exists=True, desc='reference vol to define seed space in ' + - 'simple mode - diffusion space assumed if absent', + seed_ref = File(exists=True, + desc=('reference vol to define seed space in simple mode ' + '- diffusion space assumed if absent'), argstr='--seedref=%s') out_dir = Directory(exists=True, argstr='--dir=%s', - desc='directory to put the final volumes in', genfile=True) - force_dir = traits.Bool(True, desc='use the actual directory name given - i.e. ' + - 'do not add + to make a new directory', argstr='--forcedir', - usedefault=True) - opd = traits.Bool(True, desc='outputs path distributions', argstr='--opd', usedefault=True) - correct_path_distribution = traits.Bool(desc='correct path distribution for the length of the pathways', + desc='directory to put the final volumes in', + genfile=True) + force_dir = traits.Bool(True, + desc=('use the actual directory name given - i.e. ' + 'do not add + to make a new directory'), + argstr='--forcedir', usedefault=True) + opd = traits.Bool(True, desc='outputs path distributions', + argstr='--opd', usedefault=True) + correct_path_distribution = traits.Bool(desc=('correct path distribution ' + 'for the length of the ' + 'pathways'), argstr='--pd') os2t = traits.Bool(desc='Outputs seeds to targets', argstr='--os2t') # paths_file = File('nipype_fdtpaths', usedefault=True, argstr='--out=%s', # desc='produces an output file (default is fdt_paths)') - avoid_mp = File(exists=True, desc='reject pathways passing through locations given by this mask', + avoid_mp = File(exists=True, + desc=('reject pathways passing through locations given by ' + 'this mask'), argstr='--avoid=%s') stop_mask = File(exists=True, argstr='--stop=%s', desc='stop tracking at locations given by this mask file') xfm = File(exists=True, argstr='--xfm=%s', - desc='transformation matrix taking seed space to DTI space ' + - '(either FLIRT matrix or FNIRT warp_field) - default is identity') - inv_xfm = File(argstr='--invxfm=%s', desc='transformation matrix taking DTI space to seed' + - ' space (compulsory when using a warp_field for seeds_to_dti)') + desc=('transformation matrix taking seed space to DTI space ' + '(either FLIRT matrix or FNIRT warp_field) - default is ' + 'identity')) + inv_xfm = File(argstr='--invxfm=%s', + desc=('transformation matrix taking DTI space to seed ' + 'space (compulsory when using a warp_field for ' + 'seeds_to_dti)')) n_samples = traits.Int(5000, argstr='--nsamples=%d', - desc='number of samples - default=5000', usedefault=True) - n_steps = traits.Int(argstr='--nsteps=%d', desc='number of steps per sample - default=2000') - dist_thresh = traits.Float(argstr='--distthresh=%.3f', desc='discards samples shorter than ' + - 'this threshold (in mm - default=0)') - c_thresh = traits.Float(argstr='--cthr=%.3f', desc='curvature threshold - default=0.2') - sample_random_points = traits.Bool(argstr='--sampvox', desc='sample random points within seed voxels') - step_length = traits.Float(argstr='--steplength=%.3f', desc='step_length in mm - default=0.5') - loop_check = traits.Bool(argstr='--loopcheck', desc='perform loop_checks on paths -' + - ' slower, but allows lower curvature threshold') - use_anisotropy = traits.Bool(argstr='--usef', desc='use anisotropy to constrain tracking') + desc='number of samples - default=5000', + usedefault=True) + n_steps = traits.Int(argstr='--nsteps=%d', + desc='number of steps per sample - default=2000') + dist_thresh = traits.Float(argstr='--distthresh=%.3f', + desc=('discards samples shorter than this ' + 'threshold (in mm - default=0)')) + c_thresh = traits.Float(argstr='--cthr=%.3f', + desc='curvature threshold - default=0.2') + sample_random_points = traits.Bool(argstr='--sampvox', + desc=('sample random points within ' + 'seed voxels')) + step_length = traits.Float(argstr='--steplength=%.3f', + desc='step_length in mm - default=0.5') + loop_check = traits.Bool(argstr='--loopcheck', + desc=('perform loop_checks on paths - slower, ' + 'but allows lower curvature threshold')) + use_anisotropy = traits.Bool(argstr='--usef', + desc='use anisotropy to constrain tracking') rand_fib = traits.Enum(0, 1, 2, 3, argstr='--randfib=%d', - desc='options: 0 - default, 1 - to randomly sample' + - ' initial fibres (with f > fibthresh), 2 - to sample in ' + - 'proportion fibres (with f>fibthresh) to f, 3 - to sample ALL ' + - 'populations at random (even if f fibthresh), ' + '2 - to sample in proportion fibres (with ' + 'f>fibthresh) to f, 3 - to sample ALL ' + 'populations at random (even if ' + 'f LooseVersion('5.0.6'): input_spec = FILMGLSInputSpec507 - elif Info.version() and LooseVersion(Info.version()) > LooseVersion('5.0.4'): + elif (Info.version() and + LooseVersion(Info.version()) > LooseVersion('5.0.4')): input_spec = FILMGLSInputSpec505 else: input_spec = FILMGLSInputSpec @@ -702,14 +724,16 @@ def _list_outputs(self): cwd=results_dir) outputs['thresholdac'] = self._gen_fname('threshac1.nii', cwd=results_dir) - if Info.version() and LooseVersion(Info.version()) < LooseVersion('5.0.7'): + if (Info.version() and + LooseVersion(Info.version()) < LooseVersion('5.0.7')): outputs['corrections'] = self._gen_fname('corrections.nii', cwd=results_dir) outputs['logfile'] = self._gen_fname('logfile', change_ext=False, cwd=results_dir) - if Info.version() and LooseVersion(Info.version()) > LooseVersion('5.0.6'): + if (Info.version() and + LooseVersion(Info.version()) > LooseVersion('5.0.6')): pth = results_dir numtcons, numfcons = self._get_numcons() base_contrast = 1 @@ -719,15 +743,15 @@ def _list_outputs(self): tstats = [] neffs = [] for i in range(numtcons): - copes.append(self._gen_fname('cope%d.nii' % (base_contrast + i), - cwd=pth)) + copes.append(self._gen_fname( + 'cope%d.nii' % (base_contrast + i), cwd=pth)) varcopes.append( self._gen_fname('varcope%d.nii' % (base_contrast + i), cwd=pth)) - zstats.append(self._gen_fname('zstat%d.nii' % (base_contrast + i), - cwd=pth)) - tstats.append(self._gen_fname('tstat%d.nii' % (base_contrast + i), - cwd=pth)) + zstats.append(self._gen_fname( + 'zstat%d.nii' % (base_contrast + i), cwd=pth)) + tstats.append(self._gen_fname( + 'tstat%d.nii' % (base_contrast + i), cwd=pth)) if copes: outputs['copes'] = copes outputs['varcopes'] = varcopes @@ -736,11 +760,11 @@ def _list_outputs(self): fstats = [] zfstats = [] for i in range(numfcons): - fstats.append(self._gen_fname('fstat%d.nii' % (base_contrast + i), - cwd=pth)) + fstats.append(self._gen_fname( + 'fstat%d.nii' % (base_contrast + i), cwd=pth)) zfstats.append( - self._gen_fname('zfstat%d.nii' % (base_contrast + i), - cwd=pth)) + self._gen_fname( + 'zfstat%d.nii' % (base_contrast + i), cwd=pth)) if fstats: outputs['fstats'] = fstats outputs['zfstats'] = zfstats @@ -820,7 +844,8 @@ class FLAMEOInputSpec(FSLCommandInputSpec): n_jumps = traits.Int( argstr='--njumps=%d', desc='number of jumps made by mcmc') burnin = traits.Int(argstr='--burnin=%d', - desc='number of jumps at start of mcmc to be discarded') + desc=('number of jumps at start of mcmc to be ' + 'discarded')) sample_every = traits.Int(argstr='--sampleevery=%d', desc='number of jumps for each sample') fix_mean = traits.Bool(argstr='--fixmean', desc='fix mean for tfit') @@ -829,9 +854,12 @@ class FLAMEOInputSpec(FSLCommandInputSpec): no_pe_outputs = traits.Bool(argstr='--nopeoutput', desc='do not output pe files') sigma_dofs = traits.Int(argstr='--sigma_dofs=%d', - desc='sigma (in mm) to use for Gaussian smoothing the DOFs in FLAME 2. Default is 1mm, -1 indicates no smoothing') + desc=('sigma (in mm) to use for Gaussian ' + 'smoothing the DOFs in FLAME 2. Default is ' + '1mm, -1 indicates no smoothing')) outlier_iter = traits.Int(argstr='--ioni=%d', - desc='Number of max iterations to use when inferring outliers. Default is 12.') + desc=('Number of max iterations to use when ' + 'inferring outliers. Default is 12.')) log_dir = Directory("stats", argstr='--ld=%s', usedefault=True) # ohinds # no support for ven, vef @@ -975,18 +1003,24 @@ class ContrastMgrInputSpec(FSLCommandInputSpec): param_estimates = InputMultiPath(File(exists=True), argstr='', copyfile=False, mandatory=True, - desc='Parameter estimates for each column of the design matrix') - corrections = File(exists=True, copyfile=False, mandatory=True, - desc='statistical corrections used within FILM modelling') + desc=('Parameter estimates for each ' + 'column of the design matrix')) + corrections = File( + exists=True, copyfile=False, mandatory=True, + desc='statistical corrections used within FILM modelling') dof_file = File(exists=True, argstr='', copyfile=False, mandatory=True, desc='degrees of freedom') sigmasquareds = File(exists=True, argstr='', position=-2, copyfile=False, mandatory=True, - desc='summary of residuals, See Woolrich, et. al., 2001') + desc=('summary of residuals, See Woolrich, et. al., ' + '2001')) contrast_num = traits.Range(low=1, argstr='-cope', - desc='contrast number to start labeling copes from') + desc=('contrast number to start labeling ' + 'copes from')) suffix = traits.Str(argstr='-suffix %s', - desc='suffix to put on the end of the cope filename before the contrast number, default is nothing') + desc=('suffix to put on the end of the cope filename ' + 'before the contrast number, default is ' + 'nothing')) class ContrastMgrOutputSpec(TraitedSpec): @@ -1033,7 +1067,8 @@ def _format_arg(self, name, trait_spec, value): path, _ = os.path.split(value) return path else: - return super(ContrastMgr, self)._format_arg(name, trait_spec, value) + return super(ContrastMgr, self)._format_arg( + name, trait_spec, value) def _get_design_root(self, infile): _, fname = os.path.split(infile) @@ -1200,9 +1235,11 @@ class MultipleRegressDesignInputSpec(BaseInterfaceInputSpec): T-contrasts without any weight list.") regressors = traits.Dict(traits.Str, traits.List(traits.Float), mandatory=True, - desc='dictionary containing named lists of regressors') + desc=('dictionary containing named lists of ' + 'regressors')) groups = traits.List(traits.Int, - desc='list of group identifiers (defaults to single group)') + desc=('list of group identifiers (defaults to single ' + 'group)')) class MultipleRegressDesignOutputSpec(TraitedSpec): @@ -1218,7 +1255,8 @@ class MultipleRegressDesign(BaseInterface): .. note:: FSL does not demean columns for higher level analysis. - Please see `FSL documentation `_ + Please see `FSL documentation + `_ for more details on model specification for higher level analysis. Examples @@ -1357,9 +1395,10 @@ class SMMOutputSpec(TraitedSpec): class SMM(FSLCommand): ''' - Spatial Mixture Modelling. For more detail on the spatial mixture modelling see - Mixture Models with Adaptive Spatial Regularisation for Segmentation with an Application to FMRI Data; - Woolrich, M., Behrens, T., Beckmann, C., and Smith, S.; IEEE Trans. Medical Imaging, 24(1):1-11, 2005. + Spatial Mixture Modelling. For more detail on the spatial mixture modelling + see Mixture Models with Adaptive Spatial Regularisation for Segmentation + with an Application to FMRI Data; Woolrich, M., Behrens, T., Beckmann, C., + and Smith, S.; IEEE Trans. Medical Imaging, 24(1):1-11, 2005. ''' _cmd = 'mm --ld=logdir' input_spec = SMMInputSpec @@ -1372,7 +1411,8 @@ def _list_outputs(self): cwd="logdir") outputs['activation_p_map'] = self._gen_fname( basename="w2_mean", cwd="logdir") - if not isdefined(self.inputs.no_deactivation_class) or not self.inputs.no_deactivation_class: + if (not isdefined(self.inputs.no_deactivation_class) or not + self.inputs.no_deactivation_class): outputs['deactivation_p_map'] = self._gen_fname( basename="w3_mean", cwd="logdir") return outputs @@ -1392,36 +1432,49 @@ class MELODICInputSpec(FSLCommandInputSpec): argstr="--update_mask", desc="switch off mask updating") no_bet = traits.Bool(argstr="--nobet", desc="switch off BET") bg_threshold = traits.Float( - argstr="--bgthreshold=%f", desc="brain/non-brain threshold used to mask non-brain voxels, as a percentage (only if --nobet selected)") - dim = traits.Int(argstr="-d %d", desc="dimensionality reduction into #num dimensions" - "(default: automatic estimation)") - dim_est = traits.Str(argstr="--dimest=%s", desc="use specific dim. estimation technique:" - " lap, bic, mdl, aic, mean (default: lap)") + argstr="--bgthreshold=%f", + desc=("brain/non-brain threshold used to mask non-brain voxels, as a " + "percentage (only if --nobet selected)")) + dim = traits.Int( + argstr="-d %d", + desc=("dimensionality reduction into #num dimensions (default: " + "automatic estimation)")) + dim_est = traits.Str(argstr="--dimest=%s", + desc=("use specific dim. estimation technique: lap, " + "bic, mdl, aic, mean (default: lap)")) sep_whiten = traits.Bool( argstr="--sep_whiten", desc="switch on separate whitening") sep_vn = traits.Bool( argstr="--sep_vn", desc="switch off joined variance normalization") num_ICs = traits.Int( - argstr="-n %d", desc="number of IC's to extract (for deflation approach)") - approach = traits.Str(argstr="-a %s", desc="approach for decomposition, 2D: defl, symm (default), " - " 3D: tica (default), concat") + argstr="-n %d", + desc="number of IC's to extract (for deflation approach)") + approach = traits.Str( + argstr="-a %s", + desc="approach for decomposition, 2D: defl, symm (default), 3D: tica " + "(default), concat") non_linearity = traits.Str( argstr="--nl=%s", desc="nonlinearity: gauss, tanh, pow3, pow4") var_norm = traits.Bool( argstr="--vn", desc="switch off variance normalization") pbsc = traits.Bool( - argstr="--pbsc", desc="switch off conversion to percent BOLD signal change") - cov_weight = traits.Float(argstr="--covarweight=%f", desc="voxel-wise weights for the covariance " - "matrix (e.g. segmentation information)") + argstr="--pbsc", + desc="switch off conversion to percent BOLD signal change") + cov_weight = traits.Float( + argstr="--covarweight=%f", + desc=("voxel-wise weights for the covariance matrix (e.g. " + "segmentation information)")) epsilon = traits.Float(argstr="--eps=%f", desc="minimum error change") epsilonS = traits.Float( - argstr="--epsS=%f", desc="minimum error change for rank-1 approximation in TICA") + argstr="--epsS=%f", + desc="minimum error change for rank-1 approximation in TICA") maxit = traits.Int(argstr="--maxit=%d", desc="maximum number of iterations before restart") max_restart = traits.Int( argstr="--maxrestart=%d", desc="maximum number of restarts") mm_thresh = traits.Float( - argstr="--mmthresh=%f", desc="threshold for Mixture Model based inference") + argstr="--mmthresh=%f", + desc="threshold for Mixture Model based inference") no_mm = traits.Bool( argstr="--no_mm", desc="switch off mixture modelling on IC maps") ICs = File(exists=True, argstr="--ICs=%s", @@ -1433,11 +1486,13 @@ class MELODICInputSpec(FSLCommandInputSpec): rem_cmp = traits.List( traits.Int, argstr="-f %d", desc="component numbers to remove") report = traits.Bool(argstr="--report", desc="generate Melodic web report") - bg_image = File(exists=True, argstr="--bgimage=%s", desc="specify background image for report" - " (default: mean image)") + bg_image = File( + exists=True, argstr="--bgimage=%s", + desc="specify background image for report (default: mean image)") tr_sec = traits.Float(argstr="--tr=%f", desc="TR in seconds") log_power = traits.Bool( - argstr="--logPower", desc="calculate log of power for frequency spectrum") + argstr="--logPower", + desc="calculate log of power for frequency spectrum") t_des = File(exists=True, argstr="--Tdes=%s", desc="design matrix across time-domain") t_con = File(exists=True, argstr="--Tcon=%s", @@ -1455,10 +1510,12 @@ class MELODICInputSpec(FSLCommandInputSpec): argstr="--Owhite", desc="output whitening/dewhitening matrices") out_orig = traits.Bool(argstr="--Oorig", desc="output the original ICs") out_mean = traits.Bool(argstr="--Omean", desc="output mean volume") - report_maps = traits.Str(argstr="--report_maps=%s", - desc="control string for spatial map images (see slicer)") - remove_deriv = traits.Bool(argstr="--remove_deriv", desc="removes every second entry in paradigm" - " file (EV derivatives)") + report_maps = traits.Str( + argstr="--report_maps=%s", + desc="control string for spatial map images (see slicer)") + remove_deriv = traits.Bool( + argstr="--remove_deriv", + desc="removes every second entry in paradigm file (EV derivatives)") class MELODICOutputSpec(TraitedSpec): @@ -1467,7 +1524,8 @@ class MELODICOutputSpec(TraitedSpec): class MELODIC(FSLCommand): - """Multivariate Exploratory Linear Optimised Decomposition into Independent Components + """Multivariate Exploratory Linear Optimised Decomposition into Independent + Components Examples -------- @@ -1564,43 +1622,54 @@ class ClusterInputSpec(FSLCommandInputSpec): threshold = traits.Float(argstr='--thresh=%.10f', mandatory=True, desc='threshold for input volume') - out_index_file = traits.Either(traits.Bool, File, - argstr='--oindex=%s', - desc='output of cluster index (in size order)', hash_files=False) + out_index_file = traits.Either( + traits.Bool, File, + argstr='--oindex=%s', + desc='output of cluster index (in size order)', hash_files=False) out_threshold_file = traits.Either(traits.Bool, File, argstr='--othresh=%s', - desc='thresholded image', hash_files=False) + desc='thresholded image', + hash_files=False) out_localmax_txt_file = traits.Either(traits.Bool, File, argstr='--olmax=%s', - desc='local maxima text file', hash_files=False) + desc='local maxima text file', + hash_files=False) out_localmax_vol_file = traits.Either(traits.Bool, File, argstr='--olmaxim=%s', - desc='output of local maxima volume', hash_files=False) + desc='output of local maxima volume', + hash_files=False) out_size_file = traits.Either(traits.Bool, File, argstr='--osize=%s', - desc='filename for output of size image', hash_files=False) + desc='filename for output of size image', + hash_files=False) out_max_file = traits.Either(traits.Bool, File, argstr='--omax=%s', - desc='filename for output of max image', hash_files=False) + desc='filename for output of max image', + hash_files=False) out_mean_file = traits.Either(traits.Bool, File, argstr='--omean=%s', - desc='filename for output of mean image', hash_files=False) - out_pval_file = traits.Either(traits.Bool, File, - argstr='--opvals=%s', - desc='filename for image output of log pvals', hash_files=False) + desc='filename for output of mean image', + hash_files=False) + out_pval_file = traits.Either( + traits.Bool, File, + argstr='--opvals=%s', + desc='filename for image output of log pvals', + hash_files=False) pthreshold = traits.Float(argstr='--pthresh=%.10f', requires=['dlh', 'volume'], desc='p-threshold for clusters') - peak_distance = traits.Float(argstr='--peakdist=%.10f', - desc='minimum distance between local maxima/minima, in mm (default 0)') + peak_distance = traits.Float( + argstr='--peakdist=%.10f', + desc='minimum distance between local maxima/minima, in mm (default 0)') cope_file = traits.File(argstr='--cope=%s', desc='cope volume') volume = traits.Int(argstr='--volume=%d', desc='number of voxels in the mask') dlh = traits.Float(argstr='--dlh=%.10f', desc='smoothness estimate = sqrt(det(Lambda))') - fractional = traits.Bool(False, usedefault=True, argstr='--fractional', - desc='interprets the threshold as a fraction of the robust range') + fractional = traits.Bool( + False, usedefault=True, argstr='--fractional', + desc='interprets the threshold as a fraction of the robust range') connectivity = traits.Int(argstr='--connectivity=%d', desc='the connectivity of voxels (default 26)') use_mm = traits.Bool(False, usedefault=True, argstr='--mm', @@ -1609,10 +1678,12 @@ class ClusterInputSpec(FSLCommandInputSpec): desc='find minima instead of maxima') no_table = traits.Bool(False, usedefault=True, argstr='--no_table', desc='suppresses printing of the table info') - minclustersize = traits.Bool(False, usedefault=True, argstr='--minclustersize', - desc='prints out minimum significant cluster size') + minclustersize = traits.Bool( + False, usedefault=True, argstr='--minclustersize', + desc='prints out minimum significant cluster size') xfm_file = File(argstr='--xfm=%s', - desc='filename for Linear: input->standard-space transform. Non-linear: input->highres transform') + desc=('filename for Linear: input->standard-space ' + 'transform. Non-linear: input->highres transform')) std_space_file = File(argstr='--stdvol=%s', desc='filename for standard-space volume') num_maxima = traits.Int(argstr='--num=%d', @@ -1668,9 +1739,9 @@ def _list_outputs(self): change_ext = True if suffix.endswith('.txt'): change_ext = False - outputs[outkey] = self._gen_fname(self.inputs.in_file, - suffix='_' + suffix, - change_ext=change_ext) + outputs[outkey] = self._gen_fname( + self.inputs.in_file, suffix='_' + suffix, + change_ext=change_ext) else: outputs[outkey] = os.path.abspath(inval) return outputs @@ -1702,10 +1773,12 @@ class RandomiseInputSpec(FSLCommandInputSpec): demean = traits.Bool( desc='demean data temporally before model fitting', argstr='-D') one_sample_group_mean = traits.Bool( - desc='perform 1-sample group-mean test instead of generic permutation test', + desc=('perform 1-sample group-mean test instead of generic ' + 'permutation test'), argstr='-1') show_total_perms = traits.Bool( - desc='print out how many unique permutations would be generated and exit', + desc=('print out how many unique permutations would be generated ' + 'and exit'), argstr='-q') show_info_parallel_mode = traits.Bool( desc='print out information required for parallel mode and exit', @@ -1716,7 +1789,8 @@ class RandomiseInputSpec(FSLCommandInputSpec): tfce = traits.Bool( desc='carry out Threshold-Free Cluster Enhancement', argstr='-T') tfce2D = traits.Bool( - desc='carry out Threshold-Free Cluster Enhancement with 2D optimisation', + desc=('carry out Threshold-Free Cluster Enhancement with 2D ' + 'optimisation'), argstr='--T2') f_only = traits.Bool(desc='calculate f-statistics only', argstr='--f_only') raw_stats_imgs = traits.Bool( @@ -1725,9 +1799,11 @@ class RandomiseInputSpec(FSLCommandInputSpec): desc='output permutation vector and null distribution text files', argstr='-P') num_perm = traits.Int( - argstr='-n %d', desc='number of permutations (default 5000, set to 0 for exhaustive)') + argstr='-n %d', + desc='number of permutations (default 5000, set to 0 for exhaustive)') seed = traits.Int( - argstr='--seed=%d', desc='specific integer seed for random number generator') + argstr='--seed=%d', + desc='specific integer seed for random number generator') var_smooth = traits.Int( argstr='-v %d', desc='use variance smoothing (std is in mm)') c_thresh = traits.Float( @@ -1801,8 +1877,9 @@ def _list_outputs(self): elif self.inputs.cm_thresh or self.inputs.f_cm_thresh: prefix = 'clusterm' if prefix: - outputs['t_p_files'] = glob(self._gen_fname( - '%s_%s_p_tstat*' % (self.inputs.base_name, prefix))) + outputs['t_p_files'] = glob( + self._gen_fname('%s_%s_p_tstat*' % ( + self.inputs.base_name, prefix))) outputs['t_corrected_p_files'] = glob(self._gen_fname( '%s_%s_corrp_tstat*.nii' % (self.inputs.base_name, prefix))) @@ -1824,33 +1901,37 @@ class GLMInputSpec(FSLCommandInputSpec): desc=('file name of the GLM design matrix (text time' + ' courses for temporal regression or an image' + ' file for spatial regression)')) - contrasts = File(exists=True, argstr='-c %s', desc=('matrix of t-statics' + - ' contrasts')) - mask = File(exists=True, argstr='-m %s', desc=('mask image file name if' + - ' input is image')) + contrasts = File(exists=True, argstr='-c %s', + desc=('matrix of t-statics contrasts')) + mask = File(exists=True, argstr='-m %s', + desc=('mask image file name if input is image')) dof = traits.Int(argstr='--dof=%d', desc=('set degrees of freedom' + ' explicitly')) des_norm = traits.Bool(argstr='--des_norm', desc=('switch on normalization of the design' + ' matrix columns to unit std deviation')) - dat_norm = traits.Bool(argstr='--dat_norm', desc=('switch on normalization' - ' of the data time' + - ' series to unit std' + - ' deviation')) - var_norm = traits.Bool(argstr='--vn', desc=('perform MELODIC variance-' + - 'normalisation on data')) - demean = traits.Bool(argstr='--demean', desc=('switch on demeaining of ' + - ' design and data')) + dat_norm = traits.Bool( + argstr='--dat_norm', + desc=('switch on normalization of the data time series to unit std ' + 'deviation')) + var_norm = traits.Bool( + argstr='--vn', + desc=('perform MELODIC variance-normalisation on data')) + demean = traits.Bool( + argstr='--demean', + desc=('switch on demeaining of design and data')) out_cope = File(argstr='--out_cope=%s', desc='output file name for COPE (either as txt or image') - out_z_name = File(argstr='--out_z=%s', - desc='output file name for Z-stats (either as txt or image') - out_t_name = File(argstr='--out_t=%s', - desc='output file name for t-stats (either as txt or image') - - out_p_name = File(argstr='--out_p=%s', - desc=('output file name for p-values of Z-stats (either as' + - ' text file or image)')) + out_z_name = File( + argstr='--out_z=%s', + desc='output file name for Z-stats (either as txt or image') + out_t_name = File( + argstr='--out_t=%s', + desc='output file name for t-stats (either as txt or image') + out_p_name = File( + argstr='--out_p=%s', + desc=('output file name for p-values of Z-stats (either as text file ' + 'or image)')) out_f_name = File(argstr='--out_f=%s', desc='output file name for F-value of full model fit') out_pf_name = File(argstr='--out_pf=%s', @@ -1859,50 +1940,53 @@ class GLMInputSpec(FSLCommandInputSpec): desc='output file name for residuals') out_varcb_name = File(argstr='--out_varcb=%s', desc='output file name for variance of COPEs') - - out_sigsq_name = File(argstr='--out_sigsq=%s', - desc=('output file name for residual noise variance' + - ' sigma-square')) + out_sigsq_name = File( + argstr='--out_sigsq=%s', + desc=('output file name for residual noise variance sigma-square')) out_data_name = File(argstr='--out_data=%s', desc='output file name for pre-processed data') - out_vnscales_name = File(argstr='--out_vnscales=%s', - desc=('output file name for scaling factors for variance' + - ' normalisation')) + out_vnscales_name = File( + argstr='--out_vnscales=%s', + desc=('output file name for scaling factors for variance ' + 'normalisation')) class GLMOutputSpec(TraitedSpec): - out_file = File(exists=True, desc=('file name of GLM parameters' - ' (if generated)')) - out_cope = OutputMultiPath(File(exists=True), - desc=('output file name for COPEs (either as ' - 'text file or image)')) - out_z = OutputMultiPath(File(exists=True), - desc=('output file name for COPEs (either as text ' - 'file or image)')) - out_t = OutputMultiPath(File(exists=True), - desc=('output file name for t-stats (either as ' - 'text file or image)')) - out_p = OutputMultiPath(File(exists=True), - desc=('output file name for p-values of Z-stats ' - '(either as text file or image)')) - out_f = OutputMultiPath(File(exists=True), - desc=('output file name for F-value of full model ' - 'fit')) - out_pf = OutputMultiPath(File(exists=True), - desc=('output file name for p-value for full ' - 'model fit')) - out_res = OutputMultiPath(File(exists=True), - desc='output file name for residuals') + out_file = File( + exists=True, + desc=('file name of GLM parameters (if generated)')) + out_cope = OutputMultiPath( + File(exists=True), + desc=('output file name for COPEs (either as text file or image)')) + out_z = OutputMultiPath( + File(exists=True), + desc=('output file name for COPEs (either as text file or image)')) + out_t = OutputMultiPath( + File(exists=True), + desc=('output file name for t-stats (either as text file or image)')) + out_p = OutputMultiPath( + File(exists=True), + desc=('output file name for p-values of Z-stats (either as text file ' + 'or image)')) + out_f = OutputMultiPath( + File(exists=True), + desc=('output file name for F-value of full model fit')) + out_pf = OutputMultiPath( + File(exists=True), + desc=('output file name for p-value for full model fit')) + out_res = OutputMultiPath( + File(exists=True), desc='output file name for residuals') out_varcb = OutputMultiPath(File(exists=True), desc='output file name for variance of COPEs') - out_sigsq = OutputMultiPath(File(exists=True), - desc=('output file name for residual noise ' - 'variance sigma-square')) + out_sigsq = OutputMultiPath( + File(exists=True), + desc=('output file name for residual noise variance sigma-square')) out_data = OutputMultiPath(File(exists=True), desc='output file for preprocessed data') - out_vnscales = OutputMultiPath(File(exists=True), - desc=('output file name for scaling factors ' - 'for variance normalisation')) + out_vnscales = OutputMultiPath( + File(exists=True), + desc=('output file name for scaling factors for variance ' + 'normalisation')) class GLM(FSLCommand): diff --git a/nipype/interfaces/fsl/preprocess.py b/nipype/interfaces/fsl/preprocess.py index d5fad15905..d216936471 100644 --- a/nipype/interfaces/fsl/preprocess.py +++ b/nipype/interfaces/fsl/preprocess.py @@ -46,16 +46,17 @@ class BETInputSpec(FSLCommandInputSpec): desc="Don't generate segmented output") frac = traits.Float(desc='fractional intensity threshold', argstr='-f %.2f') - vertical_gradient = traits.Float(argstr='-g %.2f', - desc='vertical gradient in fractional intensity ' - 'threshold (-1, 1)') + vertical_gradient = traits.Float( + argstr='-g %.2f', + desc='vertical gradient in fractional intensity threshold (-1, 1)') radius = traits.Int(argstr='-r %d', units='mm', desc="head radius") center = traits.List(traits.Int, desc='center of gravity in voxels', argstr='-c %s', minlen=0, maxlen=3, units='voxels') - threshold = traits.Bool(argstr='-t', - desc="apply thresholding to segmented brain image and mask") + threshold = traits.Bool( + argstr='-t', + desc="apply thresholding to segmented brain image and mask") mesh = traits.Bool(argstr='-e', desc="generate a vtk mesh brain surface") # the remaining 'options' are more like modes (mutually exclusive) that @@ -65,19 +66,20 @@ class BETInputSpec(FSLCommandInputSpec): # supported _xor_inputs = ('functional', 'reduce_bias', 'robust', 'padding', 'remove_eyes', 'surfaces', 't2_guided') - robust = traits.Bool(desc='robust brain centre estimation ' - '(iterates BET several times)', - argstr='-R', xor=_xor_inputs) - padding = traits.Bool(desc='improve BET if FOV is very small in Z ' - '(by temporarily padding end slices)', - argstr='-Z', xor=_xor_inputs) - remove_eyes = traits.Bool(desc='eye & optic nerve cleanup (can be ' - 'useful in SIENA)', - argstr='-S', xor=_xor_inputs) - surfaces = traits.Bool(desc='run bet2 and then betsurf to get additional ' - 'skull and scalp surfaces (includes ' - 'registrations)', - argstr='-A', xor=_xor_inputs) + robust = traits.Bool( + desc='robust brain centre estimation (iterates BET several times)', + argstr='-R', xor=_xor_inputs) + padding = traits.Bool( + desc=('improve BET if FOV is very small in Z (by temporarily padding ' + 'end slices)'), + argstr='-Z', xor=_xor_inputs) + remove_eyes = traits.Bool( + desc='eye & optic nerve cleanup (can be useful in SIENA)', + argstr='-S', xor=_xor_inputs) + surfaces = traits.Bool( + desc=('run bet2 and then betsurf to get additional skull and scalp ' + 'surfaces (includes registrations)'), + argstr='-A', xor=_xor_inputs) t2_guided = File(desc='as with creating surfaces, when also feeding in ' 'non-brain-extracted T2 (includes registrations)', argstr='-A2 %s', xor=_xor_inputs) @@ -163,25 +165,23 @@ def _list_outputs(self): outputs['mask_file'] = self._gen_fname(outputs['out_file'], suffix='_mask') if isdefined(self.inputs.outline) and self.inputs.outline: - outputs['outline_file'] = self._gen_fname(outputs['out_file'], - suffix='_overlay') + outputs['outline_file'] = self._gen_fname( + outputs['out_file'], suffix='_overlay') if isdefined(self.inputs.surfaces) and self.inputs.surfaces: - outputs['inskull_mask_file'] = self._gen_fname(outputs['out_file'], - suffix='_inskull_mask') - outputs['inskull_mesh_file'] = self._gen_fname(outputs['out_file'], - suffix='_inskull_mesh') - outputs[ - 'outskull_mask_file'] = self._gen_fname(outputs['out_file'], - suffix='_outskull_mask') - outputs[ - 'outskull_mesh_file'] = self._gen_fname(outputs['out_file'], - suffix='_outskull_mesh') - outputs['outskin_mask_file'] = self._gen_fname(outputs['out_file'], - suffix='_outskin_mask') - outputs['outskin_mesh_file'] = self._gen_fname(outputs['out_file'], - suffix='_outskin_mesh') - outputs['skull_mask_file'] = self._gen_fname(outputs['out_file'], - suffix='_skull_mask') + outputs['inskull_mask_file'] = self._gen_fname( + outputs['out_file'], suffix='_inskull_mask') + outputs['inskull_mesh_file'] = self._gen_fname( + outputs['out_file'], suffix='_inskull_mesh') + outputs['outskull_mask_file'] = self._gen_fname( + outputs['out_file'], suffix='_outskull_mask') + outputs['outskull_mesh_file'] = self._gen_fname( + outputs['out_file'], suffix='_outskull_mesh') + outputs['outskin_mask_file'] = self._gen_fname( + outputs['out_file'], suffix='_outskin_mask') + outputs['outskin_mesh_file'] = self._gen_fname( + outputs['out_file'], suffix='_outskin_mesh') + outputs['skull_mask_file'] = self._gen_fname( + outputs['out_file'], suffix='_skull_mask') if isdefined(self.inputs.no_output) and self.inputs.no_output: outputs['out_file'] = Undefined return outputs @@ -199,17 +199,18 @@ class FASTInputSpec(FSLCommandInputSpec): 'to be segmented', argstr='%s', position=-1, mandatory=True) out_basename = File(desc='base name of output files', - argstr='-o %s') # uses in_file name as basename if none given + argstr='-o %s') + # ^^ uses in_file name as basename if none given number_classes = traits.Range(low=1, high=10, argstr='-n %d', desc='number of tissue-type classes') output_biasfield = traits.Bool(desc='output estimated bias field', argstr='-b') - output_biascorrected = traits.Bool(desc='output restored image ' - '(bias-corrected image)', - argstr='-B') - img_type = traits.Enum((1, 2, 3), desc='int specifying type of image: ' - '(1 = T1, 2 = T2, 3 = PD)', - argstr='-t %d') + output_biascorrected = traits.Bool( + desc='output restored image (bias-corrected image)', argstr='-B') + img_type = traits.Enum( + (1, 2, 3), + desc='int specifying type of image: (1 = T1, 2 = T2, 3 = PD)', + argstr='-t %d') bias_iters = traits.Range(low=1, high=10, argstr='-I %d', desc='number of main-loop iterations during ' 'bias-field removal') @@ -236,12 +237,8 @@ class FASTInputSpec(FSLCommandInputSpec): no_bias = traits.Bool(desc='do not remove bias field', argstr='-N') use_priors = traits.Bool(desc='use priors throughout', - argstr='-P') # must also set -a!, - # mutually inclusive?? - # No, conditional - # mandatory... need to - # figure out how to - # handle with traits. + argstr='-P') + # ^^ Must also set -a!, mutually inclusive?? No, conditional mandatory... need to figure out how to handle with traits. segment_iters = traits.Range(low=1, high=50, desc='number of segmentation-initialisation' ' iterations', @@ -269,20 +266,22 @@ class FASTOutputSpec(TraitedSpec): tissue_class_map = File(exists=True, desc='path/name of binary segmented volume file' ' one val for each class _seg') - tissue_class_files = OutputMultiPath(File(desc='path/name of binary segmented volumes ' - 'one file for each class _seg_x')) - restored_image = OutputMultiPath(File(desc='restored images (one for each input image) ' - 'named according to the input images _restore')) + tissue_class_files = OutputMultiPath(File( + desc=('path/name of binary segmented volumes one file for each class ' + '_seg_x'))) + restored_image = OutputMultiPath(File( + desc=('restored images (one for each input image) named according to ' + 'the input images _restore'))) mixeltype = File(desc="path/name of mixeltype volume file _mixeltype") partial_volume_map = File(desc="path/name of partial volume file _pveseg") - partial_volume_files = OutputMultiPath(File(desc='path/name of partial volumes files ' - 'one for each class, _pve_x')) + partial_volume_files = OutputMultiPath(File( + desc='path/name of partial volumes files one for each class, _pve_x')) bias_field = OutputMultiPath(File(desc='Estimated bias field _bias')) - probability_maps = OutputMultiPath(File(desc='filenames, one for each class, for each ' - 'input, prob_x')) + probability_maps = OutputMultiPath(File( + desc='filenames, one for each class, for each input, prob_x')) class FAST(FSLCommand): @@ -329,8 +328,7 @@ def _list_outputs(self): else: basefile = self.inputs.in_files[-1] - outputs['tissue_class_map'] = self._gen_fname(basefile, - suffix='_seg') + outputs['tissue_class_map'] = self._gen_fname(basefile, suffix='_seg') if self.inputs.segments: outputs['tissue_class_files'] = [] for i in range(nclasses): @@ -344,7 +342,8 @@ def _list_outputs(self): for val, f in enumerate(self.inputs.in_files): # image numbering is 1-based outputs['restored_image'].append( - self._gen_fname(basefile, suffix='_restore_%d' % (val + 1))) + self._gen_fname(basefile, + suffix='_restore_%d' % (val + 1))) else: # single image segmentation has unnumbered output image outputs['restored_image'].append( @@ -357,8 +356,8 @@ def _list_outputs(self): outputs['partial_volume_files'] = [] for i in range(nclasses): outputs[ - 'partial_volume_files'].append(self._gen_fname(basefile, - suffix='_pve_%d' % i)) + 'partial_volume_files'].append( + self._gen_fname(basefile, suffix='_pve_%d' % i)) if self.inputs.output_biasfield: outputs['bias_field'] = [] if len(self.inputs.in_files) > 1: @@ -367,7 +366,8 @@ def _list_outputs(self): for val, f in enumerate(self.inputs.in_files): # image numbering is 1-based outputs['bias_field'].append( - self._gen_fname(basefile, suffix='_bias_%d' % (val + 1))) + self._gen_fname(basefile, + suffix='_bias_%d' % (val + 1))) else: # single image segmentation has unnumbered output image outputs['bias_field'].append( @@ -398,10 +398,12 @@ class FLIRTInputSpec(FSLCommandInputSpec): requires=['save_log'], name_template='%s_flirt.log', desc='output log') in_matrix_file = File(argstr='-init %s', desc='input 4x4 affine matrix') - apply_xfm = traits.Bool(argstr='-applyxfm', requires=['in_matrix_file'], - desc='apply transformation supplied by in_matrix_file') - apply_isoxfm = traits.Float(argstr='-applyisoxfm %f', xor=['apply_xfm'], - desc='as applyxfm but forces isotropic resampling') + apply_xfm = traits.Bool( + argstr='-applyxfm', requires=['in_matrix_file'], + desc='apply transformation supplied by in_matrix_file') + apply_isoxfm = traits.Float( + argstr='-applyisoxfm %f', xor=['apply_xfm'], + desc='as applyxfm but forces isotropic resampling') datatype = traits.Enum('char', 'short', 'int', 'float', 'double', argstr='-datatype %s', desc='force output data type') @@ -437,8 +439,9 @@ class FLIRTInputSpec(FSLCommandInputSpec): desc='do not change input sampling') force_scaling = traits.Bool(argstr='-forcescaling', desc='force rescaling even for low-res images') - min_sampling = traits.Float(argstr='-minsampling %f', units='mm', - desc='set minimum voxel dimension for sampling') + min_sampling = traits.Float( + argstr='-minsampling %f', units='mm', + desc='set minimum voxel dimension for sampling') padding_size = traits.Int(argstr='-paddingsize %d', units='voxels', desc='for applyxfm: interpolates outside image ' 'by size') @@ -488,7 +491,8 @@ class FLIRTInputSpec(FSLCommandInputSpec): desc='white matter boundary normals for BBR cost function') fieldmap = File( argstr='-fieldmap %s', min_ver='5.0.0', - desc='fieldmap image in rads/s - must be already registered to the reference image') + desc=('fieldmap image in rads/s - must be already registered to the ' + 'reference image')) fieldmapmask = File( argstr='-fieldmapmask %s', min_ver='5.0.0', desc='mask for fieldmap image') @@ -501,7 +505,8 @@ class FLIRTInputSpec(FSLCommandInputSpec): bbrtype = traits.Enum( 'signed', 'global_abs', 'local_abs', argstr='-bbrtype %s', min_ver='5.0.0', - desc='type of bbr cost function: signed [default], global_abs, local_abs') + desc=('type of bbr cost function: signed [default], global_abs, ' + 'local_abs')) bbrslope = traits.Float( argstr='-bbrslope %f', min_ver='5.0.0', desc='value of bbr slope') @@ -562,7 +567,8 @@ def _parse_inputs(self, skip=None): class ApplyXfmInputSpec(FLIRTInputSpec): apply_xfm = traits.Bool( True, argstr='-applyxfm', requires=['in_matrix_file'], - desc='apply transformation supplied by in_matrix_file', usedefault=True) + desc='apply transformation supplied by in_matrix_file', + usedefault=True) class ApplyXfm(FLIRT): @@ -595,7 +601,8 @@ class MCFLIRTInputSpec(FSLCommandInputSpec): out_file = File(argstr='-out %s', genfile=True, desc="file to write", hash_files=False) cost = traits.Enum( - 'mutualinfo', 'woods', 'corratio', 'normcorr', 'normmi', 'leastsquares', + 'mutualinfo', 'woods', 'corratio', + 'normcorr', 'normmi', 'leastsquares', argstr='-cost %s', desc="cost function to optimize") bins = traits.Int(argstr='-bins %d', desc="number of histogram bins") dof = traits.Int( @@ -607,8 +614,9 @@ class MCFLIRTInputSpec(FSLCommandInputSpec): argstr='-smooth %.2f', desc="smoothing factor for the cost function") rotation = traits.Int( argstr='-rotation %d', desc="scaling factor for rotation tolerances") - stages = traits.Int(argstr='-stages %d', - desc="stages (if 4, perform final search with sinc interpolation") + stages = traits.Int( + argstr='-stages %d', + desc="stages (if 4, perform final search with sinc interpolation") init = File(exists=True, argstr='-init %s', desc="inital transformation matrix") interpolation = traits.Enum("spline", "nn", "sinc", argstr="-%s_final", @@ -638,8 +646,9 @@ class MCFLIRTOutputSpec(TraitedSpec): par_file = File(exists=True, desc="text-file with motion parameters") mat_file = OutputMultiPath(File( exists=True), desc="transformation matrices") - rms_files = OutputMultiPath(File(exists=True), - desc="absolute and relative displacement parameters") + rms_files = OutputMultiPath(File( + exists=True), + desc="absolute and relative displacement parameters") class MCFLIRT(FSLCommand): @@ -732,31 +741,42 @@ class FNIRTInputSpec(FSLCommandInputSpec): inwarp_file = File(exists=True, argstr='--inwarp=%s', desc='name of file containing initial non-linear warps') in_intensitymap_file = File(exists=True, argstr='--intin=%s', - desc='name of file/files containing initial intensity maping' - 'usually generated by previos fnirt run') - fieldcoeff_file = traits.Either(traits.Bool, File, argstr='--cout=%s', - desc='name of output file with field coefficients or true') + desc=('name of file/files containing initial ' + 'intensity maping usually generated by ' + 'previous fnirt run')) + fieldcoeff_file = traits.Either( + traits.Bool, File, argstr='--cout=%s', + desc='name of output file with field coefficients or true') warped_file = File(argstr='--iout=%s', - desc='name of output image', genfile=True, hash_files=False) + desc='name of output image', genfile=True, + hash_files=False) field_file = traits.Either(traits.Bool, File, argstr='--fout=%s', - desc='name of output file with field or true', hash_files=False) + desc='name of output file with field or true', + hash_files=False) jacobian_file = traits.Either(traits.Bool, File, argstr='--jout=%s', - desc='name of file for writing out the Jacobian' - 'of the field (for diagnostic or VBM purposes)', hash_files=False) + desc=('name of file for writing out the ' + 'Jacobian of the field (for ' + 'diagnostic or VBM purposes)'), + hash_files=False) modulatedref_file = traits.Either(traits.Bool, File, argstr='--refout=%s', - desc='name of file for writing out intensity modulated' - '--ref (for diagnostic purposes)', hash_files=False) + desc=('name of file for writing out ' + 'intensity modulated --ref (for ' + 'diagnostic purposes)'), + hash_files=False) out_intensitymap_file = traits.Either(traits.Bool, File, argstr='--intout=%s', - desc='name of files for writing information pertaining ' - 'to intensity mapping', hash_files=False) + desc=('name of files for writing ' + 'information pertaining to ' + 'intensity mapping'), + hash_files=False) log_file = File(argstr='--logout=%s', desc='Name of log-file', genfile=True, hash_files=False) config_file = traits.Either( - traits.Enum("T1_2_MNI152_2mm", "FA_2_FMRIB58_1mm"), File(exists=True), argstr='--config=%s', + traits.Enum("T1_2_MNI152_2mm", "FA_2_FMRIB58_1mm"), File(exists=True), + argstr='--config=%s', desc='Name of config file specifying command line arguments') refmask_file = File(exists=True, argstr='--refmask=%s', desc='name of file with mask in reference space') @@ -765,74 +785,110 @@ class FNIRTInputSpec(FSLCommandInputSpec): skip_refmask = traits.Bool( argstr='--applyrefmask=0', xor=['apply_refmask'], desc='Skip specified refmask if set, default false') - skip_inmask = traits.Bool(argstr='--applyinmask=0', xor=['apply_inmask'], - desc='skip specified inmask if set, default false') + skip_inmask = traits.Bool( + argstr='--applyinmask=0', xor=['apply_inmask'], + desc='skip specified inmask if set, default false') apply_refmask = traits.List( traits.Enum(0, 1), argstr='--applyrefmask=%s', xor=['skip_refmask'], - desc='list of iterations to use reference mask on (1 to use, 0 to skip)', sep=",") + desc=('list of iterations to use reference mask on (1 to use, 0 to ' + 'skip)'), + sep=",") apply_inmask = traits.List( traits.Enum(0, 1), argstr='--applyinmask=%s', xor=['skip_inmask'], - desc='list of iterations to use input mask on (1 to use, 0 to skip)', sep=",") - skip_implicit_ref_masking = traits.Bool(argstr='--imprefm=0', - desc='skip implicit masking based on value' - 'in --ref image. Default = 0') - skip_implicit_in_masking = traits.Bool(argstr='--impinm=0', - desc='skip implicit masking based on value' - 'in --in image. Default = 0') - refmask_val = traits.Float(argstr='--imprefval=%f', - desc='Value to mask out in --ref image. Default =0.0') - inmask_val = traits.Float(argstr='--impinval=%f', - desc='Value to mask out in --in image. Default =0.0') - max_nonlin_iter = traits.List(traits.Int, - argstr='--miter=%s', - desc='Max # of non-linear iterations list, default [5, 5, 5, 5]', sep=",") - subsampling_scheme = traits.List(traits.Int, - argstr='--subsamp=%s', - desc='sub-sampling scheme, list, default [4, 2, 1, 1]', - sep=",") - warp_resolution = traits.Tuple(traits.Int, traits.Int, traits.Int, - argstr='--warpres=%d,%d,%d', - desc='(approximate) resolution (in mm) of warp basis ' - 'in x-, y- and z-direction, default 10, 10, 10') - spline_order = traits.Int(argstr='--splineorder=%d', - desc='Order of spline, 2->Qadratic spline, 3->Cubic spline. Default=3') - in_fwhm = traits.List(traits.Int, argstr='--infwhm=%s', - desc='FWHM (in mm) of gaussian smoothing kernel for input volume, default [6, 4, 2, 2]', sep=",") - ref_fwhm = traits.List(traits.Int, argstr='--reffwhm=%s', - desc='FWHM (in mm) of gaussian smoothing kernel for ref volume, default [4, 2, 0, 0]', sep=",") - regularization_model = traits.Enum('membrane_energy', 'bending_energy', - argstr='--regmod=%s', - desc='Model for regularisation of warp-field [membrane_energy bending_energy], default bending_energy') - regularization_lambda = traits.List(traits.Float, argstr='--lambda=%s', - desc='Weight of regularisation, default depending on --ssqlambda and --regmod ' - 'switches. See user documetation.', sep=",") - skip_lambda_ssq = traits.Bool(argstr='--ssqlambda=0', - desc='If true, lambda is not weighted by current ssq, default false') - jacobian_range = traits.Tuple(traits.Float, traits.Float, - argstr='--jacrange=%f,%f', - desc='Allowed range of Jacobian determinants, default 0.01, 100.0') - derive_from_ref = traits.Bool(argstr='--refderiv', - desc='If true, ref image is used to calculate derivatives. Default false') - intensity_mapping_model = traits.Enum('none', 'global_linear', 'global_non_linear' - 'local_linear', 'global_non_linear_with_bias', - 'local_non_linear', argstr='--intmod=%s', - desc='Model for intensity-mapping') - intensity_mapping_order = traits.Int(argstr='--intorder=%d', - desc='Order of poynomial for mapping intensities, default 5') - biasfield_resolution = traits.Tuple(traits.Int, traits.Int, traits.Int, - argstr='--biasres=%d,%d,%d', - desc='Resolution (in mm) of bias-field modelling ' - 'local intensities, default 50, 50, 50') - bias_regularization_lambda = traits.Float(argstr='--biaslambda=%f', - desc='Weight of regularisation for bias-field, default 10000') + desc='list of iterations to use input mask on (1 to use, 0 to skip)', + sep=",") + skip_implicit_ref_masking = traits.Bool( + argstr='--imprefm=0', + desc=('skip implicit masking based on value in --ref image. ' + 'Default = 0')) + skip_implicit_in_masking = traits.Bool( + argstr='--impinm=0', + desc=('skip implicit masking based on value in --in image. ' + 'Default = 0')) + refmask_val = traits.Float( + argstr='--imprefval=%f', + desc='Value to mask out in --ref image. Default =0.0') + inmask_val = traits.Float( + argstr='--impinval=%f', + desc='Value to mask out in --in image. Default =0.0') + max_nonlin_iter = traits.List( + traits.Int, + argstr='--miter=%s', + desc='Max # of non-linear iterations list, default [5, 5, 5, 5]', + sep=",") + subsampling_scheme = traits.List( + traits.Int, + argstr='--subsamp=%s', + desc='sub-sampling scheme, list, default [4, 2, 1, 1]', + sep=",") + warp_resolution = traits.Tuple( + traits.Int, traits.Int, traits.Int, + argstr='--warpres=%d,%d,%d', + desc=('(approximate) resolution (in mm) of warp basis in x-, y- and ' + 'z-direction, default 10, 10, 10')) + spline_order = traits.Int( + argstr='--splineorder=%d', + desc='Order of spline, 2->Qadratic spline, 3->Cubic spline. Default=3') + in_fwhm = traits.List( + traits.Int, argstr='--infwhm=%s', + desc=('FWHM (in mm) of gaussian smoothing kernel for input volume, ' + 'default [6, 4, 2, 2]'), + sep=",") + ref_fwhm = traits.List( + traits.Int, argstr='--reffwhm=%s', + desc=('FWHM (in mm) of gaussian smoothing kernel for ref volume, ' + 'default [4, 2, 0, 0]'), + sep=",") + regularization_model = traits.Enum( + 'membrane_energy', 'bending_energy', + argstr='--regmod=%s', + desc=('Model for regularisation of warp-field [membrane_energy ' + 'bending_energy], default bending_energy')) + regularization_lambda = traits.List( + traits.Float, argstr='--lambda=%s', + desc=('Weight of regularisation, default depending on --ssqlambda and ' + '--regmod switches. See user documetation.'), + sep=",") + skip_lambda_ssq = traits.Bool( + argstr='--ssqlambda=0', + desc='If true, lambda is not weighted by current ssq, default false') + jacobian_range = traits.Tuple( + traits.Float, traits.Float, + argstr='--jacrange=%f,%f', + desc='Allowed range of Jacobian determinants, default 0.01, 100.0') + derive_from_ref = traits.Bool( + argstr='--refderiv', + desc=('If true, ref image is used to calculate derivatives. ' + 'Default false')) + intensity_mapping_model = traits.Enum( + 'none', 'global_linear', 'global_non_linear' + 'local_linear', 'global_non_linear_with_bias', + 'local_non_linear', argstr='--intmod=%s', + desc='Model for intensity-mapping') + intensity_mapping_order = traits.Int( + argstr='--intorder=%d', + desc='Order of poynomial for mapping intensities, default 5') + biasfield_resolution = traits.Tuple( + traits.Int, traits.Int, traits.Int, + argstr='--biasres=%d,%d,%d', + desc=('Resolution (in mm) of bias-field modelling local intensities, ' + 'default 50, 50, 50')) + bias_regularization_lambda = traits.Float( + argstr='--biaslambda=%f', + desc='Weight of regularisation for bias-field, default 10000') skip_intensity_mapping = traits.Bool( argstr='--estint=0', xor=['apply_intensity_mapping'], desc='Skip estimate intensity-mapping default false') apply_intensity_mapping = traits.List( - traits.Enum(0, 1), argstr='--estint=%s', xor=['skip_intensity_mapping'], - desc='List of subsampling levels to apply intensity mapping for (0 to skip, 1 to apply)', sep=",") - hessian_precision = traits.Enum('double', 'float', argstr='--numprec=%s', - desc='Precision for representing Hessian, double or float. Default double') + traits.Enum(0, 1), argstr='--estint=%s', + xor=['skip_intensity_mapping'], + desc=('List of subsampling levels to apply intensity mapping for ' + '(0 to skip, 1 to apply)'), + sep=",") + hessian_precision = traits.Enum( + 'double', 'float', argstr='--numprec=%s', + desc=('Precision for representing Hessian, double or float. ' + 'Default double')) class FNIRTOutputSpec(TraitedSpec): @@ -955,14 +1011,18 @@ class ApplyWarpInputSpec(FSLCommandInputSpec): desc="treat warp field as absolute: x' = w(x)") relwarp = traits.Bool(argstr='--rel', xor=['abswarp'], position=-1, desc="treat warp field as relative: x' = x + w(x)") - datatype = traits.Enum('char', 'short', 'int', 'float', 'double', - argstr='--datatype=%s', - desc='Force output data type [char short int float double].') - supersample = traits.Bool(argstr='--super', - desc='intermediary supersampling of output, default is off') - superlevel = traits.Either(traits.Enum('a'), traits.Int, - argstr='--superlevel=%s', - desc="level of intermediary supersampling, a for 'automatic' or integer level. Default = 2") + datatype = traits.Enum( + 'char', 'short', 'int', 'float', 'double', + argstr='--datatype=%s', + desc='Force output data type [char short int float double].') + supersample = traits.Bool( + argstr='--super', + desc='intermediary supersampling of output, default is off') + superlevel = traits.Either( + traits.Enum('a'), traits.Int, + argstr='--superlevel=%s', + desc=("level of intermediary supersampling, a for 'automatic' or " + "integer level. Default = 2")) premat = File(exists=True, argstr='--premat=%s', desc='filename for pre-transform (affine matrix)') postmat = File(exists=True, argstr='--postmat=%s', @@ -1028,16 +1088,22 @@ class SliceTimerInputSpec(FSLCommandInputSpec): desc='slice indexing from top to bottom') time_repetition = traits.Float(argstr='--repeat=%f', desc='Specify TR of data - default is 3s') - slice_direction = traits.Enum(1, 2, 3, argstr='--direction=%d', - desc='direction of slice acquisition (x=1, y=2, z=3) - default is z') + slice_direction = traits.Enum( + 1, 2, 3, argstr='--direction=%d', + desc='direction of slice acquisition (x=1, y=2, z=3) - default is z') interleaved = traits.Bool(argstr='--odd', desc='use interleaved acquisition') - custom_timings = File(exists=True, argstr='--tcustom=%s', - desc='slice timings, in fractions of TR, range 0:1 (default is 0.5 = no shift)') - global_shift = traits.Float(argstr='--tglobal', - desc='shift in fraction of TR, range 0:1 (default is 0.5 = no shift)') - custom_order = File(exists=True, argstr='--ocustom=%s', - desc='filename of single-column custom interleave order file (first slice is referred to as 1 not 0)') + custom_timings = File( + exists=True, argstr='--tcustom=%s', + desc=('slice timings, in fractions of TR, range 0:1 (default is 0.5 = ' + 'no shift)')) + global_shift = traits.Float( + argstr='--tglobal', + desc='shift in fraction of TR, range 0:1 (default is 0.5 = no shift)') + custom_order = File( + exists=True, argstr='--ocustom=%s', + desc=('filename of single-column custom interleave order file (first ' + 'slice is referred to as 1 not 0)')) class SliceTimerOutputSpec(TraitedSpec): @@ -1082,18 +1148,20 @@ class SUSANInputSpec(FSLCommandInputSpec): in_file = File(exists=True, argstr='%s', mandatory=True, position=1, desc='filename of input timeseries') - brightness_threshold = traits.Float(argstr='%.10f', - position=2, mandatory=True, - desc='brightness threshold and should be greater than ' - 'noise level and less than contrast of edges to ' - 'be preserved.') - fwhm = traits.Float(argstr='%.10f', - position=3, mandatory=True, - desc='fwhm of smoothing, in mm, gets converted using sqrt(8*log(2))') + brightness_threshold = traits.Float( + argstr='%.10f', + position=2, mandatory=True, + desc=('brightness threshold and should be greater than noise level ' + 'and less than contrast of edges to be preserved.')) + fwhm = traits.Float( + argstr='%.10f', position=3, mandatory=True, + desc='fwhm of smoothing, in mm, gets converted using sqrt(8*log(2))') dimension = traits.Enum(3, 2, argstr='%d', position=4, usedefault=True, desc='within-plane (2) or fully 3D (3)') - use_median = traits.Enum(1, 0, argstr='%d', position=5, usedefault=True, - desc='whether to use a local median filter in the cases where single-point noise is detected') + use_median = traits.Enum( + 1, 0, argstr='%d', position=5, usedefault=True, + desc=('whether to use a local median filter in the cases where ' + 'single-point noise is detected')) usans = traits.List( traits.Tuple(File(exists=True), traits.Float), maxlen=2, argstr='', position=6, default=[], usedefault=True, @@ -1166,66 +1234,85 @@ class FUGUEInputSpec(FSLCommandInputSpec): desc='filename for input phase image') fmap_in_file = File(exists=True, argstr='--loadfmap=%s', desc='filename for loading fieldmap (rad/s)') - unwarped_file = File(argstr='--unwarp=%s', desc='apply unwarping and save as filename', + unwarped_file = File(argstr='--unwarp=%s', + desc='apply unwarping and save as filename', xor=['warped_file'], requires=['in_file']) - warped_file = File(argstr='--warp=%s', desc='apply forward warping and save as filename', + warped_file = File(argstr='--warp=%s', + desc='apply forward warping and save as filename', xor=['unwarped_file'], requires=['in_file']) - - forward_warping = traits.Bool(False, usedefault=True, - desc='apply forward warping instead of unwarping') - + forward_warping = traits.Bool( + False, usedefault=True, + desc='apply forward warping instead of unwarping') dwell_to_asym_ratio = traits.Float(argstr='--dwelltoasym=%.10f', desc='set the dwell to asym time ratio') - dwell_time = traits.Float(argstr='--dwell=%.10f', - desc=('set the EPI dwell time per phase-encode line - same as echo ' - 'spacing - (sec)')) - asym_se_time = traits.Float(argstr='--asym=%.10f', - desc='set the fieldmap asymmetric spin echo time (sec)') + dwell_time = traits.Float( + argstr='--dwell=%.10f', + desc=('set the EPI dwell time per phase-encode line - same as echo ' + 'spacing - (sec)')) + asym_se_time = traits.Float( + argstr='--asym=%.10f', + desc='set the fieldmap asymmetric spin echo time (sec)') median_2dfilter = traits.Bool(argstr='--median', desc='apply 2D median filtering') despike_2dfilter = traits.Bool(argstr='--despike', desc='apply a 2D de-spiking filter') - no_gap_fill = traits.Bool(argstr='--nofill', - desc='do not apply gap-filling measure to the fieldmap') - no_extend = traits.Bool(argstr='--noextend', - desc='do not apply rigid-body extrapolation to the fieldmap') - smooth2d = traits.Float(argstr='--smooth2=%.2f', - desc='apply 2D Gaussian smoothing of sigma N (in mm)') - smooth3d = traits.Float(argstr='--smooth3=%.2f', - desc='apply 3D Gaussian smoothing of sigma N (in mm)') + no_gap_fill = traits.Bool( + argstr='--nofill', + desc='do not apply gap-filling measure to the fieldmap') + no_extend = traits.Bool( + argstr='--noextend', + desc='do not apply rigid-body extrapolation to the fieldmap') + smooth2d = traits.Float( + argstr='--smooth2=%.2f', + desc='apply 2D Gaussian smoothing of sigma N (in mm)') + smooth3d = traits.Float( + argstr='--smooth3=%.2f', + desc='apply 3D Gaussian smoothing of sigma N (in mm)') poly_order = traits.Int(argstr='--poly=%d', desc='apply polynomial fitting of order N') - fourier_order = traits.Int(argstr='--fourier=%d', - desc='apply Fourier (sinusoidal) fitting of order N') + fourier_order = traits.Int( + argstr='--fourier=%d', + desc='apply Fourier (sinusoidal) fitting of order N') pava = traits.Bool(argstr='--pava', desc='apply monotonic enforcement via PAVA') - despike_threshold = traits.Float(argstr='--despikethreshold=%s', - desc='specify the threshold for de-spiking (default=3.0)') - unwarp_direction = traits.Enum('x', 'y', 'z', 'x-', 'y-', 'z-', - argstr='--unwarpdir=%s', - desc='specifies direction of warping (default y)') - phase_conjugate = traits.Bool(argstr='--phaseconj', - desc='apply phase conjugate method of unwarping') - icorr = traits.Bool(argstr='--icorr', requires=['shift_in_file'], - desc='apply intensity correction to unwarping (pixel shift method only)') + despike_threshold = traits.Float( + argstr='--despikethreshold=%s', + desc='specify the threshold for de-spiking (default=3.0)') + unwarp_direction = traits.Enum( + 'x', 'y', 'z', 'x-', 'y-', 'z-', + argstr='--unwarpdir=%s', + desc='specifies direction of warping (default y)') + phase_conjugate = traits.Bool( + argstr='--phaseconj', + desc='apply phase conjugate method of unwarping') + icorr = traits.Bool( + argstr='--icorr', requires=['shift_in_file'], + desc=('apply intensity correction to unwarping (pixel shift method ' + 'only)')) icorr_only = traits.Bool(argstr='--icorronly', requires=['unwarped_file'], desc='apply intensity correction only') - mask_file = File(exists=True, argstr='--mask=%s', desc='filename for loading valid mask') - nokspace = traits.Bool(False, argstr='--nokspace', desc='do not use k-space forward warping') + mask_file = File(exists=True, argstr='--mask=%s', + desc='filename for loading valid mask') + nokspace = traits.Bool(False, argstr='--nokspace', + desc='do not use k-space forward warping') # Special outputs: shift (voxel shift map, vsm) save_shift = traits.Bool(False, xor=['save_unmasked_shift'], desc='write pixel shift volume') - shift_out_file = File(argstr='--saveshift=%s', desc='filename for saving pixel shift volume') - save_unmasked_shift = traits.Bool(argstr='--unmaskshift', xor=['save_shift'], - desc='saves the unmasked shiftmap when using --saveshift') + shift_out_file = File(argstr='--saveshift=%s', + desc='filename for saving pixel shift volume') + save_unmasked_shift = traits.Bool( + argstr='--unmaskshift', xor=['save_shift'], + desc='saves the unmasked shiftmap when using --saveshift') # Special outputs: fieldmap (fmap) save_fmap = traits.Bool(False, xor=['save_unmasked_fmap'], desc='write field map volume') - fmap_out_file = File(argstr='--savefmap=%s', desc='filename for saving fieldmap (rad/s)') - save_unmasked_fmap = traits.Bool(False, argstr='--unmaskfmap', xor=['save_fmap'], - desc='saves the unmasked fieldmap when using --savefmap') + fmap_out_file = File(argstr='--savefmap=%s', + desc='filename for saving fieldmap (rad/s)') + save_unmasked_fmap = traits.Bool( + False, argstr='--unmaskfmap', xor=['save_fmap'], + desc='saves the unmasked fieldmap when using --savefmap') class FUGUEOutputSpec(TraitedSpec): @@ -1237,14 +1324,16 @@ class FUGUEOutputSpec(TraitedSpec): class FUGUE(FSLCommand): """ - `FUGUE `_ is, most generally, a set of tools for - EPI distortion correction. + `FUGUE `_ is, most generally, + a set of tools for EPI distortion correction. Distortions may be corrected for - 1. improving registration with non-distorted images (e.g. structurals), or + 1. improving registration with non-distorted images (e.g. structurals), + or 2. dealing with motion-dependent changes. - FUGUE is designed to deal only with the first case - improving registration. + FUGUE is designed to deal only with the first case - + improving registration. Examples @@ -1310,7 +1399,9 @@ def _parse_inputs(self, skip=None): input_fmap = isdefined(self.inputs.fmap_in_file) if not input_phase and not input_vsm and not input_fmap: - raise RuntimeError('Either phasemap_in_file, shift_in_file or fmap_in_file must be set.') + raise RuntimeError( + ('Either phasemap_in_file, shift_in_file or fmap_in_file must ' + 'be set.')) if not isdefined(self.inputs.in_file): skip += ['unwarped_file', 'warped_file'] @@ -1330,7 +1421,8 @@ def _parse_inputs(self, skip=None): # Handle shift output if not isdefined(self.inputs.shift_out_file): - vsm_save_masked = (isdefined(self.inputs.save_shift) and self.inputs.save_shift) + vsm_save_masked = (isdefined(self.inputs.save_shift) and + self.inputs.save_shift) vsm_save_unmasked = (isdefined(self.inputs.save_unmasked_shift) and self.inputs.save_unmasked_shift) @@ -1345,8 +1437,9 @@ def _parse_inputs(self, skip=None): elif input_vsm: trait_spec.name_source = 'shift_in_file' else: - raise RuntimeError(('Either phasemap_in_file, shift_in_file or ' - 'fmap_in_file must be set.')) + raise RuntimeError( + ('Either phasemap_in_file, shift_in_file or ' + 'fmap_in_file must be set.')) if vsm_save_unmasked: trait_spec.name_template = '%s_vsm_unmasked' @@ -1357,7 +1450,8 @@ def _parse_inputs(self, skip=None): # Handle fieldmap output if not isdefined(self.inputs.fmap_out_file): - fmap_save_masked = (isdefined(self.inputs.save_fmap) and self.inputs.save_fmap) + fmap_save_masked = (isdefined(self.inputs.save_fmap) and + self.inputs.save_fmap) fmap_save_unmasked = (isdefined(self.inputs.save_unmasked_fmap) and self.inputs.save_unmasked_fmap) @@ -1372,8 +1466,9 @@ def _parse_inputs(self, skip=None): elif input_fmap: trait_spec.name_source = 'fmap_in_file' else: - raise RuntimeError(('Either phasemap_in_file, shift_in_file or ' - 'fmap_in_file must be set.')) + raise RuntimeError( + ('Either phasemap_in_file, shift_in_file or ' + 'fmap_in_file must be set.')) if fmap_save_unmasked: trait_spec.name_template = '%s_fieldmap_unmasked' @@ -1400,11 +1495,13 @@ class PRELUDEInputSpec(FSLCommandInputSpec): desc='raw phase file') unwrapped_phase_file = File(genfile=True, argstr='--unwrap=%s', - desc='file containing unwrapepd phase', hash_files=False) + desc='file containing unwrapepd phase', + hash_files=False) num_partitions = traits.Int(argstr='--numphasesplit=%d', desc='number of phase partitions to use') - labelprocess2d = traits.Bool(argstr='--labelslices', - desc='does label processing in 2D (slice at a time)') + labelprocess2d = traits.Bool( + argstr='--labelslices', + desc='does label processing in 2D (slice at a time)') process2d = traits.Bool(argstr='--slices', xor=['labelprocess2d'], desc='does all processing in 2D (slice at a time)') @@ -1570,8 +1667,8 @@ def _gen_fname(self, name): method = 'none' if isdefined(self.inputs.method) and self.inputs.method != 'none': method = 'fast' - if self.inputs.list_of_specific_structures and \ - self.inputs.method == 'auto': + if (self.inputs.list_of_specific_structures and + self.inputs.method == 'auto'): method = 'none' if isdefined(self.inputs.method_as_numerical_threshold): diff --git a/nipype/interfaces/fsl/utils.py b/nipype/interfaces/fsl/utils.py index 40f94a1c0f..59300155d0 100644 --- a/nipype/interfaces/fsl/utils.py +++ b/nipype/interfaces/fsl/utils.py @@ -38,7 +38,8 @@ class CopyGeomInputSpec(FSLCommandInputSpec): in_file = File(exists=True, mandatory=True, argstr="%s", position=0, desc="source image") dest_file = File(exists=True, mandatory=True, argstr="%s", position=1, - desc="destination image", copyfile=True, output_name='out_file', + desc="destination image", copyfile=True, + output_name='out_file', name_source='dest_file', name_template='%s') ignore_dims = traits.Bool(desc='Do not copy image dimensions', argstr='-d', position="-1") @@ -50,11 +51,12 @@ class CopyGeomOutputSpec(TraitedSpec): class CopyGeom(FSLCommand): """Use fslcpgeom to copy the header geometry information to another image. - Copy certain parts of the header information (image dimensions, voxel dimensions, - voxel dimensions units string, image orientation/origin or qform/sform info) - from one image to another. Note that only copies from Analyze to Analyze - or Nifti to Nifti will work properly. Copying from different files will result - in loss of information or potentially incorrect settings. + Copy certain parts of the header information (image dimensions, voxel + dimensions, voxel dimensions units string, image orientation/origin or + qform/sform info) from one image to another. Note that only copies from + Analyze to Analyze or Nifti to Nifti will work properly. Copying from + different files will result in loss of information or potentially incorrect + settings. """ _cmd = "fslcpgeom" input_spec = CopyGeomInputSpec @@ -95,14 +97,17 @@ class ImageMeantsInputSpec(FSLCommandInputSpec): 'option)'), argstr='--usemm') show_all = traits.Bool(desc=('show all voxel time series (within mask) ' 'instead of averaging'), argstr='--showall') - eig = traits.Bool(desc=('calculate Eigenvariate(s) instead of mean (output ' - 'will have 0 mean)'), argstr='--eig') + eig = traits.Bool( + desc=('calculate Eigenvariate(s) instead of mean (output will have 0 ' + 'mean)'), + argstr='--eig') order = traits.Int(1, desc='select number of Eigenvariates', argstr='--order=%d', usedefault=True) nobin = traits.Bool(desc=('do not binarise the mask for calculation of ' 'Eigenvariates'), argstr='--no_bin') - transpose = traits.Bool(desc=('output results in transpose format (one row ' - 'per voxel/mean)'), argstr='--transpose') + transpose = traits.Bool( + desc=('output results in transpose format (one row per voxel/mean)'), + argstr='--transpose') class ImageMeantsOutputSpec(TraitedSpec): @@ -111,8 +116,8 @@ class ImageMeantsOutputSpec(TraitedSpec): class ImageMeants(FSLCommand): """ Use fslmeants for printing the average timeseries (intensities) to - the screen (or saves to a file). The average is taken over all voxels in - the mask (or all voxels in the image if no mask is specified) + the screen (or saves to a file). The average is taken over all voxels + in the mask (or all voxels in the image if no mask is specified) """ _cmd = 'fslmeants' @@ -139,13 +144,17 @@ def _gen_filename(self, name): class SmoothInputSpec(FSLCommandInputSpec): in_file = File(exists=True, argstr="%s", position=0, mandatory=True) sigma = traits.Float( - argstr="-kernel gauss %.03f -fmean", position=1, xor=['fwhm'], mandatory=True, + argstr="-kernel gauss %.03f -fmean", position=1, xor=['fwhm'], + mandatory=True, desc='gaussian kernel sigma in mm (not voxels)') fwhm = traits.Float( - argstr="-kernel gauss %.03f -fmean", position=1, xor=['sigma'], mandatory=True, - desc='gaussian kernel fwhm, will be converted to sigma in mm (not voxels)') + argstr="-kernel gauss %.03f -fmean", position=1, xor=['sigma'], + mandatory=True, + desc=('gaussian kernel fwhm, will be converted to sigma in mm ' + '(not voxels)')) smoothed_file = File( - argstr="%s", position=2, name_source=['in_file'], name_template='%s_smooth', hash_files=False) + argstr="%s", position=2, name_source=['in_file'], + name_template='%s_smooth', hash_files=False) class SmoothOutputSpec(TraitedSpec): @@ -357,9 +366,10 @@ class SplitInputSpec(FSLCommandInputSpec): in_file = File(exists=True, argstr="%s", position=0, mandatory=True, desc="input filename") out_base_name = traits.Str(argstr="%s", position=1, desc="outputs prefix") - dimension = traits.Enum('t', 'x', 'y', 'z', argstr="-%s", position=2, - mandatory=True, - desc="dimension along which the file will be split") + dimension = traits.Enum( + 't', 'x', 'y', 'z', argstr="-%s", position=2, + mandatory=True, + desc="dimension along which the file will be split") class SplitOutputSpec(TraitedSpec): @@ -470,11 +480,11 @@ class FilterRegressorInputSpec(FSLCommandInputSpec): design_file = File(exists=True, argstr="-d %s", position=3, mandatory=True, desc=("name of the matrix with time courses (e.g. GLM " "design or MELODIC mixing matrix)")) - filter_columns = traits.List(traits.Int, argstr="-f '%s'", - xor=["filter_all"], mandatory=True, - position=4, - desc=("(1-based) column indices to filter out " - "of the data")) + filter_columns = traits.List( + traits.Int, argstr="-f '%s'", + xor=["filter_all"], mandatory=True, + position=4, + desc=("(1-based) column indices to filter out of the data")) filter_all = traits.Bool(mandatory=True, argstr="-f '%s'", xor=["filter_columns"], position=4, desc=("use all columns in the design file in " @@ -509,8 +519,10 @@ def _format_arg(self, name, trait_spec, value): n_cols = design.shape[1] except IndexError: n_cols = 1 - return trait_spec.argstr % ",".join(map(str, list(range(1, n_cols + 1)))) - return super(FilterRegressor, self)._format_arg(name, trait_spec, value) + return trait_spec.argstr % ",".join( + map(str, list(range(1, n_cols + 1)))) + return super(FilterRegressor, self)._format_arg( + name, trait_spec, value) def _list_outputs(self): outputs = self.output_spec().get() @@ -650,7 +662,6 @@ class AvScale(CommandLine): def _run_interface(self, runtime): runtime = super(AvScale, self)._run_interface(runtime) - expr = re.compile( 'Rotation\ &\ Translation\ Matrix:\n(?P[0-9\.\ \n-]+)[\s\n]*' '(Rotation\ Angles\ \(x,y,z\)\ \[rads\]\ =\ (?P[0-9\.\ -]+))?[\s\n]*' @@ -667,21 +678,27 @@ def _run_interface(self, runtime): out = expr.search(runtime.stdout).groupdict() outputs = {} outputs['rotation_translation_matrix'] = [[ - float(v) for v in r.strip().split(' ')] for r in out['rot_tran_mat'].strip().split('\n')] - outputs['scales'] = [float(s) for s in out['scales'].strip().split(' ')] + float(v) for v in r.strip().split(' ')] + for r in out['rot_tran_mat'].strip().split('\n')] + outputs['scales'] = [ + float(s) for s in out['scales'].strip().split(' ')] outputs['skews'] = [float(s) for s in out['skews'].strip().split(' ')] outputs['average_scaling'] = float(out['avg_scaling'].strip()) outputs['determinant'] = float(out['determinant'].strip()) - outputs['left_right_orientation_preserved'] = out['lr_orientation'].strip() == 'preserved' + outputs['left_right_orientation_preserved'] = out[ + 'lr_orientation'].strip() == 'preserved' outputs['forward_half_transform'] = [[ - float(v) for v in r.strip().split(' ')] for r in out['fwd_half_xfm'].strip().split('\n')] + float(v) for v in r.strip().split(' ')] + for r in out['fwd_half_xfm'].strip().split('\n')] outputs['backward_half_transform'] = [[ - float(v) for v in r.strip().split(' ')] for r in out['bwd_half_xfm'].strip().split('\n')] + float(v) for v in r.strip().split(' ')] + for r in out['bwd_half_xfm'].strip().split('\n')] if self.inputs.all_param: - outputs['rot_angles'] = [float(r) for r in out['rot_angles'].strip().split(' ')] - outputs['translations'] = [float(r) for r in out['translations'].strip().split(' ')] - + outputs['rot_angles'] = [ + float(r) for r in out['rot_angles'].strip().split(' ')] + outputs['translations'] = [ + float(r) for r in out['translations'].strip().split(' ')] setattr(self, '_results', outputs) return runtime @@ -702,17 +719,18 @@ class OverlayInputSpec(FSLCommandInputSpec): background_image = File(exists=True, position=4, mandatory=True, argstr='%s', desc='image to use as background') _xor_inputs = ('auto_thresh_bg', 'full_bg_range', 'bg_thresh') - auto_thresh_bg = traits.Bool(desc=('automatically threshold the background ' - 'image'), - argstr='-a', position=5, - xor=_xor_inputs, mandatory=True) + auto_thresh_bg = traits.Bool( + desc=('automatically threshold the background image'), + argstr='-a', position=5, + xor=_xor_inputs, mandatory=True) full_bg_range = traits.Bool(desc='use full range of background image', argstr='-A', position=5, xor=_xor_inputs, mandatory=True) - bg_thresh = traits.Tuple(traits.Float, traits.Float, argstr='%.3f %.3f', - position=5, - desc='min and max values for background intensity', - xor=_xor_inputs, mandatory=True) + bg_thresh = traits.Tuple( + traits.Float, traits.Float, argstr='%.3f %.3f', + position=5, + desc='min and max values for background intensity', + xor=_xor_inputs, mandatory=True) stat_image = File(exists=True, position=6, mandatory=True, argstr='%s', desc='statistical image to overlay in color') stat_thresh = traits.Tuple(traits.Float, traits.Float, position=7, @@ -784,8 +802,9 @@ def _list_outputs(self): if isdefined(self.inputs.stat_image2) and ( not isdefined(self.inputs.show_negative_stats) or not self.inputs.show_negative_stats): - stem = "%s_and_%s" % (split_filename(self.inputs.stat_image)[1], - split_filename(self.inputs.stat_image2)[1]) + stem = "%s_and_%s" % ( + split_filename(self.inputs.stat_image)[1], + split_filename(self.inputs.stat_image2)[1]) else: stem = split_filename(self.inputs.stat_image)[1] out_file = self._gen_fname(stem, suffix='_overlay') @@ -826,10 +845,10 @@ class SlicerInputSpec(FSLCommandInputSpec): desc='label left-right orientation') _xor_options = ('single_slice', 'middle_slices', 'all_axial', 'sample_axial') - single_slice = traits.Enum('x', 'y', 'z', position=10, argstr='-%s', - xor=_xor_options, requires=['slice_number'], - desc=('output picture of single slice in the x, ' - 'y, or z plane')) + single_slice = traits.Enum( + 'x', 'y', 'z', position=10, argstr='-%s', + xor=_xor_options, requires=['slice_number'], + desc=('output picture of single slice in the x, y, or z plane')) slice_number = traits.Int(position=11, argstr='-%d', desc='slice number to save in picture') middle_slices = traits.Bool(position=10, argstr='-a', xor=_xor_options, @@ -926,9 +945,9 @@ class PlotTimeSeriesInputSpec(FSLCommandInputSpec): y_range = traits.Tuple(traits.Float, traits.Float, argstr="%s", xor=("y_min", "y_max"), desc="min and max y axis values") - x_units = traits.Int(argstr="-u %d", usedefault=True, default_value=1, - desc=("scaling units for x-axis (between 1 and length " - "of in file)")) + x_units = traits.Int( + argstr="-u %d", usedefault=True, default_value=1, + desc=("scaling units for x-axis (between 1 and length of in file)")) plot_size = traits.Tuple(traits.Int, traits.Int, argstr="%s", desc="plot image height and width") x_precision = traits.Int(argstr="--precision=%d", @@ -1028,8 +1047,8 @@ class PlotMotionParamsOutputSpec(TraitedSpec): class PlotMotionParams(FSLCommand): - """Use fsl_tsplot to plot the estimated motion parameters from a realignment - program. + """Use fsl_tsplot to plot the estimated motion parameters from a + realignment program. Examples @@ -1049,9 +1068,9 @@ class PlotMotionParams(FSLCommand): The 'in_source' attribute determines the order of columns that are expected in the source file. FSL prints motion parameters in the order rotations, translations, while SPM prints them in the opposite order. This interface - should be able to plot timecourses of motion parameters generated from other - sources as long as they fall under one of these two patterns. For more - flexibilty, see the :class:`fsl.PlotTimeSeries` interface. + should be able to plot timecourses of motion parameters generated from + other sources as long as they fall under one of these two patterns. For + more flexibilty, see the :class:`fsl.PlotTimeSeries` interface. """ _cmd = 'fsl_tsplot' @@ -1118,9 +1137,9 @@ def _gen_filename(self, name): class ConvertXFMInputSpec(FSLCommandInputSpec): in_file = File(exists=True, mandatory=True, argstr="%s", position=-1, desc="input transformation matrix") - in_file2 = File(exists=True, argstr="%s", position=-2, - desc=("second input matrix (for use with fix_scale_skew or " - "concat_xfm")) + in_file2 = File( + exists=True, argstr="%s", position=-2, + desc="second input matrix (for use with fix_scale_skew or concat_xfm)") _options = ["invert_xfm", "concat_xfm", "fix_scale_skew"] invert_xfm = traits.Bool(argstr="-inverse", position=-3, xor=_options, desc="invert input transformation") @@ -1216,7 +1235,8 @@ class SwapDimensions(FSLCommand): This interface accepts a three-tuple corresponding to the new orientation. You may either provide dimension ids in the form of - (-)x, (-)y, or (-z), or nifti-syle dimension codes (RL, LR, AP, PA, IS, SI). + (-)x, (-)y, or (-z), or nifti-syle dimension codes + (RL, LR, AP, PA, IS, SI). """ _cmd = "fslswapdim" @@ -1390,8 +1410,8 @@ def _list_outputs(self): class InvWarpInputSpec(FSLCommandInputSpec): warp = File(exists=True, argstr='--warp=%s', mandatory=True, desc=('Name of file containing warp-coefficients/fields. This ' - 'would typically be the output from the --cout switch of ' - 'fnirt (but can also use fields, like the output from ' + 'would typically be the output from the --cout switch of' + ' fnirt (but can also use fields, like the output from ' '--fout).')) reference = File(exists=True, argstr='--ref=%s', mandatory=True, desc=('Name of a file in target space. Note that the ' @@ -1408,17 +1428,17 @@ class InvWarpInputSpec(FSLCommandInputSpec): 'component included as part of the ' 'displacements.')) absolute = traits.Bool(argstr='--abs', xor=['relative'], - desc=('If set it indicates that the warps in --warp ' - 'should be interpreted as absolute, provided ' - 'that it is not created by fnirt (which ' + desc=('If set it indicates that the warps in --warp' + ' should be interpreted as absolute, provided' + ' that it is not created by fnirt (which ' 'always uses relative warps). If set it also ' 'indicates that the output --out should be ' 'absolute.')) relative = traits.Bool(argstr='--rel', xor=['absolute'], - desc=('If set it indicates that the warps in --warp ' - 'should be interpreted as relative. I.e. the ' - 'values in --warp are displacements from the ' - 'coordinates in the --ref space. If set it ' + desc=('If set it indicates that the warps in --warp' + ' should be interpreted as relative. I.e. the' + ' values in --warp are displacements from the' + ' coordinates in the --ref space. If set it ' 'also indicates that the output --out should ' 'be relative.')) niter = traits.Int(argstr='--niter=%d', @@ -1570,7 +1590,8 @@ def _gen_filename(self, name): elif name == 'magnitude_out_file': return self._gen_fname(self.inputs.complex_in_file, suffix="_mag") elif name == 'phase_out_file': - return self._gen_fname(self.inputs.complex_in_file, suffix="_phase") + return self._gen_fname( + self.inputs.complex_in_file, suffix="_phase") elif name == 'real_out_file': return self._gen_fname(self.inputs.complex_in_file, suffix="_real") elif name == 'imaginary_out_file': @@ -1600,11 +1621,12 @@ def _list_outputs(self): class WarpUtilsInputSpec(FSLCommandInputSpec): - in_file = File(exists=True, argstr='--in=%s', mandatory=True, - desc=('Name of file containing warp-coefficients/fields. This ' - 'would typically be the output from the --cout switch of ' - 'fnirt (but can also use fields, like the output from ' - '--fout).')) + in_file = File( + exists=True, argstr='--in=%s', mandatory=True, + desc=('Name of file containing warp-coefficients/fields. This ' + 'would typically be the output from the --cout switch of ' + 'fnirt (but can also use fields, like the output from ' + '--fout).')) reference = File(exists=True, argstr='--ref=%s', mandatory=True, desc=('Name of a file in target space. Note that the ' 'target space is now different from the target ' @@ -1612,55 +1634,66 @@ class WarpUtilsInputSpec(FSLCommandInputSpec): 'would typically be the file that was specified ' 'with the --in argument when running fnirt.')) - out_format = traits.Enum('spline', 'field', argstr='--outformat=%s', - desc=('Specifies the output format. If set to field (default) ' - 'the output will be a (4D) field-file. If set to spline ' - 'the format will be a (4D) file of spline coefficients.')) - - warp_resolution = traits.Tuple(traits.Float, traits.Float, traits.Float, - argstr='--warpres=%0.4f,%0.4f,%0.4f', - desc=('Specifies the resolution/knot-spacing of the splines pertaining ' - 'to the coefficients in the --out file. This parameter is only ' - 'relevant if --outformat is set to spline. It should be noted ' - 'that if the --in file has a higher resolution, the resulting ' - 'coefficients will pertain to the closest (in a least-squares' - ' sense) file in the space of fields with the --warpres' - ' resolution. It should also be noted that the resolution ' - 'will always be an integer multiple of the voxel ' - 'size.')) - - knot_space = traits.Tuple(traits.Int, traits.Int, traits.Int, - argstr='--knotspace=%d,%d,%d', - desc=('Alternative (to --warpres) specification of the resolution of ' - 'the output spline-field.')) - - out_file = File(argstr='--out=%s', position=-1, name_source=['in_file'], output_name='out_file', - desc=('Name of output file. The format of the output depends on what other ' - 'parameters are set. The default format is a (4D) field-file. If the ' - '--outformat is set to spline the format will be a (4D) file of spline ' - 'coefficients.')) - - write_jacobian = traits.Bool(False, mandatory=True, usedefault=True, - desc='Switch on --jac flag with automatically generated filename') - - out_jacobian = File(argstr='--jac=%s', - desc=('Specifies that a (3D) file of Jacobian determinants corresponding ' - 'to --in should be produced and written to filename.')) - - with_affine = traits.Bool(False, argstr='--withaff', - desc=('Specifies that the affine transform (i.e. that which was ' - 'specified for the --aff parameter in fnirt) should be ' - 'included as displacements in the --out file. That can be ' - 'useful for interfacing with software that cannot decode ' - 'FSL/fnirt coefficient-files (where the affine transform is ' - 'stored separately from the displacements).')) + out_format = traits.Enum( + 'spline', 'field', argstr='--outformat=%s', + desc=('Specifies the output format. If set to field (default) ' + 'the output will be a (4D) field-file. If set to spline ' + 'the format will be a (4D) file of spline coefficients.')) + + warp_resolution = traits.Tuple( + traits.Float, traits.Float, traits.Float, + argstr='--warpres=%0.4f,%0.4f,%0.4f', + desc=('Specifies the resolution/knot-spacing of the splines pertaining' + ' to the coefficients in the --out file. This parameter is only ' + 'relevant if --outformat is set to spline. It should be noted ' + 'that if the --in file has a higher resolution, the resulting ' + 'coefficients will pertain to the closest (in a least-squares' + ' sense) file in the space of fields with the --warpres' + ' resolution. It should also be noted that the resolution ' + 'will always be an integer multiple of the voxel ' + 'size.')) + + knot_space = traits.Tuple( + traits.Int, traits.Int, traits.Int, + argstr='--knotspace=%d,%d,%d', + desc=('Alternative (to --warpres) specification of the resolution of ' + 'the output spline-field.')) + + out_file = File( + argstr='--out=%s', position=-1, name_source=['in_file'], + output_name='out_file', + desc=('Name of output file. The format of the output depends on what ' + 'other parameters are set. The default format is a (4D) ' + 'field-file. If the --outformat is set to spline the format ' + 'will be a (4D) file of spline coefficients.')) + + write_jacobian = traits.Bool( + False, mandatory=True, usedefault=True, + desc='Switch on --jac flag with automatically generated filename') + + out_jacobian = File( + argstr='--jac=%s', + desc=('Specifies that a (3D) file of Jacobian determinants ' + 'corresponding to --in should be produced and written to ' + 'filename.')) + + with_affine = traits.Bool( + False, argstr='--withaff', + desc=('Specifies that the affine transform (i.e. that which was ' + 'specified for the --aff parameter in fnirt) should be ' + 'included as displacements in the --out file. That can be ' + 'useful for interfacing with software that cannot decode ' + 'FSL/fnirt coefficient-files (where the affine transform is ' + 'stored separately from the displacements).')) class WarpUtilsOutputSpec(TraitedSpec): out_file = File( - desc=('Name of output file, containing the warp as field or coefficients.')) - out_jacobian = File(desc=('Name of output file, containing the map of the determinant of ' - 'the Jacobian')) + desc=('Name of output file, containing the warp as field or ' + 'coefficients.')) + out_jacobian = File( + desc=('Name of output file, containing the map of the determinant of ' + 'the Jacobian')) class WarpUtils(FSLCommand): @@ -1695,7 +1728,8 @@ def _parse_inputs(self, skip=None): skip = [] suffix = 'field' - if isdefined(self.inputs.out_format) and self.inputs.out_format == 'spline': + if (isdefined(self.inputs.out_format) and + self.inputs.out_format == 'spline'): suffix = 'coeffs' trait_spec = self.inputs.trait('out_file') @@ -1715,52 +1749,64 @@ def _parse_inputs(self, skip=None): class ConvertWarpInputSpec(FSLCommandInputSpec): - reference = File(exists=True, argstr='--ref=%s', mandatory=True, position=1, - desc='Name of a file in target space of the full transform.') + reference = File( + exists=True, argstr='--ref=%s', mandatory=True, position=1, + desc='Name of a file in target space of the full transform.') - out_file = File(argstr='--out=%s', position=-1, name_source=['reference'], - name_template='%s_concatwarp', output_name='out_file', - desc=('Name of output file, containing warps that are the combination of all ' - 'those given as arguments. The format of this will be a field-file (rather ' - 'than spline coefficients) with any affine components included.')) + out_file = File( + argstr='--out=%s', position=-1, name_source=['reference'], + name_template='%s_concatwarp', output_name='out_file', + desc=('Name of output file, containing warps that are the combination ' + 'of all those given as arguments. The format of this will be a ' + 'field-file (rather than spline coefficients) with any affine ' + 'components included.')) premat = File(exists=True, argstr='--premat=%s', desc='filename for pre-transform (affine matrix)') warp1 = File(exists=True, argstr='--warp1=%s', - desc='Name of file containing initial warp-fields/coefficients (follows premat). This could e.g. be a ' - 'fnirt-transform from a subjects structural scan to an average of a group ' - 'of subjects.') + desc='Name of file containing initial ' + 'warp-fields/coefficients (follows premat). This could ' + 'e.g. be a fnirt-transform from a subjects structural ' + 'scan to an average of a group of subjects.') midmat = File(exists=True, argstr="--midmat=%s", desc="Name of file containing mid-warp-affine transform") - warp2 = File(exists=True, argstr='--warp2=%s', - desc='Name of file containing secondary warp-fields/coefficients (after warp1/midmat but before postmat). This could e.g. be a ' - 'fnirt-transform from the average of a group of subjects to some standard ' - 'space (e.g. MNI152).') - - postmat = File(exists=True, argstr='--postmat=%s', - desc='Name of file containing an affine transform (applied last). It could e.g. be an affine ' - 'transform that maps the MNI152-space into a better approximation to the ' - 'Talairach-space (if indeed there is one).') - - shift_in_file = File(exists=True, argstr='--shiftmap=%s', - desc='Name of file containing a "shiftmap", a non-linear transform with ' - 'displacements only in one direction (applied first, before premat). This would typically be a ' - 'fieldmap that has been pre-processed using fugue that maps a ' - 'subjects functional (EPI) data onto an undistorted space (i.e. a space ' - 'that corresponds to his/her true anatomy).') - - shift_direction = traits.Enum('y-', 'y', 'x', 'x-', 'z', 'z-', - argstr="--shiftdir=%s", requires=['shift_in_file'], - desc='Indicates the direction that the distortions from ' - '--shiftmap goes. It depends on the direction and ' - 'polarity of the phase-encoding in the EPI sequence.') - - cons_jacobian = traits.Bool(False, argstr='--constrainj', - desc='Constrain the Jacobian of the warpfield to lie within specified ' - 'min/max limits.') + warp2 = File( + exists=True, argstr='--warp2=%s', + desc='Name of file containing secondary warp-fields/coefficients ' + '(after warp1/midmat but before postmat). This could e.g. be a ' + 'fnirt-transform from the average of a group of subjects to some ' + 'standard space (e.g. MNI152).') + + postmat = File( + exists=True, argstr='--postmat=%s', + desc='Name of file containing an affine transform (applied last). It ' + 'could e.g. be an affine transform that maps the MNI152-space ' + 'into a better approximation to the Talairach-space (if indeed ' + 'there is one).') + + shift_in_file = File( + exists=True, argstr='--shiftmap=%s', + desc='Name of file containing a "shiftmap", a non-linear transform ' + 'with displacements only in one direction (applied first, before ' + 'premat). This would typically be a fieldmap that has been ' + 'pre-processed using fugue that maps a subjects functional (EPI) ' + 'data onto an undistorted space (i.e. a space that corresponds ' + 'to his/her true anatomy).') + + shift_direction = traits.Enum( + 'y-', 'y', 'x', 'x-', 'z', 'z-', + argstr="--shiftdir=%s", requires=['shift_in_file'], + desc='Indicates the direction that the distortions from ' + '--shiftmap goes. It depends on the direction and ' + 'polarity of the phase-encoding in the EPI sequence.') + + cons_jacobian = traits.Bool( + False, argstr='--constrainj', + desc='Constrain the Jacobian of the warpfield to lie within specified ' + 'min/max limits.') jacobian_min = traits.Float(argstr='--jmin=%f', desc='Minimum acceptable Jacobian value for ' @@ -1769,30 +1815,38 @@ class ConvertWarpInputSpec(FSLCommandInputSpec): desc='Maximum acceptable Jacobian value for ' 'constraint (default 100.0)') - abswarp = traits.Bool(argstr='--abs', xor=['relwarp'], - desc='If set it indicates that the warps in --warp1 and --warp2 should be ' - 'interpreted as absolute. I.e. the values in --warp1/2 are the ' - 'coordinates in the next space, rather than displacements. This flag ' - 'is ignored if --warp1/2 was created by fnirt, which always creates ' - 'relative displacements.') - - relwarp = traits.Bool(argstr='--rel', xor=['abswarp'], - desc='If set it indicates that the warps in --warp1/2 should be interpreted ' - 'as relative. I.e. the values in --warp1/2 are displacements from the ' - 'coordinates in the next space.') - - out_abswarp = traits.Bool(argstr='--absout', xor=['out_relwarp'], - desc='If set it indicates that the warps in --out should be absolute, i.e. ' - 'the values in --out are displacements from the coordinates in --ref.') - - out_relwarp = traits.Bool(argstr='--relout', xor=['out_abswarp'], - desc='If set it indicates that the warps in --out should be relative, i.e. ' - 'the values in --out are displacements from the coordinates in --ref.') + abswarp = traits.Bool( + argstr='--abs', xor=['relwarp'], + desc='If set it indicates that the warps in --warp1 and --warp2 should' + ' be interpreted as absolute. I.e. the values in --warp1/2 are ' + 'the coordinates in the next space, rather than displacements. ' + 'This flag is ignored if --warp1/2 was created by fnirt, which ' + 'always creates relative displacements.') + + relwarp = traits.Bool( + argstr='--rel', xor=['abswarp'], + desc='If set it indicates that the warps in --warp1/2 should be ' + 'interpreted as relative. I.e. the values in --warp1/2 are ' + 'displacements from the coordinates in the next space.') + + out_abswarp = traits.Bool( + argstr='--absout', xor=['out_relwarp'], + desc='If set it indicates that the warps in --out should be absolute, ' + 'i.e. the values in --out are displacements from the coordinates ' + 'in --ref.') + + out_relwarp = traits.Bool( + argstr='--relout', xor=['out_abswarp'], + desc='If set it indicates that the warps in --out should be relative, ' + 'i.e. the values in --out are displacements from the coordinates ' + 'in --ref.') class ConvertWarpOutputSpec(TraitedSpec): - out_file = File(exists=True, - desc='Name of output file, containing the warp as field or coefficients.') + out_file = File( + exists=True, + desc='Name of output file, containing the warp as field or ' + 'coefficients.') class ConvertWarp(FSLCommand): @@ -1846,8 +1900,10 @@ class WarpPointsInputSpec(WarpPointsBaseInputSpec): class WarpPointsOutputSpec(TraitedSpec): - out_file = File(exists=True, - desc='Name of output file, containing the warp as field or coefficients.') + out_file = File( + exists=True, + desc='Name of output file, containing the warp as field or ' + 'coefficients.') class WarpPoints(CommandLine): @@ -1903,8 +1959,8 @@ def _parse_inputs(self, skip=None): if ext in ['.vtk', '.trk']: if self._tmpfile is None: - self._tmpfile = tempfile.NamedTemporaryFile(suffix='.txt', dir=os.getcwd(), - delete=False).name + self._tmpfile = tempfile.NamedTemporaryFile( + suffix='.txt', dir=os.getcwd(), delete=False).name second_args = self._tmpfile return first_args + [second_args] @@ -1914,7 +1970,8 @@ def _vtk_to_coords(self, in_file, out_file=None): from ...interfaces import vtkbase as VTKInfo if VTKInfo.no_tvtk(): - raise ImportError('TVTK is required and tvtk package was not found') + raise ImportError( + 'TVTK is required and tvtk package was not found') reader = tvtk.PolyDataReader(file_name=in_file + '.vtk') reader.update() @@ -1932,7 +1989,8 @@ def _coords_to_vtk(self, points, out_file): from ...interfaces import vtkbase as VTKInfo if VTKInfo.no_tvtk(): - raise ImportError('TVTK is required and tvtk package was not found') + raise ImportError( + 'TVTK is required and tvtk package was not found') reader = tvtk.PolyDataReader(file_name=self.inputs.in_file) reader.update() @@ -2009,8 +2067,8 @@ class WarpPointsToStdInputSpec(WarpPointsBaseInputSpec): class WarpPointsToStd(WarpPoints): """ Use FSL `img2stdcoord `_ - to transform point sets to standard space coordinates. Accepts plain text files and - vtk files. + to transform point sets to standard space coordinates. Accepts plain text + files and vtk files. .. Note:: transformation of TrackVis trk files is not yet implemented @@ -2039,26 +2097,40 @@ class WarpPointsToStd(WarpPoints): class MotionOutliersInputSpec(FSLCommandInputSpec): in_file = File( - exists=True, mandatory=True, desc="unfiltered 4D image", argstr="-i %s") - out_file = File(argstr="-o %s", name_source='in_file', name_template='%s_outliers.txt', - keep_extension=True, desc='output outlier file name', hash_files=False) + exists=True, mandatory=True, desc="unfiltered 4D image", + argstr="-i %s") + out_file = File(argstr="-o %s", name_source='in_file', + name_template='%s_outliers.txt', + keep_extension=True, desc='output outlier file name', + hash_files=False) mask = File( exists=True, argstr="-m %s", desc="mask image for calculating metric") metric = traits.Enum( 'refrms', ['refrms', 'dvars', 'refmse', 'fd', 'fdrms'], argstr="--%s", - desc='metrics: refrms - RMS intensity difference to reference volume as metric [default metric], ' - 'refmse - Mean Square Error version of refrms (used in original version of fsl_motion_outliers), ' - 'dvars - DVARS, fd - frame displacement, fdrms - FD with RMS matrix calculation') + desc='metrics: refrms - RMS intensity difference to reference volume ' + 'as metric [default metric], refmse - Mean Square Error version ' + 'of refrms (used in original version of fsl_motion_outliers), ' + 'dvars - DVARS, fd - frame displacement, fdrms - FD with RMS ' + 'matrix calculation') threshold = traits.Float(argstr="--thresh=%g", - desc="specify absolute threshold value (otherwise use box-plot cutoff = P75 + 1.5*IQR)") + desc=("specify absolute threshold value " + "(otherwise use box-plot cutoff = P75 + " + "1.5*IQR)")) no_motion_correction = traits.Bool( - argstr="--nomoco", desc="do not run motion correction (assumed already done)") - dummy = traits.Int(argstr="--dummy=%d", - desc='number of dummy scans to delete (before running anything and creating EVs)') - out_metric_values = File(argstr="-s %s", name_source='in_file', name_template='%s_metrics.txt', - keep_extension=True, desc='output metric values (DVARS etc.) file name', hash_files=False) - out_metric_plot = File(argstr="-p %s", name_source='in_file', name_template='%s_metrics.png', hash_files=False, - keep_extension=True, desc='output metric values plot (DVARS etc.) file name') + argstr="--nomoco", + desc="do not run motion correction (assumed already done)") + dummy = traits.Int( + argstr="--dummy=%d", + desc='number of dummy scans to delete (before running anything and ' + 'creating EVs)') + out_metric_values = File( + argstr="-s %s", name_source='in_file', name_template='%s_metrics.txt', + keep_extension=True, + desc='output metric values (DVARS etc.) file name', hash_files=False) + out_metric_plot = File( + argstr="-p %s", name_source='in_file', name_template='%s_metrics.png', + hash_files=False, keep_extension=True, + desc='output metric values plot (DVARS etc.) file name') class MotionOutliersOutputSpec(TraitedSpec):