From d87e90fb3a03540a592ea641f1048754e10d635f Mon Sep 17 00:00:00 2001 From: jason-wg Date: Mon, 21 Dec 2015 12:34:41 -0800 Subject: [PATCH 01/25] Create brainsuite.py I created an interface for Brainsuite's command line tools. I'd like it to be included in nipype builds installed per the instructions on the nipype website. --- nipype/interfaces/brainsuite.py | 711 ++++++++++++++++++++++++++++++++ 1 file changed, 711 insertions(+) create mode 100644 nipype/interfaces/brainsuite.py diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py new file mode 100644 index 0000000000..01eb3f39ff --- /dev/null +++ b/nipype/interfaces/brainsuite.py @@ -0,0 +1,711 @@ +import os +import re as regex + +from nipype.interfaces.base import( + TraitedSpec, + CommandLineInputSpec, + CommandLine, + File, + traits, + isdefined, +) + + +class bseInputSpec(CommandLineInputSpec): + + inputMRIFile = File(exists=True, mandatory=True, argstr='-i %s', desc='input MRI volume', position=0) + + outputMRIVolume = File(mandatory=False, desc='output brain-masked MRI volume. If unspecified, output file name will be auto generated.', argstr='-o %s', position=1, hash_files=False, genfile=True) + + diffusionConstant = traits.Float(25, usedefault=True, desc='diffusion constant [default if unspecified: 25]' , argstr='-d %f') + + diffusionIterations = traits.Int(3, usedefault=True, desc='diffusion iterations [default if unspecified: 3]', argstr='-n %d') + + edgeDetectionConstant = traits.Float(0.64, usedefault=True, desc='edge detection constant [default if unspecified: 0.64]', argstr='-s %f') + + radius = traits.Float(1, usedefault=True, desc='radius of erosion/dilation filter [default if unspecified: 1]', argstr='-r %f') + + dilateFinalMask = traits.Bool(True, usedefault=True, desc='dilate final mask [default if unspecified: True]', argstr='-p') + + trim = traits.Bool(True, usedefault=True, desc='trim brainstem [default if unspecified: True]', argstr='--trim') + + outputMaskFile = File(mandatory=False, desc='save smooth brain mask' , argstr='--mask %s', hash_files=False) + + outputDiffusionFilter = File(desc='diffusion filter output', argstr='--adf %s', hash_files=False) + + outputEdgeMap = File(desc='edge map output', argstr='--edge %s', hash_files=False) + + outputDetailedBrainMask = File(desc='save detailed brain mask', argstr='--hires %s', hash_files=False) + + outputCortexFile = File(desc='cortex file', argstr='--cortex %s', hash_files=False) + + verbosityLevel = traits.Float(1, usedefault=True, desc=' verbosity level (0=silent) [default if unspecified: 1]', argstr='-v %f') + + noRotate = traits.Bool(True, usedefault=True, desc='retain original orientation (default behavior will auto-rotate input NII files to LPI orientation) [default if unspecified: True]', argstr='--norotate') + + timer = traits.Bool(desc='show timing', argstr='--timer') + + +class bseOutputSpec(TraitedSpec): + outputMRIVolume = File(desc='path/name of brain-masked MRI volume') + outputMaskFile = File(desc='path/name of smooth brain mask') + outputDiffusionFilter = File(desc='path/name of diffusion filter output') + outputEdgeMap = File(desc='path/name of edge map output') + outputDetailedBrainMask = File(desc='path/name of detailed brain mask') + outputCortexFile = File(desc='path/name of cortex file') + + +class bse(CommandLine): + input_spec = bseInputSpec + output_spec = bseOutputSpec + _cmd = 'bse' + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputMRIVolume): + outputs['outputMRIVolume'] = (os.getcwd() + '/' + self.inputs.outputMRIVolume) + else: + outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') + + + if isdefined(self.inputs.outputMaskFile): + outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + if isdefined(self.inputs.outputDiffusionFilter): + outputs['outputDiffusionFilter'] = (os.getcwd() + '/' + self.inputs.outputDiffusionFilter) + if isdefined(self.inputs.outputEdgeMap): + outputs['outputEdgeMap'] = (os.getcwd() + '/' + self.inputs.outputEdgeMap) + if isdefined(self.inputs.outputDetailedBrainMask): + outputs['outputDetailedBrainMask'] = (os.getcwd() + '/' + self.inputs.outputDetailedBrainMask) + if isdefined(self.inputs.outputCortexFile): + outputs['outputCortexFile'] = (os.getcwd() + '/' + self.inputs.outputCortexFile) + + return outputs + + def _gen_filename(self, name): + if name=='outputMRIVolume': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + + + + +class bfcInputSpec(CommandLineInputSpec): + inputMRIFile = File(exists = True, mandatory=True, desc='input skull-stripped MRI volume', argstr='-i %s', position=0) + + outputMRIVolume = File(mandatory=False, desc='output bias-corrected MRI volume. If unspecified, output file name will be auto generated.', argstr='-o %s', position=1, hash_files=False, genfile=True) + + outputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) + + outputBiasField = File(desc='save bias field estimate', argstr='--bias %s', hash_files=False) + + outputMaskedBiasField = File(desc='save bias field estimate (masked)', argstr='--maskedbias %s', hash_files=False) + + histogramRadius = traits.Int(desc='histogram radius (voxels)', argstr='-r %d') + + biasEstimateSpacing = traits.Int(desc='bias sample spacing (voxels)', argstr='-s %d') + + controlPointSpacing = traits.Int(desc='control point spacing (voxels)', argstr='-c %d') + + splineLambda = traits.Float(desc='spline stiffness weighting parameter', argstr='-w %f') + + histogramType = traits.Enum('ellipse', 'block', desc="Options for type of histogram\nellipse: use ellipsoid for ROI histogram\nblock:use block for ROI histogram", argstr='%s') + + iterativeMode = traits.Bool(desc='iterative mode (overrides -r, -s, -c, -w settings)', argstr='--iterate') + + correctionScheduleFile = File(desc='list of parameters ', argstr='--schedule %s') + + biasFieldEstimatesOutputPrefix = traits.Str(desc='save iterative bias field estimates as .n.field.nii.gz', argstr='--biasprefix %s') + + correctedImagesOutputPrefix = traits.Str(desc='save iterative corrected images as .n.bfc.nii.gz', argstr='--prefix %s') + + correctWholeVolume = traits.Bool(desc='apply correction field to entire volume', argstr='--extrapolate') + + minBias = traits.Float(0.5, usedefault=True, desc='minimum allowed bias value [default if unspecified: 0.5]', argstr='-L %f') + + maxBias = traits.Float(1.5, usedefault=True, desc='maximum allowed bias value [default if unspecified: 1.5]', argstr='-U %f') + + biasRange = traits.Enum("low", "medium", "high", desc="Preset options for bias_model\nlow: small bias model [0.95,1.05]\nmedium: medium bias model [0.90,1.10]\nhigh: high bias model [0.80,1.20]", argstr='%s') + intermediate_file_type = traits.Enum("analyze", "nifti", "gzippedAnalyze", "gzippedNifti", desc="Options for the format in which intermediate files are generated", argstr='%s') + + convergenceThreshold = traits.Float(desc='convergence threshold', argstr='--eps %f') + + biasEstimateConvergenceThreshold = traits.Float(desc='bias estimate convergence threshold (values > 0.1 disable)', argstr='--beps %f') + + verbosityLevel = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') + + timer = traits.Bool(desc='display timing information', argstr='--timer') + + + +class bfcOutputSpec(TraitedSpec): + outputMRIVolume = File(desc='path/name of output file') + outputMaskFile = File(desc='path/name of mask output file') + outputBiasField = File(desc='path/name of bias field output file') + outputMaskedBiasField = File(desc='path/name of masked bias field output') + correctionScheduleFile = File(desc='path/name of schedule file') + +class bfc(CommandLine): + input_spec = bfcInputSpec + output_spec = bfcOutputSpec + _cmd = 'bfc' + + def _gen_filename(self, name): + if name=='outputMRIVolume': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _format_arg(self, name, spec, value): + if name == 'histogramType': + return spec.argstr%{"ellipse":"--ellipse" , "block":"--block"}[value] + if name == 'biasRange': + return spec.argstr%{"low":"--low" , "medium":"--medium", "high":"--high"}[value] + if name == 'intermediate_file_type': + return spec.argstr%{"analyze":"--analyze" , "nifti":"--nifti", "gzippedAnalyze":"--analyzegz", "gzippedNifti":"--niftigz"}[value] + + return super(bfc, self)._format_arg(name, spec, value) + + + + def _list_outputs(self): + outputs = self.output_spec().get() + + if isdefined(self.inputs.outputMRIVolume): + outputs['outputMRIVolume'] = (os.getcwd() + '/' + self.inputs.outputMRIVolume) + else: + outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') + + + if isdefined(self.inputs.outputMaskFile): + outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + if isdefined(self.inputs.outputBiasField): + outputs['outputBiasField'] = (os.getcwd() + '/' + self.inputs.outputBiasField) + if isdefined(self.inputs.outputMaskedBiasField): + outputs['outputMaskedBiasField'] = (os.getcwd() + '/' + self.inputs.outputMaskedBiasField) + if isdefined(self.inputs.correctionScheduleFile): + outputs['correctionScheduleFile'] = (os.getcwd() + '/' + self.inputs.correctionScheduleFile) + + return outputs + + + + + + + +class pvcInputSpec(CommandLineInputSpec): + inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') + inputMaskFile = File(desc='brain mask file', argstr='-m %s') + outputLabelFile = File(mandatory=False, desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + outputTissueFractionFile = File(mandatory=False, desc='output tissue fraction file', argstr='-f %s', genfile=True) + spatialPrior = traits.Float(desc='spatial prior strength', argstr='-l %f') + verbosity = traits.Int(desc='verbosity level (0 = silent)', argstr='-v %d') + threeClassFlag = traits.Bool(desc='use a three-class (CSF=0,GM=1,WM=2) labeling', argstr='-3') + timer = traits.Bool(desc='time processing', argstr='--timer') + +class pvcOutputSpec(TraitedSpec): + outputLabelFile = File(desc='path/name of label file') + outputTissueFractionFile = File(desc='path/name of tissue fraction file') + +class pvc(CommandLine): + input_spec = pvcInputSpec + output_spec = pvcOutputSpec + _cmd = 'pvc' + + + def _gen_filename(self, name): + if name=='outputLabelFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', self._cmd, 'Output_', name, myExtension)) + if name=='outputTissueFractionFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputLabelFile): + outputs['outputLabelFile'] = (os.getcwd() + '/' + self.inputs.outputLabelFile) + else: + outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') + + if isdefined(self.inputs.outputTissueFractionFile): + outputs['outputTissueFractionFile'] = (os.getcwd() + '/' + self.inputs.outputTissueFractionFile) + else: + outputs['outputTissueFractionFile'] = self._gen_filename('outputTissueFractionFile') + + return outputs + + + + + + +class cerebroInputSpec(CommandLineInputSpec): + inputMRIFile = File(mandatory=True, desc='input 3D MRI volume', argstr='-i %s') + inputAtlasMRIFile = File(mandatory=True, desc='atlas MRI volume', argstr='--atlas %s') + inputAtlasLabelFile = File(mandatory=True, desc='atlas labeling', argstr='--atlaslabels %s') + inputBrainMaskFile = File(desc='brain mask file', argstr='-m %s') + outputCerebrumMaskFile = File(mandatory=False, desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + outputLabelMaskFile = File(mandatory=False, desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', argstr='-l %s', genfile=True) + costFunction = traits.Int(2, usedefault=True, desc='0,1,2 [default if unspecified: 2]', argstr='-c %d') + useCentroids = traits.Bool(desc='use centroids of data to initialize position', argstr='--centroids') + outputAffineTransformFile = File(desc='save affine transform to file.', argstr='--air %s') + outputWarpTransformFile = File(desc='save warp transform to file.', argstr='--warp %s') + verbosity = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') + linearConvergence = traits.Float(desc='linear convergence', argstr='--linconv %f') + warpLabel = traits.Int(desc='warp order (2,3,4,5,6,7,8)', argstr='--warplevel %d') + warpConvergence = traits.Float(desc='warp convergence', argstr='--warpconv %f') + keepTempFiles = traits.Bool(desc="don't remove temporary files", argstr='--keep') + tempDirectory = traits.Str(desc='specify directory to use for temporary files', argstr='--tempdir %s') + tempDirectoryBase = traits.Str(desc='create a temporary directory within this directory', argstr='--tempdirbase %s') + + +class cerebroOutputSpec(TraitedSpec): + outputCerebrumMaskFile = File(desc='path/name of cerebrum mask file') + outputLabelMaskFile = File(desc='path/name of label mask file') + outputAffineTransformFile = File(desc='path/name of affine transform file') + outputWarpTransformFile = File(desc='path/name of warp transform file') + + +class cerebro(CommandLine): + input_spec = cerebroInputSpec + output_spec = cerebroOutputSpec + _cmd = 'cerebro' + + def _gen_filename(self, name): + if name=='outputCerebrumMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + if name=='outputLabelMaskFile': + myExtension= '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputCerebrumMaskFile): + outputs['outputCerebrumMaskFile'] = (os.getcwd() + '/' + self.inputs.outputCerebrumMaskFile) + else: + outputs['outputCerebrumMaskFile'] = self._gen_filename('outputCerebrumMaskFile') + + + if isdefined(self.inputs.outputLabelMaskFile): + outputs['outputLabelMaskFile'] = (os.getcwd() + '/' + self.inputs.outputLabelMaskFile) + else: + outputs['outputLabelMaskFile'] = self._gen_filename('outputLabelMaskFile') + + + if isdefined(self.inputs.outputAffineTransformFile): + outputs['outputAffineTransformFile'] = (os.getcwd() + '/' + self.inputs.outputAffineTransformFile) + if isdefined(self.inputs.outputWarpTransformFile): + outputs['outputWarpTransformFile'] = (os.getcwd() + '/' + self.inputs.outputWarpTransformFile) + + return outputs + + + + + + +class cortexInputSpec(CommandLineInputSpec): + inputHemisphereLabelFile = File(mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') + outputCerebrumMask = File(mandatory=False, desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + inputTissueFractionFile = File(mandatory=True, desc='tissue fraction file (32-bit float)', argstr='-f %s') + tissueFractionThreshold = traits.Float(50.0, usedefault=True, desc='tissue fraction threshold (percentage) [default if unspecified: 50]', argstr='-p %f') + computeWGBoundary = traits.Bool(True, usedefault=True, desc='compute WM/GM boundary [default if unspecified: True]', argstr='-w') + computeGCBoundary = traits.Bool(desc='compute GM/CSF boundary', argstr='-g') + includeAllSubcorticalAreas = traits.Bool(True, usedefault=True, esc='include all subcortical areas in WM mask [default if unspecified: True]', argstr='-a') + verbosity = traits.Int(desc='verbosity level', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + +class cortexOutputSpec(TraitedSpec): + outputCerebrumMask = File(desc='path/name of cerebrum mask') + + +class cortex(CommandLine): + input_spec = cortexInputSpec + output_spec = cortexOutputSpec + _cmd = 'cortex' + + def _gen_filename(self, name): + if name=='outputCerebrumMask': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputCerebrumMask): + outputs['outputCerebrumMask'] = (os.getcwd() + '/' + self.inputs.outputCerebrumMask) + else: + outputs['outputCerebrumMask'] = self._gen_filename('outputCerebrumMask') + + + + return outputs + + + + + + + +class scrubmaskInputSpec(CommandLineInputSpec): + inputMaskFile = File(mandatory=True, desc='input structure mask file', argstr='-i %s') + outputMaskFile = File(mandatory=False, desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + backgroundFillThreshold = traits.Int(2, usedefault=True, desc='background fill threshold [default if unspecified: 2]', argstr='-b %d') + foregroundTrimThreshold = traits.Int(0, usedefault=True, desc='foreground trim threshold [default if unspecified: 0]', argstr='-f %d') + numberIterations = traits.Int(desc='number of iterations', argstr='-n %d') + verbosity = traits.Int(desc='verbosity (0=silent)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + +class scrubmaskOutputSpec(TraitedSpec): + outputMaskFile = File(desc='path/name of mask file') + + +class scrubmask(CommandLine): + input_spec = scrubmaskInputSpec + output_spec = scrubmaskOutputSpec + _cmd = 'scrubmask' + + + def _gen_filename(self, name): + if name=='outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputMaskFile): + outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + else: + outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') + + return outputs + + + + + + + +class tcaInputSpec(CommandLineInputSpec): + inputMaskFile = File(mandatory=True, desc='input mask volume', argstr='-i %s') + outputMaskFile = File(mandatory=False, desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + minCorrectionSize = traits.Int(2500, usedefault=True, desc='maximum correction size [default if unspecified: 2500]', argstr='-m %d') + maxCorrectionSize = traits.Int(desc='minimum correction size', argstr='-n %d') + foregroundDelta = traits.Int(20, usedefault=True, desc='foreground delta [default if unspecified: 20]', argstr='--delta %d') + verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + +class tcaOutputSpec(TraitedSpec): + outputMaskFile = File(desc='path/name of mask file') + + +class tca(CommandLine): + input_spec = tcaInputSpec + output_spec = tcaOutputSpec + _cmd = 'tca' + + + + def _gen_filename(self, name): + if name=='outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputMaskFile): + outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + else: + outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') + + return outputs + + + + + + +class dewispInputSpec(CommandLineInputSpec): + inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') + outputMaskFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + verbosity = traits.Int(desc='verbosity', argstr='-v %d') + sizeThreshold = traits.Int(desc='size threshold', argstr='-t %d') + maximumIterations = traits.Int(desc='maximum number of iterations', argstr='-n %d') + timer = traits.Bool(desc='time processing', argstr='--timer') + +class dewispOutputSpec(TraitedSpec): + outputMaskFile = File(desc='path/name of mask file') + + +class dewisp(CommandLine): + input_spec = dewispInputSpec + output_spec = dewispOutputSpec + _cmd = 'dewisp' + + + def _gen_filename(self, name): + if name=='outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputMaskFile): + outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + else: + outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') + + return outputs + + + + + + + + + +class dfsInputSpec(CommandLineInputSpec): + inputVolumeFile = File(mandatory=True, desc='input 3D volume', argstr='-i %s') + outputSurfaceFile = File(mandatory=False, desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + inputShadingVolume = File(desc='shade surface model with data from image volume', argstr='-c %s') + smoothingIterations = traits.Int(10, usedefault=True, desc='number of smoothing iterations [default if unspecified: 10]', argstr='-n %d') + smoothingConstant = traits.Float(0.5, usedefault=True, desc='smoothing constant [default if unspecified: 0.5]', argstr='-a %f') + curvatureWeighting = traits.Float(5.0, usedefault=True, desc='curvature weighting [default if unspecified: 5.0]', argstr='-w %f') + scalingPercentile = traits.Float(desc='scaling percentile', argstr='-f %f') + nonZeroTessellation = traits.Bool(desc='tessellate non-zero voxels', argstr='-nz', xor=('nonZeroTessellation', 'specialTessellation')) + tessellationThreshold = traits.Float(desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%f') + specialTessellation = traits.Enum('greater_than', 'less_than', 'equal_to', desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%s', xor=('nonZeroTessellation', 'specialTessellation'), requires=['tessellationThreshold'], position=-1) + zeroPadFlag = traits.Bool(desc='zero-pad volume (avoids clipping at edges)', argstr='-z') + noNormalsFlag = traits.Bool(desc='do not compute vertex normals', argstr='--nonormals') + postSmoothFlag = traits.Bool(desc='smooth vertices after coloring', argstr='--postsmooth') + verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + +class dfsOutputSpec(TraitedSpec): + outputSurfaceFile = File(desc='path/name of surface file') + +class dfs(CommandLine): + input_spec = dfsInputSpec + output_spec = dfsOutputSpec + _cmd = 'dfs' + + def _format_arg(self, name, spec, value): + if name == 'tessellationThreshold': + return '' #blank argstr + if name == 'specialTessellation': + threshold = self.inputs.tessellationThreshold + return spec.argstr%{"greater_than":''.join(("-gt %f" % threshold)), "less_than":''.join(("-lt %f" % threshold)) , "equal_to":''.join(("-eq %f" % threshold))}[value] + return super(dfs, self)._format_arg(name, spec, value) + + + def _gen_filename(self, name): + if name=='outputSurfaceFile': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputSurfaceFile): + outputs['outputSurfaceFile'] = (os.getcwd() + '/' + self.inputs.outputSurfaceFile) + else: + outputs['outputSurfaceFile'] = self._gen_filename('outputSurfaceFile') + + return outputs + + + + +class pialmeshInputSpec(CommandLineInputSpec): + inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') + outputSurfaceFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + verbosity = traits.Int(desc='verbosity', argstr='-v %d') + inputTissueFractionFile = File(mandatory=True, desc='floating point (32) tissue fraction image', argstr='-f %s') + numIterations = traits.Int(100, usedefault=True, desc='number of iterations [default if unspecified: 100]', argstr='-n %d') + searchRadius = traits.Float(1, usedefault=True, desc='search radius [default if unspecified: 1]', argstr='-r %f') + stepSize = traits.Float(0.4, usedefault=True, desc='step size [default if unspecified: 0.4]', argstr='-s %f') + inputMaskFile = File(mandatory=True, desc='restrict growth to mask file region', argstr='-m %s') + maxThickness = traits.Float(20, usedefault=True, desc='maximum allowed tissue thickness [default if unspecified: 20]', argstr='--max %f') + tissueThreshold = traits.Float(1.05, usedefault=True, desc='tissue threshold [default if unspecified: 1.05]', argstr='-t %f') +# output interval is not an output -- it specifies how frequently the output surfaces are generated + outputInterval = traits.Int(10, usedefault=True, desc='output interval [default if unspecified: 10]', argstr='--interval %d') + exportPrefix = traits.Str(desc='prefix for exporting surfaces if interval is set', argstr='--prefix %s') + laplacianSmoothing = traits.Float(0.025, usedefault=True, desc='apply Laplacian smoothing [default if unspecified: 0.025]', argstr='--smooth %f') + timer = traits.Bool(desc='show timing', argstr='--timer') + recomputNormals = traits.Bool(desc='recompute normals at each iteration', argstr='--norm') + normalSmoother = traits.Float(0.2, usedefault=True, desc='strength of normal smoother. [default if unspecified: 0.2]', argstr='--nc %f') + tangentSmoother = traits.Float(desc='strength of tangential smoother.', argstr='--tc %f') + + +class pialmeshOutputSpec(TraitedSpec): + outputSurfaceFile = File(desc='path/name of surface file') + + +class pialmesh(CommandLine): + input_spec = pialmeshInputSpec + output_spec = pialmeshOutputSpec + _cmd = 'pialmesh' + + + def _gen_filename(self, name): + if name=='outputSurfaceFile': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputSurfaceFile): + outputs['outputSurfaceFile'] = (os.getcwd() + '/' + self.inputs.outputSurfaceFile) + else: + outputs['outputSurfaceFile'] = self._gen_filename('outputSurfaceFile') + + return outputs + + + + + + + + +class skullfinderInputSpec(CommandLineInputSpec): + inputMRIFile = File(mandatory=True, desc='input file', argstr='-i %s') + inputMaskFile = File(mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') + outputLabelFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + verbosity = traits.Int(desc='verbosity', argstr='-v %d') + lowerThreshold = traits.Int(desc='Lower threshold for segmentation', argstr='-l %d') + upperThreshold = traits.Int(desc='Upper threshold for segmentation', argstr='-u %d') + surfaceFilePrefix = traits.Str(desc='if specified, generate surface files for brain, skull, and scalp', argstr='-s %s') + bgLabelValue = traits.Int(desc='background label value (0-255)', argstr='--bglabel %d') + scalpLabelValue = traits.Int(desc='scalp label value (0-255)', argstr='--scalplabel %d') + skullLabelValue = traits.Int(desc='skull label value (0-255)', argstr='--skulllabel %d') + spaceLabelValue = traits.Int(desc='space label value (0-255)', argstr='--spacelabel %d') + brainLabelValue = traits.Int(desc='brain label value (0-255)', argstr='--brainlabel %d') + performFinalOpening = traits.Bool(desc='perform a final opening operation on the scalp mask', argstr='--finalOpening') + +class skullfinderOutputSpec(TraitedSpec): + outputLabelFile = File(desc='path/name of label file') + + +class skullfinder(CommandLine): + input_spec = skullfinderInputSpec + output_spec = skullfinderOutputSpec + _cmd = 'skullfinder' + + + def _gen_filename(self, name): + if name=='outputLabelFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputLabelFile): + outputs['outputLabelFile'] = (os.getcwd() + '/' + self.inputs.outputLabelFile) + else: + outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') + + return outputs + + + + + + +class hemisplitInputSpec(CommandLineInputSpec): + inputSurfaceFile = File(mandatory=True, desc='input surface', argstr='-i %s') + inputHemisphereLabelFile = File(mandatory=True, desc='input hemisphere label volume', argstr='-l %s') + outputLeftHemisphere = File(mandatory=False, desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) + outputRightHemisphere = File(mandatory=False, desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) + pialSurfaceFile = File(desc='pial surface file -- must have same geometry as input surface', argstr='-p %s') + outputLeftPialHemisphere = File(mandatory=False, desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) + outputRightPialHemisphere = File(mandatory=False, desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) + verbosity = traits.Int(desc='verbosity (0 = silent)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + + + +class hemisplitOutputSpec(TraitedSpec): + outputLeftHemisphere = File(desc='path/name of left hemisphere') + outputRightHemisphere = File(desc='path/name of right hemisphere') + outputLeftPialHemisphere = File(desc='path/name of left pial hemisphere') + outputRightPialHemisphere = File(desc='path/name of right pial hemisphere') + + +class hemisplit(CommandLine): + input_spec = hemisplitInputSpec + output_spec = hemisplitOutputSpec + _cmd = 'hemisplit' + + + + def _gen_filename(self, name): + if name=='outputLeftHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + if name=='outputRightHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + if name=='outputLeftPialHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + if name=='outputRightPialHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputLeftHemisphere): + outputs['outputLeftHemisphere'] = (os.getcwd() + '/' + self.inputs.outputLeftHemisphere) + else: + outputs['outputLeftHemisphere'] = self._gen_filename('outputLeftHemisphere') + + if isdefined(self.inputs.outputRightHemisphere): + outputs['outputRightHemisphere'] = (os.getcwd() + '/' + self.inputs.outputRightHemisphere) + else: + outputs['outputRightHemisphere'] = self._gen_filename('outputRightHemisphere') + + + + if isdefined(self.inputs.outputLeftPialHemisphere): + outputs['outputLeftPialHemisphere'] = (os.getcwd() + '/' + self.inputs.outputLeftPialHemisphere) + if isdefined(self.inputs.outputRightPialHemisphere): + outputs['outputRightPialHemisphere'] = (os.getcwd() + '/' + self.inputs.outputRightPialHemisphere) + + return outputs + + +#removes directory of a pathway to a file, removes extension, returns file name up to first occurence of three consecutive underscore characters (if any) +#ex: /home/abc/testData___bseOutput_output_file.nii.gz --> testData +def getFileName(string): + underscoreRegex = regex.compile("[^___]+") + dotRegex = regex.compile("[^.]+") + slashRegex = regex.compile("[^/]+") + arr = underscoreRegex.findall(string) + arr2 = dotRegex.findall(arr[0]); + arr3 = slashRegex.findall(arr2[0]) + return arr3[len(arr3) - 1] From 87682ae2417614bcf87cd964ee2bba8624729a58 Mon Sep 17 00:00:00 2001 From: jason-wg Date: Thu, 24 Dec 2015 19:25:28 -0800 Subject: [PATCH 02/25] FIX proposed for S3io When I tried running this code, type(outputs[key]) was never == list or == str, so the method, self.s3tolocal, never got called. When I tried debugging, type(outputs[key]) turned out to be --- nipype/interfaces/io.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nipype/interfaces/io.py b/nipype/interfaces/io.py index ed5c0b5f9f..fad7b983d4 100644 --- a/nipype/interfaces/io.py +++ b/nipype/interfaces/io.py @@ -664,6 +664,9 @@ def _list_outputs(self): outputs[key][i] = self.s3tolocal(path, bkt) elif type(outputs[key]) == str: outputs[key] = self.s3tolocal(outputs[key], bkt) + else: + outputs[key] = self.s3tolocal(outputs[key], bkt) + return outputs From a5a750497a1745ffd71c149b9a39b2faf65c1727 Mon Sep 17 00:00:00 2001 From: jason-wg Date: Wed, 6 Jan 2016 15:04:11 -0800 Subject: [PATCH 03/25] Update brainsuite.py I updated the formatting to comply with the PEP8 style guide (The exception is that some lines run over 79 characters) As for instantiating names, the reason I approached it this way is to shorten the names of outputs that ran through multiple steps of processing using brainsuite command line tools. Is it fine to leave the instantiation of outputs how it is now? --- nipype/interfaces/brainsuite.py | 957 ++++++++++++++++++++------------ 1 file changed, 613 insertions(+), 344 deletions(-) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index 01eb3f39ff..99a6405909 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -13,36 +13,46 @@ class bseInputSpec(CommandLineInputSpec): - inputMRIFile = File(exists=True, mandatory=True, argstr='-i %s', desc='input MRI volume', position=0) - - outputMRIVolume = File(mandatory=False, desc='output brain-masked MRI volume. If unspecified, output file name will be auto generated.', argstr='-o %s', position=1, hash_files=False, genfile=True) - - diffusionConstant = traits.Float(25, usedefault=True, desc='diffusion constant [default if unspecified: 25]' , argstr='-d %f') - - diffusionIterations = traits.Int(3, usedefault=True, desc='diffusion iterations [default if unspecified: 3]', argstr='-n %d') - - edgeDetectionConstant = traits.Float(0.64, usedefault=True, desc='edge detection constant [default if unspecified: 0.64]', argstr='-s %f') - - radius = traits.Float(1, usedefault=True, desc='radius of erosion/dilation filter [default if unspecified: 1]', argstr='-r %f') - - dilateFinalMask = traits.Bool(True, usedefault=True, desc='dilate final mask [default if unspecified: True]', argstr='-p') - - trim = traits.Bool(True, usedefault=True, desc='trim brainstem [default if unspecified: True]', argstr='--trim') - - outputMaskFile = File(mandatory=False, desc='save smooth brain mask' , argstr='--mask %s', hash_files=False) - - outputDiffusionFilter = File(desc='diffusion filter output', argstr='--adf %s', hash_files=False) - - outputEdgeMap = File(desc='edge map output', argstr='--edge %s', hash_files=False) - - outputDetailedBrainMask = File(desc='save detailed brain mask', argstr='--hires %s', hash_files=False) - - outputCortexFile = File(desc='cortex file', argstr='--cortex %s', hash_files=False) - - verbosityLevel = traits.Float(1, usedefault=True, desc=' verbosity level (0=silent) [default if unspecified: 1]', argstr='-v %f') - - noRotate = traits.Bool(True, usedefault=True, desc='retain original orientation (default behavior will auto-rotate input NII files to LPI orientation) [default if unspecified: True]', argstr='--norotate') - + inputMRIFile = File(exists=True, mandatory=True, argstr='-i %s', + desc='input MRI volume', position=0) + outputMRIVolume = File(mandatory=False, + desc='output brain-masked MRI volume. If' + 'unspecified, output file name will be auto' + 'generated.', + argstr='-o %s', position=1, hash_files=False, + genfile=True) + diffusionConstant = traits.Float(25, usedefault=True, + desc='diffusion constant', argstr='-d %f') + diffusionIterations = traits.Int(3, usedefault=True, + desc='diffusion iterations', + argstr='-n %d') + edgeDetectionConstant = traits.Float(0.64, usedefault=True, + desc='edge detection constant', + argstr='-s %f') + radius = traits.Float(1, usedefault=True, + desc='radius of erosion/dilation filter', + argstr='-r %f') + dilateFinalMask = traits.Bool(True, usedefault=True, + desc='dilate final mask', argstr='-p') + trim = traits.Bool(True, usedefault=True, desc='trim brainstem', + argstr='--trim') + outputMaskFile = File(mandatory=False, desc='save smooth brain mask', + argstr='--mask %s', hash_files=False) + outputDiffusionFilter = File(desc='diffusion filter output', + argstr='--adf %s', hash_files=False) + outputEdgeMap = File(desc='edge map output', argstr='--edge %s', + hash_files=False) + outputDetailedBrainMask = File(desc='save detailed brain mask', + argstr='--hires %s', hash_files=False) + outputCortexFile = File(desc='cortex file', argstr='--cortex %s', + hash_files=False) + verbosityLevel = traits.Float(1, usedefault=True, + desc=' verbosity level (0=silent)', + argstr='-v %f') + noRotate = traits.Bool(True, usedefault=True, + desc='retain original orientation' + '(default behavior will auto-rotate input NII files' + 'to LPI orientation)', argstr='--norotate') timer = traits.Bool(desc='show timing', argstr='--timer') @@ -53,7 +63,7 @@ class bseOutputSpec(TraitedSpec): outputEdgeMap = File(desc='path/name of edge map output') outputDetailedBrainMask = File(desc='path/name of detailed brain mask') outputCortexFile = File(desc='path/name of cortex file') - + class bse(CommandLine): input_spec = bseInputSpec @@ -61,84 +71,111 @@ class bse(CommandLine): _cmd = 'bse' def _list_outputs(self): - + outputs = self.output_spec().get() if isdefined(self.inputs.outputMRIVolume): - outputs['outputMRIVolume'] = (os.getcwd() + '/' + self.inputs.outputMRIVolume) + outputs['outputMRIVolume'] = (os.getcwd() + '/' + + self.inputs.outputMRIVolume) else: outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') - - + if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + outputs['outputMaskFile'] = (os.getcwd() + '/' + + self.inputs.outputMaskFile) if isdefined(self.inputs.outputDiffusionFilter): - outputs['outputDiffusionFilter'] = (os.getcwd() + '/' + self.inputs.outputDiffusionFilter) + outputs['outputDiffusionFilter'] = (os.getcwd() + '/' + + self.inputs.outputDiffusionFilter) if isdefined(self.inputs.outputEdgeMap): - outputs['outputEdgeMap'] = (os.getcwd() + '/' + self.inputs.outputEdgeMap) + outputs['outputEdgeMap'] = (os.getcwd() + '/' + + self.inputs.outputEdgeMap) if isdefined(self.inputs.outputDetailedBrainMask): - outputs['outputDetailedBrainMask'] = (os.getcwd() + '/' + self.inputs.outputDetailedBrainMask) + outputs['outputDetailedBrainMask'] = (os.getcwd() + '/' + + self.inputs.outputDetailedBrainMask) if isdefined(self.inputs.outputCortexFile): - outputs['outputCortexFile'] = (os.getcwd() + '/' + self.inputs.outputCortexFile) - + outputs['outputCortexFile'] = (os.getcwd() + '/' + + self.inputs.outputCortexFile) + return outputs - + def _gen_filename(self, name): - if name=='outputMRIVolume': + if name == 'outputMRIVolume': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - - - + return ''.join((os.getcwd(), '/', + getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) class bfcInputSpec(CommandLineInputSpec): - inputMRIFile = File(exists = True, mandatory=True, desc='input skull-stripped MRI volume', argstr='-i %s', position=0) - - outputMRIVolume = File(mandatory=False, desc='output bias-corrected MRI volume. If unspecified, output file name will be auto generated.', argstr='-o %s', position=1, hash_files=False, genfile=True) - + inputMRIFile = File(exists=True, mandatory=True, + desc='input skull-stripped MRI volume', + argstr='-i %s', position=0) + outputMRIVolume = File(mandatory=False, + desc='output bias-corrected MRI volume.' + 'If unspecified, output file name' + 'will be auto generated.', argstr='-o %s', + position=1, hash_files=False, genfile=True) outputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) - - outputBiasField = File(desc='save bias field estimate', argstr='--bias %s', hash_files=False) - - outputMaskedBiasField = File(desc='save bias field estimate (masked)', argstr='--maskedbias %s', hash_files=False) - - histogramRadius = traits.Int(desc='histogram radius (voxels)', argstr='-r %d') - - biasEstimateSpacing = traits.Int(desc='bias sample spacing (voxels)', argstr='-s %d') - - controlPointSpacing = traits.Int(desc='control point spacing (voxels)', argstr='-c %d') - - splineLambda = traits.Float(desc='spline stiffness weighting parameter', argstr='-w %f') - - histogramType = traits.Enum('ellipse', 'block', desc="Options for type of histogram\nellipse: use ellipsoid for ROI histogram\nblock:use block for ROI histogram", argstr='%s') - - iterativeMode = traits.Bool(desc='iterative mode (overrides -r, -s, -c, -w settings)', argstr='--iterate') - - correctionScheduleFile = File(desc='list of parameters ', argstr='--schedule %s') - - biasFieldEstimatesOutputPrefix = traits.Str(desc='save iterative bias field estimates as .n.field.nii.gz', argstr='--biasprefix %s') - - correctedImagesOutputPrefix = traits.Str(desc='save iterative corrected images as .n.bfc.nii.gz', argstr='--prefix %s') - - correctWholeVolume = traits.Bool(desc='apply correction field to entire volume', argstr='--extrapolate') - - minBias = traits.Float(0.5, usedefault=True, desc='minimum allowed bias value [default if unspecified: 0.5]', argstr='-L %f') - - maxBias = traits.Float(1.5, usedefault=True, desc='maximum allowed bias value [default if unspecified: 1.5]', argstr='-U %f') - - biasRange = traits.Enum("low", "medium", "high", desc="Preset options for bias_model\nlow: small bias model [0.95,1.05]\nmedium: medium bias model [0.90,1.10]\nhigh: high bias model [0.80,1.20]", argstr='%s') - intermediate_file_type = traits.Enum("analyze", "nifti", "gzippedAnalyze", "gzippedNifti", desc="Options for the format in which intermediate files are generated", argstr='%s') - - convergenceThreshold = traits.Float(desc='convergence threshold', argstr='--eps %f') - - biasEstimateConvergenceThreshold = traits.Float(desc='bias estimate convergence threshold (values > 0.1 disable)', argstr='--beps %f') - - verbosityLevel = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') - + outputBiasField = File(desc='save bias field estimate', + argstr='--bias %s', hash_files=False) + outputMaskedBiasField = File(desc='save bias field estimate (masked)', + argstr='--maskedbias %s', hash_files=False) + histogramRadius = traits.Int(desc='histogram radius (voxels)', + argstr='-r %d') + biasEstimateSpacing = traits.Int(desc='bias sample spacing (voxels)', + argstr='-s %d') + controlPointSpacing = traits.Int(desc='control point spacing (voxels)', + argstr='-c %d') + splineLambda = traits.Float(desc='spline stiffness weighting parameter', + argstr='-w %f') + histogramType = traits.Enum('ellipse', 'block', + desc='Options for type of histogram\nellipse:' + 'use ellipsoid for ROI histogram\nblock' + ':use block for ROI histogram', + argstr='%s') + iterativeMode = traits.Bool(desc='iterative mode (overrides -r, -s, -c,' + '-w settings)', + argstr='--iterate') + correctionScheduleFile = File(desc='list of parameters ', + argstr='--schedule %s') + biasFieldEstimatesOutputPrefix = traits.Str(desc='save iterative bias' + 'field estimates as' + '.n.field.nii.gz', + argstr='--biasprefix %s') + correctedImagesOutputPrefix = traits.Str(desc='save iterative corrected' + 'images as' + '.n.bfc.nii.gz', + argstr='--prefix %s') + correctWholeVolume = traits.Bool(desc='apply correction field to entire' + 'volume', argstr='--extrapolate') + minBias = traits.Float(0.5, usedefault=True, desc='minimum allowed bias' + 'value', + argstr='-L %f') + maxBias = traits.Float(1.5, usedefault=True, desc='maximum allowed bias' '' + 'value', + argstr='-U %f') + biasRange = traits.Enum("low", "medium", "high", + desc='Preset options for bias_model\n' + 'low: small bias model [0.95,1.05]\n' + 'medium: medium bias model [0.90,1.10]\n' + 'high: high bias model [0.80,1.20]', + argstr='%s') + intermediate_file_type = traits.Enum("analyze", "nifti", + "gzippedAnalyze", "gzippedNifti", + desc='Options for the format in' + 'which intermediate files are' "" + 'generated', + argstr='%s') + convergenceThreshold = traits.Float(desc='convergence threshold', + argstr='--eps %f') + biasEstimateConvergenceThreshold = traits.Float( + desc='bias estimate convergence threshold (values > 0.1 disable)', + argstr='--beps %f') + verbosityLevel = traits.Int( + desc='verbosity level (0=silent)', + argstr='-v %d') timer = traits.Bool(desc='display timing information', argstr='--timer') - - + class bfcOutputSpec(TraitedSpec): outputMRIVolume = File(desc='path/name of output file') outputMaskFile = File(desc='path/name of mask output file') @@ -146,121 +183,169 @@ class bfcOutputSpec(TraitedSpec): outputMaskedBiasField = File(desc='path/name of masked bias field output') correctionScheduleFile = File(desc='path/name of schedule file') + class bfc(CommandLine): input_spec = bfcInputSpec output_spec = bfcOutputSpec _cmd = 'bfc' - + def _gen_filename(self, name): - if name=='outputMRIVolume': + if name == 'outputMRIVolume': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) def _format_arg(self, name, spec, value): if name == 'histogramType': - return spec.argstr%{"ellipse":"--ellipse" , "block":"--block"}[value] + return spec.argstr % { + "ellipse": "--ellipse", "block": "--block"}[value] if name == 'biasRange': - return spec.argstr%{"low":"--low" , "medium":"--medium", "high":"--high"}[value] + return spec.argstr % {"low": "--low", + "medium": "--medium", "high": "--high"}[value] if name == 'intermediate_file_type': - return spec.argstr%{"analyze":"--analyze" , "nifti":"--nifti", "gzippedAnalyze":"--analyzegz", "gzippedNifti":"--niftigz"}[value] + return spec.argstr % {"analyze": "--analyze", "nifti": "--nifti", + "gzippedAnalyze": "--analyzegz", "gzippedNifti": "--niftigz"}[value] return super(bfc, self)._format_arg(name, spec, value) - - def _list_outputs(self): outputs = self.output_spec().get() - + if isdefined(self.inputs.outputMRIVolume): - outputs['outputMRIVolume'] = (os.getcwd() + '/' + self.inputs.outputMRIVolume) + outputs['outputMRIVolume'] = ( + os.getcwd() + '/' + self.inputs.outputMRIVolume) else: outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + outputs['outputMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputMaskFile) if isdefined(self.inputs.outputBiasField): - outputs['outputBiasField'] = (os.getcwd() + '/' + self.inputs.outputBiasField) + outputs['outputBiasField'] = ( + os.getcwd() + '/' + self.inputs.outputBiasField) if isdefined(self.inputs.outputMaskedBiasField): - outputs['outputMaskedBiasField'] = (os.getcwd() + '/' + self.inputs.outputMaskedBiasField) + outputs['outputMaskedBiasField'] = ( + os.getcwd() + '/' + self.inputs.outputMaskedBiasField) if isdefined(self.inputs.correctionScheduleFile): - outputs['correctionScheduleFile'] = (os.getcwd() + '/' + self.inputs.correctionScheduleFile) - - return outputs - - - - + outputs['correctionScheduleFile'] = ( + os.getcwd() + '/' + self.inputs.correctionScheduleFile) + return outputs class pvcInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') inputMaskFile = File(desc='brain mask file', argstr='-m %s') - outputLabelFile = File(mandatory=False, desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - outputTissueFractionFile = File(mandatory=False, desc='output tissue fraction file', argstr='-f %s', genfile=True) + outputLabelFile = File( + mandatory=False, + desc='output label file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + outputTissueFractionFile = File( + mandatory=False, + desc='output tissue fraction file', + argstr='-f %s', + genfile=True) spatialPrior = traits.Float(desc='spatial prior strength', argstr='-l %f') verbosity = traits.Int(desc='verbosity level (0 = silent)', argstr='-v %d') - threeClassFlag = traits.Bool(desc='use a three-class (CSF=0,GM=1,WM=2) labeling', argstr='-3') + threeClassFlag = traits.Bool( + desc='use a three-class (CSF=0,GM=1,WM=2) labeling', + argstr='-3') timer = traits.Bool(desc='time processing', argstr='--timer') + class pvcOutputSpec(TraitedSpec): outputLabelFile = File(desc='path/name of label file') outputTissueFractionFile = File(desc='path/name of tissue fraction file') + class pvc(CommandLine): input_spec = pvcInputSpec output_spec = pvcOutputSpec _cmd = 'pvc' - def _gen_filename(self, name): - if name=='outputLabelFile': + if name == 'outputLabelFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', self._cmd, 'Output_', name, myExtension)) - if name=='outputTissueFractionFile': + return ''.join((os.getcwd(), '/', self._cmd, + 'Output_', name, myExtension)) + if name == 'outputTissueFractionFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputLabelFile): - outputs['outputLabelFile'] = (os.getcwd() + '/' + self.inputs.outputLabelFile) + outputs['outputLabelFile'] = ( + os.getcwd() + '/' + self.inputs.outputLabelFile) else: outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') if isdefined(self.inputs.outputTissueFractionFile): - outputs['outputTissueFractionFile'] = (os.getcwd() + '/' + self.inputs.outputTissueFractionFile) + outputs['outputTissueFractionFile'] = ( + os.getcwd() + '/' + self.inputs.outputTissueFractionFile) else: - outputs['outputTissueFractionFile'] = self._gen_filename('outputTissueFractionFile') + outputs['outputTissueFractionFile'] = self._gen_filename( + 'outputTissueFractionFile') return outputs - - - - class cerebroInputSpec(CommandLineInputSpec): - inputMRIFile = File(mandatory=True, desc='input 3D MRI volume', argstr='-i %s') - inputAtlasMRIFile = File(mandatory=True, desc='atlas MRI volume', argstr='--atlas %s') - inputAtlasLabelFile = File(mandatory=True, desc='atlas labeling', argstr='--atlaslabels %s') + inputMRIFile = File( + mandatory=True, + desc='input 3D MRI volume', + argstr='-i %s') + inputAtlasMRIFile = File( + mandatory=True, + desc='atlas MRI volume', + argstr='--atlas %s') + inputAtlasLabelFile = File( + mandatory=True, + desc='atlas labeling', + argstr='--atlaslabels %s') inputBrainMaskFile = File(desc='brain mask file', argstr='-m %s') - outputCerebrumMaskFile = File(mandatory=False, desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - outputLabelMaskFile = File(mandatory=False, desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', argstr='-l %s', genfile=True) - costFunction = traits.Int(2, usedefault=True, desc='0,1,2 [default if unspecified: 2]', argstr='-c %d') - useCentroids = traits.Bool(desc='use centroids of data to initialize position', argstr='--centroids') - outputAffineTransformFile = File(desc='save affine transform to file.', argstr='--air %s') - outputWarpTransformFile = File(desc='save warp transform to file.', argstr='--warp %s') + outputCerebrumMaskFile = File( + mandatory=False, + desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + outputLabelMaskFile = File( + mandatory=False, + desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', + argstr='-l %s', + genfile=True) + costFunction = traits.Int(2, usedefault=True, desc='0,1,2', argstr='-c %d') + useCentroids = traits.Bool( + desc='use centroids of data to initialize position', + argstr='--centroids') + outputAffineTransformFile = File( + desc='save affine transform to file.', + argstr='--air %s') + outputWarpTransformFile = File( + desc='save warp transform to file.', + argstr='--warp %s') verbosity = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') - linearConvergence = traits.Float(desc='linear convergence', argstr='--linconv %f') - warpLabel = traits.Int(desc='warp order (2,3,4,5,6,7,8)', argstr='--warplevel %d') - warpConvergence = traits.Float(desc='warp convergence', argstr='--warpconv %f') - keepTempFiles = traits.Bool(desc="don't remove temporary files", argstr='--keep') - tempDirectory = traits.Str(desc='specify directory to use for temporary files', argstr='--tempdir %s') - tempDirectoryBase = traits.Str(desc='create a temporary directory within this directory', argstr='--tempdirbase %s') + linearConvergence = traits.Float( + desc='linear convergence', + argstr='--linconv %f') + warpLabel = traits.Int( + desc='warp order (2,3,4,5,6,7,8)', + argstr='--warplevel %d') + warpConvergence = traits.Float( + desc='warp convergence', + argstr='--warpconv %f') + keepTempFiles = traits.Bool( + desc="don't remove temporary files", + argstr='--keep') + tempDirectory = traits.Str( + desc='specify directory to use for temporary files', + argstr='--tempdir %s') + tempDirectoryBase = traits.Str( + desc='create a temporary directory within this directory', + argstr='--tempdirbase %s') class cerebroOutputSpec(TraitedSpec): @@ -276,51 +361,77 @@ class cerebro(CommandLine): _cmd = 'cerebro' def _gen_filename(self, name): - if name=='outputCerebrumMaskFile': + if name == 'outputCerebrumMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - if name=='outputLabelMaskFile': - myExtension= '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputLabelMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) + def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputCerebrumMaskFile): - outputs['outputCerebrumMaskFile'] = (os.getcwd() + '/' + self.inputs.outputCerebrumMaskFile) + outputs['outputCerebrumMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputCerebrumMaskFile) else: - outputs['outputCerebrumMaskFile'] = self._gen_filename('outputCerebrumMaskFile') - + outputs['outputCerebrumMaskFile'] = self._gen_filename( + 'outputCerebrumMaskFile') if isdefined(self.inputs.outputLabelMaskFile): - outputs['outputLabelMaskFile'] = (os.getcwd() + '/' + self.inputs.outputLabelMaskFile) + outputs['outputLabelMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputLabelMaskFile) else: - outputs['outputLabelMaskFile'] = self._gen_filename('outputLabelMaskFile') - + outputs['outputLabelMaskFile'] = self._gen_filename( + 'outputLabelMaskFile') if isdefined(self.inputs.outputAffineTransformFile): - outputs['outputAffineTransformFile'] = (os.getcwd() + '/' + self.inputs.outputAffineTransformFile) + outputs['outputAffineTransformFile'] = ( + os.getcwd() + '/' + self.inputs.outputAffineTransformFile) if isdefined(self.inputs.outputWarpTransformFile): - outputs['outputWarpTransformFile'] = (os.getcwd() + '/' + self.inputs.outputWarpTransformFile) + outputs['outputWarpTransformFile'] = ( + os.getcwd() + '/' + self.inputs.outputWarpTransformFile) return outputs - - - - class cortexInputSpec(CommandLineInputSpec): - inputHemisphereLabelFile = File(mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') - outputCerebrumMask = File(mandatory=False, desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - inputTissueFractionFile = File(mandatory=True, desc='tissue fraction file (32-bit float)', argstr='-f %s') - tissueFractionThreshold = traits.Float(50.0, usedefault=True, desc='tissue fraction threshold (percentage) [default if unspecified: 50]', argstr='-p %f') - computeWGBoundary = traits.Bool(True, usedefault=True, desc='compute WM/GM boundary [default if unspecified: True]', argstr='-w') - computeGCBoundary = traits.Bool(desc='compute GM/CSF boundary', argstr='-g') - includeAllSubcorticalAreas = traits.Bool(True, usedefault=True, esc='include all subcortical areas in WM mask [default if unspecified: True]', argstr='-a') + inputHemisphereLabelFile = File( + mandatory=True, + desc='hemisphere / lobe label volume', + argstr='-h %s') + outputCerebrumMask = File( + mandatory=False, + desc='output structure mask. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + inputTissueFractionFile = File( + mandatory=True, + desc='tissue fraction file (32-bit float)', + argstr='-f %s') + tissueFractionThreshold = traits.Float( + 50.0, + usedefault=True, + desc='tissue fraction threshold (percentage)', + argstr='-p %f') + computeWGBoundary = traits.Bool( + True, + usedefault=True, + desc='compute WM/GM boundary', + argstr='-w') + computeGCBoundary = traits.Bool( + desc='compute GM/CSF boundary', argstr='-g') + includeAllSubcorticalAreas = traits.Bool( + True, + usedefault=True, + esc='include all subcortical areas in WM mask', + argstr='-a') verbosity = traits.Int(desc='verbosity level', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') + class cortexOutputSpec(TraitedSpec): outputCerebrumMask = File(desc='path/name of cerebrum mask') @@ -331,38 +442,49 @@ class cortex(CommandLine): _cmd = 'cortex' def _gen_filename(self, name): - if name=='outputCerebrumMask': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), "___", self._cmd, 'Output_', name, myExtension)) - + if name == 'outputCerebrumMask': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputCerebrumMask): - outputs['outputCerebrumMask'] = (os.getcwd() + '/' + self.inputs.outputCerebrumMask) + outputs['outputCerebrumMask'] = ( + os.getcwd() + '/' + self.inputs.outputCerebrumMask) else: - outputs['outputCerebrumMask'] = self._gen_filename('outputCerebrumMask') - - + outputs['outputCerebrumMask'] = self._gen_filename( + 'outputCerebrumMask') return outputs - - - - - class scrubmaskInputSpec(CommandLineInputSpec): - inputMaskFile = File(mandatory=True, desc='input structure mask file', argstr='-i %s') - outputMaskFile = File(mandatory=False, desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - backgroundFillThreshold = traits.Int(2, usedefault=True, desc='background fill threshold [default if unspecified: 2]', argstr='-b %d') - foregroundTrimThreshold = traits.Int(0, usedefault=True, desc='foreground trim threshold [default if unspecified: 0]', argstr='-f %d') + inputMaskFile = File( + mandatory=True, + desc='input structure mask file', + argstr='-i %s') + outputMaskFile = File( + mandatory=False, + desc='output structure mask file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + backgroundFillThreshold = traits.Int( + 2, + usedefault=True, + desc='background fill threshold', + argstr='-b %d') + foregroundTrimThreshold = traits.Int( + 0, + usedefault=True, + desc='foreground trim threshold', + argstr='-f %d') numberIterations = traits.Int(desc='number of iterations', argstr='-n %d') verbosity = traits.Int(desc='verbosity (0=silent)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') + class scrubmaskOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') @@ -372,38 +494,51 @@ class scrubmask(CommandLine): output_spec = scrubmaskOutputSpec _cmd = 'scrubmask' - def _gen_filename(self, name): - if name=='outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) - + if name == 'outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + outputs['outputMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputMaskFile) else: outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') return outputs - - - - - class tcaInputSpec(CommandLineInputSpec): - inputMaskFile = File(mandatory=True, desc='input mask volume', argstr='-i %s') - outputMaskFile = File(mandatory=False, desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - minCorrectionSize = traits.Int(2500, usedefault=True, desc='maximum correction size [default if unspecified: 2500]', argstr='-m %d') - maxCorrectionSize = traits.Int(desc='minimum correction size', argstr='-n %d') - foregroundDelta = traits.Int(20, usedefault=True, desc='foreground delta [default if unspecified: 20]', argstr='--delta %d') + inputMaskFile = File( + mandatory=True, + desc='input mask volume', + argstr='-i %s') + outputMaskFile = File( + mandatory=False, + desc='output mask volume. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + minCorrectionSize = traits.Int( + 2500, + usedefault=True, + desc='maximum correction size', + argstr='-m %d') + maxCorrectionSize = traits.Int( + desc='minimum correction size', + argstr='-n %d') + foregroundDelta = traits.Int( + 20, + usedefault=True, + desc='foreground delta', + argstr='--delta %d') verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') + class tcaOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') @@ -413,38 +548,39 @@ class tca(CommandLine): output_spec = tcaOutputSpec _cmd = 'tca' - - def _gen_filename(self, name): - if name=='outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) - - + if name == 'outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + outputs['outputMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputMaskFile) else: outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') return outputs - - - - class dewispInputSpec(CommandLineInputSpec): inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') - outputMaskFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + outputMaskFile = File( + mandatory=False, + desc='output file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') sizeThreshold = traits.Int(desc='size threshold', argstr='-t %d') - maximumIterations = traits.Int(desc='maximum number of iterations', argstr='-n %d') + maximumIterations = traits.Int( + desc='maximum number of iterations', + argstr='-n %d') timer = traits.Bool(desc='time processing', argstr='--timer') + class dewispOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') @@ -454,51 +590,91 @@ class dewisp(CommandLine): output_spec = dewispOutputSpec _cmd = 'dewisp' - def _gen_filename(self, name): - if name=='outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) - + if name == 'outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + outputs['outputMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputMaskFile) else: outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') return outputs - - - - - - - class dfsInputSpec(CommandLineInputSpec): - inputVolumeFile = File(mandatory=True, desc='input 3D volume', argstr='-i %s') - outputSurfaceFile = File(mandatory=False, desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - inputShadingVolume = File(desc='shade surface model with data from image volume', argstr='-c %s') - smoothingIterations = traits.Int(10, usedefault=True, desc='number of smoothing iterations [default if unspecified: 10]', argstr='-n %d') - smoothingConstant = traits.Float(0.5, usedefault=True, desc='smoothing constant [default if unspecified: 0.5]', argstr='-a %f') - curvatureWeighting = traits.Float(5.0, usedefault=True, desc='curvature weighting [default if unspecified: 5.0]', argstr='-w %f') + inputVolumeFile = File( + mandatory=True, + desc='input 3D volume', + argstr='-i %s') + outputSurfaceFile = File( + mandatory=False, + desc='output surface mesh file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + inputShadingVolume = File( + desc='shade surface model with data from image volume', + argstr='-c %s') + smoothingIterations = traits.Int( + 10, + usedefault=True, + desc='number of smoothing iterations', + argstr='-n %d') + smoothingConstant = traits.Float( + 0.5, + usedefault=True, + desc='smoothing constant', + argstr='-a %f') + curvatureWeighting = traits.Float( + 5.0, + usedefault=True, + desc='curvature weighting', + argstr='-w %f') scalingPercentile = traits.Float(desc='scaling percentile', argstr='-f %f') - nonZeroTessellation = traits.Bool(desc='tessellate non-zero voxels', argstr='-nz', xor=('nonZeroTessellation', 'specialTessellation')) - tessellationThreshold = traits.Float(desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%f') - specialTessellation = traits.Enum('greater_than', 'less_than', 'equal_to', desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%s', xor=('nonZeroTessellation', 'specialTessellation'), requires=['tessellationThreshold'], position=-1) - zeroPadFlag = traits.Bool(desc='zero-pad volume (avoids clipping at edges)', argstr='-z') - noNormalsFlag = traits.Bool(desc='do not compute vertex normals', argstr='--nonormals') - postSmoothFlag = traits.Bool(desc='smooth vertices after coloring', argstr='--postsmooth') + nonZeroTessellation = traits.Bool( + desc='tessellate non-zero voxels', + argstr='-nz', + xor=( + 'nonZeroTessellation', + 'specialTessellation')) + tessellationThreshold = traits.Float( + desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', + argstr='%f') + specialTessellation = traits.Enum( + 'greater_than', + 'less_than', + 'equal_to', + desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', + argstr='%s', + xor=( + 'nonZeroTessellation', + 'specialTessellation'), + requires=['tessellationThreshold'], + position=- + 1) + zeroPadFlag = traits.Bool( + desc='zero-pad volume (avoids clipping at edges)', + argstr='-z') + noNormalsFlag = traits.Bool( + desc='do not compute vertex normals', + argstr='--nonormals') + postSmoothFlag = traits.Bool( + desc='smooth vertices after coloring', + argstr='--postsmooth') verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') + class dfsOutputSpec(TraitedSpec): outputSurfaceFile = File(desc='path/name of surface file') + class dfs(CommandLine): input_spec = dfsInputSpec output_spec = dfsOutputSpec @@ -506,51 +682,100 @@ class dfs(CommandLine): def _format_arg(self, name, spec, value): if name == 'tessellationThreshold': - return '' #blank argstr + return '' # blank argstr if name == 'specialTessellation': threshold = self.inputs.tessellationThreshold - return spec.argstr%{"greater_than":''.join(("-gt %f" % threshold)), "less_than":''.join(("-lt %f" % threshold)) , "equal_to":''.join(("-eq %f" % threshold))}[value] + return spec.argstr % {"greater_than": ''.join(("-gt %f" % threshold)), "less_than": ''.join( + ("-lt %f" % threshold)), "equal_to": ''.join(("-eq %f" % threshold))}[value] return super(dfs, self)._format_arg(name, spec, value) - def _gen_filename(self, name): - if name=='outputSurfaceFile': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputSurfaceFile': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), + "___", self._cmd, 'Output_', name, myExtension)) - def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputSurfaceFile): - outputs['outputSurfaceFile'] = (os.getcwd() + '/' + self.inputs.outputSurfaceFile) + outputs['outputSurfaceFile'] = ( + os.getcwd() + '/' + self.inputs.outputSurfaceFile) else: - outputs['outputSurfaceFile'] = self._gen_filename('outputSurfaceFile') + outputs['outputSurfaceFile'] = self._gen_filename( + 'outputSurfaceFile') return outputs - - class pialmeshInputSpec(CommandLineInputSpec): inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') - outputSurfaceFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + outputSurfaceFile = File( + mandatory=False, + desc='output file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') - inputTissueFractionFile = File(mandatory=True, desc='floating point (32) tissue fraction image', argstr='-f %s') - numIterations = traits.Int(100, usedefault=True, desc='number of iterations [default if unspecified: 100]', argstr='-n %d') - searchRadius = traits.Float(1, usedefault=True, desc='search radius [default if unspecified: 1]', argstr='-r %f') - stepSize = traits.Float(0.4, usedefault=True, desc='step size [default if unspecified: 0.4]', argstr='-s %f') - inputMaskFile = File(mandatory=True, desc='restrict growth to mask file region', argstr='-m %s') - maxThickness = traits.Float(20, usedefault=True, desc='maximum allowed tissue thickness [default if unspecified: 20]', argstr='--max %f') - tissueThreshold = traits.Float(1.05, usedefault=True, desc='tissue threshold [default if unspecified: 1.05]', argstr='-t %f') -# output interval is not an output -- it specifies how frequently the output surfaces are generated - outputInterval = traits.Int(10, usedefault=True, desc='output interval [default if unspecified: 10]', argstr='--interval %d') - exportPrefix = traits.Str(desc='prefix for exporting surfaces if interval is set', argstr='--prefix %s') - laplacianSmoothing = traits.Float(0.025, usedefault=True, desc='apply Laplacian smoothing [default if unspecified: 0.025]', argstr='--smooth %f') + inputTissueFractionFile = File( + mandatory=True, + desc='floating point (32) tissue fraction image', + argstr='-f %s') + numIterations = traits.Int( + 100, + usedefault=True, + desc='number of iterations', + argstr='-n %d') + searchRadius = traits.Float( + 1, + usedefault=True, + desc='search radius', + argstr='-r %f') + stepSize = traits.Float( + 0.4, + usedefault=True, + desc='step size', + argstr='-s %f') + inputMaskFile = File( + mandatory=True, + desc='restrict growth to mask file region', + argstr='-m %s') + maxThickness = traits.Float( + 20, + usedefault=True, + desc='maximum allowed tissue thickness', + argstr='--max %f') + tissueThreshold = traits.Float( + 1.05, + usedefault=True, + desc='tissue threshold', + argstr='-t %f') +# output interval is not an output -- it specifies how frequently the +# output surfaces are generated + outputInterval = traits.Int( + 10, + usedefault=True, + desc='output interval', + argstr='--interval %d') + exportPrefix = traits.Str( + desc='prefix for exporting surfaces if interval is set', + argstr='--prefix %s') + laplacianSmoothing = traits.Float( + 0.025, + usedefault=True, + desc='apply Laplacian smoothing', + argstr='--smooth %f') timer = traits.Bool(desc='show timing', argstr='--timer') - recomputNormals = traits.Bool(desc='recompute normals at each iteration', argstr='--norm') - normalSmoother = traits.Float(0.2, usedefault=True, desc='strength of normal smoother. [default if unspecified: 0.2]', argstr='--nc %f') - tangentSmoother = traits.Float(desc='strength of tangential smoother.', argstr='--tc %f') + recomputNormals = traits.Bool( + desc='recompute normals at each iteration', + argstr='--norm') + normalSmoother = traits.Float( + 0.2, + usedefault=True, + desc='strength of normal smoother.', + argstr='--nc %f') + tangentSmoother = traits.Float( + desc='strength of tangential smoother.', + argstr='--tc %f') class pialmeshOutputSpec(TraitedSpec): @@ -562,45 +787,65 @@ class pialmesh(CommandLine): output_spec = pialmeshOutputSpec _cmd = 'pialmesh' - def _gen_filename(self, name): - if name=='outputSurfaceFile': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - - + if name == 'outputSurfaceFile': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputSurfaceFile): - outputs['outputSurfaceFile'] = (os.getcwd() + '/' + self.inputs.outputSurfaceFile) + outputs['outputSurfaceFile'] = ( + os.getcwd() + '/' + self.inputs.outputSurfaceFile) else: - outputs['outputSurfaceFile'] = self._gen_filename('outputSurfaceFile') + outputs['outputSurfaceFile'] = self._gen_filename( + 'outputSurfaceFile') return outputs - - - - - - class skullfinderInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='input file', argstr='-i %s') - inputMaskFile = File(mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') - outputLabelFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + inputMaskFile = File( + mandatory=True, + desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', + argstr='-m %s') + outputLabelFile = File( + mandatory=False, + desc='output file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') - lowerThreshold = traits.Int(desc='Lower threshold for segmentation', argstr='-l %d') - upperThreshold = traits.Int(desc='Upper threshold for segmentation', argstr='-u %d') - surfaceFilePrefix = traits.Str(desc='if specified, generate surface files for brain, skull, and scalp', argstr='-s %s') - bgLabelValue = traits.Int(desc='background label value (0-255)', argstr='--bglabel %d') - scalpLabelValue = traits.Int(desc='scalp label value (0-255)', argstr='--scalplabel %d') - skullLabelValue = traits.Int(desc='skull label value (0-255)', argstr='--skulllabel %d') - spaceLabelValue = traits.Int(desc='space label value (0-255)', argstr='--spacelabel %d') - brainLabelValue = traits.Int(desc='brain label value (0-255)', argstr='--brainlabel %d') - performFinalOpening = traits.Bool(desc='perform a final opening operation on the scalp mask', argstr='--finalOpening') + lowerThreshold = traits.Int( + desc='Lower threshold for segmentation', + argstr='-l %d') + upperThreshold = traits.Int( + desc='Upper threshold for segmentation', + argstr='-u %d') + surfaceFilePrefix = traits.Str( + desc='if specified, generate surface files for brain, skull, and scalp', + argstr='-s %s') + bgLabelValue = traits.Int( + desc='background label value (0-255)', + argstr='--bglabel %d') + scalpLabelValue = traits.Int( + desc='scalp label value (0-255)', + argstr='--scalplabel %d') + skullLabelValue = traits.Int( + desc='skull label value (0-255)', + argstr='--skulllabel %d') + spaceLabelValue = traits.Int( + desc='space label value (0-255)', + argstr='--spacelabel %d') + brainLabelValue = traits.Int( + desc='brain label value (0-255)', + argstr='--brainlabel %d') + performFinalOpening = traits.Bool( + desc='perform a final opening operation on the scalp mask', + argstr='--finalOpening') + class skullfinderOutputSpec(TraitedSpec): outputLabelFile = File(desc='path/name of label file') @@ -611,42 +856,60 @@ class skullfinder(CommandLine): output_spec = skullfinderOutputSpec _cmd = 'skullfinder' - def _gen_filename(self, name): - if name=='outputLabelFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - - + if name == 'outputLabelFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): - outputs = self.output_spec().get() - if isdefined(self.inputs.outputLabelFile): - outputs['outputLabelFile'] = (os.getcwd() + '/' + self.inputs.outputLabelFile) - else: - outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') - - return outputs - - - + outputs = self.output_spec().get() + if isdefined(self.inputs.outputLabelFile): + outputs['outputLabelFile'] = ( + os.getcwd() + '/' + self.inputs.outputLabelFile) + else: + outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') + return outputs class hemisplitInputSpec(CommandLineInputSpec): - inputSurfaceFile = File(mandatory=True, desc='input surface', argstr='-i %s') - inputHemisphereLabelFile = File(mandatory=True, desc='input hemisphere label volume', argstr='-l %s') - outputLeftHemisphere = File(mandatory=False, desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) - outputRightHemisphere = File(mandatory=False, desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) - pialSurfaceFile = File(desc='pial surface file -- must have same geometry as input surface', argstr='-p %s') - outputLeftPialHemisphere = File(mandatory=False, desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) - outputRightPialHemisphere = File(mandatory=False, desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) + inputSurfaceFile = File( + mandatory=True, + desc='input surface', + argstr='-i %s') + inputHemisphereLabelFile = File( + mandatory=True, + desc='input hemisphere label volume', + argstr='-l %s') + outputLeftHemisphere = File( + mandatory=False, + desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', + argstr='--left %s', + genfile=True) + outputRightHemisphere = File( + mandatory=False, + desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', + argstr='--right %s', + genfile=True) + pialSurfaceFile = File( + desc='pial surface file -- must have same geometry as input surface', + argstr='-p %s') + outputLeftPialHemisphere = File( + mandatory=False, + desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', + argstr='-pl %s', + genfile=True) + outputRightPialHemisphere = File( + mandatory=False, + desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', + argstr='-pr %s', + genfile=True) verbosity = traits.Int(desc='verbosity (0 = silent)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') - - + class hemisplitOutputSpec(TraitedSpec): outputLeftHemisphere = File(desc='path/name of left hemisphere') outputRightHemisphere = File(desc='path/name of right hemisphere') @@ -659,53 +922,59 @@ class hemisplit(CommandLine): output_spec = hemisplitOutputSpec _cmd = 'hemisplit' - - def _gen_filename(self, name): - if name=='outputLeftHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name=='outputRightHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name=='outputLeftPialHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name=='outputRightPialHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - + if name == 'outputLeftHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), + "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputRightHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), + "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputLeftPialHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), + "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputRightPialHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputLeftHemisphere): - outputs['outputLeftHemisphere'] = (os.getcwd() + '/' + self.inputs.outputLeftHemisphere) + outputs['outputLeftHemisphere'] = (os.getcwd() + '/' + + self.inputs.outputLeftHemisphere) else: - outputs['outputLeftHemisphere'] = self._gen_filename('outputLeftHemisphere') + outputs['outputLeftHemisphere'] = self._gen_filename( + 'outputLeftHemisphere') if isdefined(self.inputs.outputRightHemisphere): - outputs['outputRightHemisphere'] = (os.getcwd() + '/' + self.inputs.outputRightHemisphere) + outputs['outputRightHemisphere'] = (os.getcwd() + '/' + + self.inputs.outputRightHemisphere) else: - outputs['outputRightHemisphere'] = self._gen_filename('outputRightHemisphere') - - + outputs['outputRightHemisphere'] = self._gen_filename( + 'outputRightHemisphere') if isdefined(self.inputs.outputLeftPialHemisphere): - outputs['outputLeftPialHemisphere'] = (os.getcwd() + '/' + self.inputs.outputLeftPialHemisphere) + outputs['outputLeftPialHemisphere'] = ( + os.getcwd() + '/' + self.inputs.outputLeftPialHemisphere) if isdefined(self.inputs.outputRightPialHemisphere): - outputs['outputRightPialHemisphere'] = (os.getcwd() + '/' + self.inputs.outputRightPialHemisphere) + outputs['outputRightPialHemisphere'] = ( + os.getcwd() + '/' + self.inputs.outputRightPialHemisphere) return outputs -#removes directory of a pathway to a file, removes extension, returns file name up to first occurence of three consecutive underscore characters (if any) -#ex: /home/abc/testData___bseOutput_output_file.nii.gz --> testData +# removes directory of a pathway to a file, removes extension, returns file name +# up to first occurence of three consecutive underscore characters (if any) +# ex: /home/abc/testData___bseOutput_output_file.nii.gz --> testData def getFileName(string): - underscoreRegex = regex.compile("[^___]+") + underscoreRegex = regex.compile("[_]{3}") dotRegex = regex.compile("[^.]+") slashRegex = regex.compile("[^/]+") - arr = underscoreRegex.findall(string) - arr2 = dotRegex.findall(arr[0]); + arr = underscoreRegex.split(string) + arr2 = dotRegex.findall(arr[0]) arr3 = slashRegex.findall(arr2[0]) return arr3[len(arr3) - 1] From c52d3c54cff722227358598ac0589391095b5619 Mon Sep 17 00:00:00 2001 From: Jason W Date: Fri, 22 Jan 2016 14:45:33 -0800 Subject: [PATCH 04/25] Update brainsuite.py Added l_outputs function to simplify insantiation of output names/reduce repetition in code --- nipype/interfaces/brainsuite.py | 685 ++++++++++---------------------- 1 file changed, 212 insertions(+), 473 deletions(-) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index 99a6405909..05f2373643 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -49,8 +49,7 @@ class bseInputSpec(CommandLineInputSpec): verbosityLevel = traits.Float(1, usedefault=True, desc=' verbosity level (0=silent)', argstr='-v %f') - noRotate = traits.Bool(True, usedefault=True, - desc='retain original orientation' + noRotate = traits.Bool(desc='retain original orientation' '(default behavior will auto-rotate input NII files' 'to LPI orientation)', argstr='--norotate') timer = traits.Bool(desc='show timing', argstr='--timer') @@ -70,39 +69,23 @@ class bse(CommandLine): output_spec = bseOutputSpec _cmd = 'bse' - def _list_outputs(self): + def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') - outputs = self.output_spec().get() - if isdefined(self.inputs.outputMRIVolume): - outputs['outputMRIVolume'] = (os.getcwd() + '/' + - self.inputs.outputMRIVolume) - else: - outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') - - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + - self.inputs.outputMaskFile) - if isdefined(self.inputs.outputDiffusionFilter): - outputs['outputDiffusionFilter'] = (os.getcwd() + '/' + - self.inputs.outputDiffusionFilter) - if isdefined(self.inputs.outputEdgeMap): - outputs['outputEdgeMap'] = (os.getcwd() + '/' + - self.inputs.outputEdgeMap) - if isdefined(self.inputs.outputDetailedBrainMask): - outputs['outputDetailedBrainMask'] = (os.getcwd() + '/' + - self.inputs.outputDetailedBrainMask) - if isdefined(self.inputs.outputCortexFile): - outputs['outputCortexFile'] = (os.getcwd() + '/' + - self.inputs.outputCortexFile) - - return outputs + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + + return toReturn - def _gen_filename(self, name): if name == 'outputMRIVolume': myExtension = '.nii.gz' return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + return None + + def _list_outputs(self): + return l_outputs(self) class bfcInputSpec(CommandLineInputSpec): @@ -168,11 +151,9 @@ class bfcInputSpec(CommandLineInputSpec): convergenceThreshold = traits.Float(desc='convergence threshold', argstr='--eps %f') biasEstimateConvergenceThreshold = traits.Float( - desc='bias estimate convergence threshold (values > 0.1 disable)', - argstr='--beps %f') + desc='bias estimate convergence threshold (values > 0.1 disable)', argstr='--beps %f') verbosityLevel = traits.Int( - desc='verbosity level (0=silent)', - argstr='-v %d') + desc='verbosity level (0=silent)', argstr='-v %d') timer = traits.Bool(desc='display timing information', argstr='--timer') @@ -190,67 +171,43 @@ class bfc(CommandLine): _cmd = 'bfc' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputMRIVolume': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + return None def _format_arg(self, name, spec, value): if name == 'histogramType': - return spec.argstr % { - "ellipse": "--ellipse", "block": "--block"}[value] + return spec.argstr % {"ellipse": "--ellipse", "block": "--block"}[value] if name == 'biasRange': - return spec.argstr % {"low": "--low", - "medium": "--medium", "high": "--high"}[value] + return spec.argstr % {"low": "--low", "medium": "--medium", "high": "--high"}[value] if name == 'intermediate_file_type': - return spec.argstr % {"analyze": "--analyze", "nifti": "--nifti", - "gzippedAnalyze": "--analyzegz", "gzippedNifti": "--niftigz"}[value] + return spec.argstr % {"analyze": "--analyze", "nifti": "--nifti", "gzippedAnalyze": "--analyzegz", "gzippedNifti": "--niftigz"}[value] return super(bfc, self)._format_arg(name, spec, value) def _list_outputs(self): - outputs = self.output_spec().get() - - if isdefined(self.inputs.outputMRIVolume): - outputs['outputMRIVolume'] = ( - os.getcwd() + '/' + self.inputs.outputMRIVolume) - else: - outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') - - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputMaskFile) - if isdefined(self.inputs.outputBiasField): - outputs['outputBiasField'] = ( - os.getcwd() + '/' + self.inputs.outputBiasField) - if isdefined(self.inputs.outputMaskedBiasField): - outputs['outputMaskedBiasField'] = ( - os.getcwd() + '/' + self.inputs.outputMaskedBiasField) - if isdefined(self.inputs.correctionScheduleFile): - outputs['correctionScheduleFile'] = ( - os.getcwd() + '/' + self.inputs.correctionScheduleFile) - - return outputs + return l_outputs(self) class pvcInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') inputMaskFile = File(desc='brain mask file', argstr='-m %s') outputLabelFile = File( - mandatory=False, - desc='output label file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) outputTissueFractionFile = File( - mandatory=False, - desc='output tissue fraction file', - argstr='-f %s', - genfile=True) + mandatory=False, desc='output tissue fraction file', argstr='-f %s', genfile=True) spatialPrior = traits.Float(desc='spatial prior strength', argstr='-l %f') verbosity = traits.Int(desc='verbosity level (0 = silent)', argstr='-v %d') threeClassFlag = traits.Bool( - desc='use a three-class (CSF=0,GM=1,WM=2) labeling', - argstr='-3') + desc='use a three-class (CSF=0,GM=1,WM=2) labeling', argstr='-3') timer = traits.Bool(desc='time processing', argstr='--timer') @@ -265,87 +222,56 @@ class pvc(CommandLine): _cmd = 'pvc' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputLabelFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', self._cmd, - 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', self._cmd, 'Output_', name, myExtension)) if name == 'outputTissueFractionFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) - - def _list_outputs(self): + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - outputs = self.output_spec().get() - if isdefined(self.inputs.outputLabelFile): - outputs['outputLabelFile'] = ( - os.getcwd() + '/' + self.inputs.outputLabelFile) - else: - outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') + return None - if isdefined(self.inputs.outputTissueFractionFile): - outputs['outputTissueFractionFile'] = ( - os.getcwd() + '/' + self.inputs.outputTissueFractionFile) - else: - outputs['outputTissueFractionFile'] = self._gen_filename( - 'outputTissueFractionFile') - - return outputs + def _list_outputs(self): + return l_outputs(self) class cerebroInputSpec(CommandLineInputSpec): inputMRIFile = File( - mandatory=True, - desc='input 3D MRI volume', - argstr='-i %s') + mandatory=True, desc='input 3D MRI volume', argstr='-i %s') inputAtlasMRIFile = File( - mandatory=True, - desc='atlas MRI volume', - argstr='--atlas %s') + mandatory=True, desc='atlas MRI volume', argstr='--atlas %s') inputAtlasLabelFile = File( - mandatory=True, - desc='atlas labeling', - argstr='--atlaslabels %s') + mandatory=True, desc='atlas labeling', argstr='--atlaslabels %s') inputBrainMaskFile = File(desc='brain mask file', argstr='-m %s') outputCerebrumMaskFile = File( - mandatory=False, - desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) outputLabelMaskFile = File( - mandatory=False, - desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', - argstr='-l %s', - genfile=True) + mandatory=False, desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', argstr='-l %s', genfile=True) costFunction = traits.Int(2, usedefault=True, desc='0,1,2', argstr='-c %d') useCentroids = traits.Bool( - desc='use centroids of data to initialize position', - argstr='--centroids') + desc='use centroids of data to initialize position', argstr='--centroids') outputAffineTransformFile = File( - desc='save affine transform to file.', - argstr='--air %s') + desc='save affine transform to file.', argstr='--air %s') outputWarpTransformFile = File( - desc='save warp transform to file.', - argstr='--warp %s') + desc='save warp transform to file.', argstr='--warp %s') verbosity = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') linearConvergence = traits.Float( - desc='linear convergence', - argstr='--linconv %f') + desc='linear convergence', argstr='--linconv %f') warpLabel = traits.Int( - desc='warp order (2,3,4,5,6,7,8)', - argstr='--warplevel %d') + desc='warp order (2,3,4,5,6,7,8)', argstr='--warplevel %d') warpConvergence = traits.Float( - desc='warp convergence', - argstr='--warpconv %f') + desc='warp convergence', argstr='--warpconv %f') keepTempFiles = traits.Bool( - desc="don't remove temporary files", - argstr='--keep') + desc="don't remove temporary files", argstr='--keep') tempDirectory = traits.Str( - desc='specify directory to use for temporary files', - argstr='--tempdir %s') + desc='specify directory to use for temporary files', argstr='--tempdir %s') tempDirectoryBase = traits.Str( - desc='create a temporary directory within this directory', - argstr='--tempdirbase %s') + desc='create a temporary directory within this directory', argstr='--tempdirbase %s') class cerebroOutputSpec(TraitedSpec): @@ -361,73 +287,40 @@ class cerebro(CommandLine): _cmd = 'cerebro' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputCerebrumMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) if name == 'outputLabelMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) - - def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputCerebrumMaskFile): - outputs['outputCerebrumMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputCerebrumMaskFile) - else: - outputs['outputCerebrumMaskFile'] = self._gen_filename( - 'outputCerebrumMaskFile') + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - if isdefined(self.inputs.outputLabelMaskFile): - outputs['outputLabelMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputLabelMaskFile) - else: - outputs['outputLabelMaskFile'] = self._gen_filename( - 'outputLabelMaskFile') + return None - if isdefined(self.inputs.outputAffineTransformFile): - outputs['outputAffineTransformFile'] = ( - os.getcwd() + '/' + self.inputs.outputAffineTransformFile) - if isdefined(self.inputs.outputWarpTransformFile): - outputs['outputWarpTransformFile'] = ( - os.getcwd() + '/' + self.inputs.outputWarpTransformFile) - - return outputs + def _list_outputs(self): + return l_outputs(self) class cortexInputSpec(CommandLineInputSpec): inputHemisphereLabelFile = File( - mandatory=True, - desc='hemisphere / lobe label volume', - argstr='-h %s') + mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') outputCerebrumMask = File( - mandatory=False, - desc='output structure mask. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) inputTissueFractionFile = File( - mandatory=True, - desc='tissue fraction file (32-bit float)', - argstr='-f %s') + mandatory=True, desc='tissue fraction file (32-bit float)', argstr='-f %s') tissueFractionThreshold = traits.Float( - 50.0, - usedefault=True, - desc='tissue fraction threshold (percentage)', - argstr='-p %f') + 50.0, usedefault=True, desc='tissue fraction threshold (percentage)', argstr='-p %f') computeWGBoundary = traits.Bool( - True, - usedefault=True, - desc='compute WM/GM boundary', - argstr='-w') + True, usedefault=True, desc='compute WM/GM boundary', argstr='-w') computeGCBoundary = traits.Bool( desc='compute GM/CSF boundary', argstr='-g') includeAllSubcorticalAreas = traits.Bool( - True, - usedefault=True, - esc='include all subcortical areas in WM mask', - argstr='-a') + True, usedefault=True, esc='include all subcortical areas in WM mask', argstr='-a') verbosity = traits.Int(desc='verbosity level', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') @@ -442,44 +335,30 @@ class cortex(CommandLine): _cmd = 'cortex' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputCerebrumMask': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), "___", self._cmd, 'Output_', name, myExtension)) - def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputCerebrumMask): - outputs['outputCerebrumMask'] = ( - os.getcwd() + '/' + self.inputs.outputCerebrumMask) - else: - outputs['outputCerebrumMask'] = self._gen_filename( - 'outputCerebrumMask') + return None - return outputs + def _list_outputs(self): + return l_outputs(self) class scrubmaskInputSpec(CommandLineInputSpec): inputMaskFile = File( - mandatory=True, - desc='input structure mask file', - argstr='-i %s') + mandatory=True, desc='input structure mask file', argstr='-i %s') outputMaskFile = File( - mandatory=False, - desc='output structure mask file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) backgroundFillThreshold = traits.Int( - 2, - usedefault=True, - desc='background fill threshold', - argstr='-b %d') + 2, usedefault=True, desc='background fill threshold', argstr='-b %d') foregroundTrimThreshold = traits.Int( - 0, - usedefault=True, - desc='foreground trim threshold', - argstr='-f %d') + 0, usedefault=True, desc='foreground trim threshold', argstr='-f %d') numberIterations = traits.Int(desc='number of iterations', argstr='-n %d') verbosity = traits.Int(desc='verbosity (0=silent)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') @@ -495,46 +374,31 @@ class scrubmask(CommandLine): _cmd = 'scrubmask' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + return None def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputMaskFile) - else: - outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') - - return outputs + return l_outputs(self) class tcaInputSpec(CommandLineInputSpec): inputMaskFile = File( - mandatory=True, - desc='input mask volume', - argstr='-i %s') + mandatory=True, desc='input mask volume', argstr='-i %s') outputMaskFile = File( - mandatory=False, - desc='output mask volume. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) minCorrectionSize = traits.Int( - 2500, - usedefault=True, - desc='maximum correction size', - argstr='-m %d') + 2500, usedefault=True, desc='maximum correction size', argstr='-m %d') maxCorrectionSize = traits.Int( - desc='minimum correction size', - argstr='-n %d') + desc='minimum correction size', argstr='-n %d') foregroundDelta = traits.Int( - 20, - usedefault=True, - desc='foreground delta', - argstr='--delta %d') + 20, usedefault=True, desc='foreground delta', argstr='--delta %d') verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') @@ -549,35 +413,29 @@ class tca(CommandLine): _cmd = 'tca' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) - def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputMaskFile) - else: - outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') + return None - return outputs + def _list_outputs(self): + return l_outputs(self) class dewispInputSpec(CommandLineInputSpec): inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') outputMaskFile = File( - mandatory=False, - desc='output file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') sizeThreshold = traits.Int(desc='size threshold', argstr='-t %d') maximumIterations = traits.Int( - desc='maximum number of iterations', - argstr='-n %d') + desc='maximum number of iterations', argstr='-n %d') timer = traits.Bool(desc='time processing', argstr='--timer') @@ -591,82 +449,47 @@ class dewisp(CommandLine): _cmd = 'dewisp' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) - def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputMaskFile) - else: - outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') + return None - return outputs + def _list_outputs(self): + return l_outputs(self) class dfsInputSpec(CommandLineInputSpec): inputVolumeFile = File( - mandatory=True, - desc='input 3D volume', - argstr='-i %s') + mandatory=True, desc='input 3D volume', argstr='-i %s') outputSurfaceFile = File( - mandatory=False, - desc='output surface mesh file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) inputShadingVolume = File( - desc='shade surface model with data from image volume', - argstr='-c %s') + desc='shade surface model with data from image volume', argstr='-c %s') smoothingIterations = traits.Int( - 10, - usedefault=True, - desc='number of smoothing iterations', - argstr='-n %d') + 10, usedefault=True, desc='number of smoothing iterations', argstr='-n %d') smoothingConstant = traits.Float( - 0.5, - usedefault=True, - desc='smoothing constant', - argstr='-a %f') + 0.5, usedefault=True, desc='smoothing constant', argstr='-a %f') curvatureWeighting = traits.Float( - 5.0, - usedefault=True, - desc='curvature weighting', - argstr='-w %f') + 5.0, usedefault=True, desc='curvature weighting', argstr='-w %f') scalingPercentile = traits.Float(desc='scaling percentile', argstr='-f %f') nonZeroTessellation = traits.Bool( - desc='tessellate non-zero voxels', - argstr='-nz', - xor=( - 'nonZeroTessellation', - 'specialTessellation')) + desc='tessellate non-zero voxels', argstr='-nz', xor=('nonZeroTessellation', 'specialTessellation')) tessellationThreshold = traits.Float( - desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', - argstr='%f') - specialTessellation = traits.Enum( - 'greater_than', - 'less_than', - 'equal_to', - desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', - argstr='%s', - xor=( - 'nonZeroTessellation', - 'specialTessellation'), - requires=['tessellationThreshold'], - position=- - 1) + desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%f') + specialTessellation = traits.Enum('greater_than', 'less_than', 'equal_to', desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%s', xor=( + 'nonZeroTessellation', 'specialTessellation'), requires=['tessellationThreshold'], position=-1) zeroPadFlag = traits.Bool( - desc='zero-pad volume (avoids clipping at edges)', - argstr='-z') + desc='zero-pad volume (avoids clipping at edges)', argstr='-z') noNormalsFlag = traits.Bool( - desc='do not compute vertex normals', - argstr='--nonormals') + desc='do not compute vertex normals', argstr='--nonormals') postSmoothFlag = traits.Bool( - desc='smooth vertices after coloring', - argstr='--postsmooth') + desc='smooth vertices after coloring', argstr='--postsmooth') verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') @@ -685,97 +508,59 @@ def _format_arg(self, name, spec, value): return '' # blank argstr if name == 'specialTessellation': threshold = self.inputs.tessellationThreshold - return spec.argstr % {"greater_than": ''.join(("-gt %f" % threshold)), "less_than": ''.join( - ("-lt %f" % threshold)), "equal_to": ''.join(("-eq %f" % threshold))}[value] + return spec.argstr % {"greater_than": ''.join(("-gt %f" % threshold)), "less_than": ''.join(("-lt %f" % threshold)), "equal_to": ''.join(("-eq %f" % threshold))}[value] return super(dfs, self)._format_arg(name, spec, value) def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputSurfaceFile': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), - "___", self._cmd, 'Output_', name, myExtension)) - - def _list_outputs(self): + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), "___", self._cmd, 'Output_', name, myExtension)) - outputs = self.output_spec().get() - if isdefined(self.inputs.outputSurfaceFile): - outputs['outputSurfaceFile'] = ( - os.getcwd() + '/' + self.inputs.outputSurfaceFile) - else: - outputs['outputSurfaceFile'] = self._gen_filename( - 'outputSurfaceFile') + return None - return outputs + def _list_outputs(self): + return l_outputs(self) class pialmeshInputSpec(CommandLineInputSpec): inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') outputSurfaceFile = File( - mandatory=False, - desc='output file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') inputTissueFractionFile = File( - mandatory=True, - desc='floating point (32) tissue fraction image', - argstr='-f %s') + mandatory=True, desc='floating point (32) tissue fraction image', argstr='-f %s') numIterations = traits.Int( - 100, - usedefault=True, - desc='number of iterations', - argstr='-n %d') + 100, usedefault=True, desc='number of iterations', argstr='-n %d') searchRadius = traits.Float( - 1, - usedefault=True, - desc='search radius', - argstr='-r %f') - stepSize = traits.Float( - 0.4, - usedefault=True, - desc='step size', - argstr='-s %f') + 1, usedefault=True, desc='search radius', argstr='-r %f') + stepSize = traits.Float(0.4, usedefault=True, + desc='step size', argstr='-s %f') inputMaskFile = File( - mandatory=True, - desc='restrict growth to mask file region', - argstr='-m %s') + mandatory=True, desc='restrict growth to mask file region', argstr='-m %s') maxThickness = traits.Float( - 20, - usedefault=True, - desc='maximum allowed tissue thickness', - argstr='--max %f') + 20, usedefault=True, desc='maximum allowed tissue thickness', argstr='--max %f') tissueThreshold = traits.Float( - 1.05, - usedefault=True, - desc='tissue threshold', - argstr='-t %f') + 1.05, usedefault=True, desc='tissue threshold', argstr='-t %f') # output interval is not an output -- it specifies how frequently the # output surfaces are generated outputInterval = traits.Int( - 10, - usedefault=True, - desc='output interval', - argstr='--interval %d') + 10, usedefault=True, desc='output interval', argstr='--interval %d') exportPrefix = traits.Str( - desc='prefix for exporting surfaces if interval is set', - argstr='--prefix %s') + desc='prefix for exporting surfaces if interval is set', argstr='--prefix %s') laplacianSmoothing = traits.Float( - 0.025, - usedefault=True, - desc='apply Laplacian smoothing', - argstr='--smooth %f') + 0.025, usedefault=True, desc='apply Laplacian smoothing', argstr='--smooth %f') timer = traits.Bool(desc='show timing', argstr='--timer') recomputNormals = traits.Bool( - desc='recompute normals at each iteration', - argstr='--norm') + desc='recompute normals at each iteration', argstr='--norm') normalSmoother = traits.Float( - 0.2, - usedefault=True, - desc='strength of normal smoother.', - argstr='--nc %f') + 0.2, usedefault=True, desc='strength of normal smoother.', argstr='--nc %f') tangentSmoother = traits.Float( - desc='strength of tangential smoother.', - argstr='--tc %f') + desc='strength of tangential smoother.', argstr='--tc %f') class pialmeshOutputSpec(TraitedSpec): @@ -788,63 +573,46 @@ class pialmesh(CommandLine): _cmd = 'pialmesh' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputSurfaceFile': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), - "___", self._cmd, 'Output_', name, myExtension)) - - def _list_outputs(self): + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - outputs = self.output_spec().get() - if isdefined(self.inputs.outputSurfaceFile): - outputs['outputSurfaceFile'] = ( - os.getcwd() + '/' + self.inputs.outputSurfaceFile) - else: - outputs['outputSurfaceFile'] = self._gen_filename( - 'outputSurfaceFile') + return None - return outputs + def _list_outputs(self): + return l_outputs(self) class skullfinderInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='input file', argstr='-i %s') inputMaskFile = File( - mandatory=True, - desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', - argstr='-m %s') + mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') outputLabelFile = File( - mandatory=False, - desc='output file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') lowerThreshold = traits.Int( - desc='Lower threshold for segmentation', - argstr='-l %d') + desc='Lower threshold for segmentation', argstr='-l %d') upperThreshold = traits.Int( - desc='Upper threshold for segmentation', - argstr='-u %d') + desc='Upper threshold for segmentation', argstr='-u %d') surfaceFilePrefix = traits.Str( - desc='if specified, generate surface files for brain, skull, and scalp', - argstr='-s %s') + desc='if specified, generate surface files for brain, skull, and scalp', argstr='-s %s') bgLabelValue = traits.Int( - desc='background label value (0-255)', - argstr='--bglabel %d') + desc='background label value (0-255)', argstr='--bglabel %d') scalpLabelValue = traits.Int( - desc='scalp label value (0-255)', - argstr='--scalplabel %d') + desc='scalp label value (0-255)', argstr='--scalplabel %d') skullLabelValue = traits.Int( - desc='skull label value (0-255)', - argstr='--skulllabel %d') + desc='skull label value (0-255)', argstr='--skulllabel %d') spaceLabelValue = traits.Int( - desc='space label value (0-255)', - argstr='--spacelabel %d') + desc='space label value (0-255)', argstr='--spacelabel %d') brainLabelValue = traits.Int( - desc='brain label value (0-255)', - argstr='--brainlabel %d') + desc='brain label value (0-255)', argstr='--brainlabel %d') performFinalOpening = traits.Bool( - desc='perform a final opening operation on the scalp mask', - argstr='--finalOpening') + desc='perform a final opening operation on the scalp mask', argstr='--finalOpening') class skullfinderOutputSpec(TraitedSpec): @@ -857,55 +625,36 @@ class skullfinder(CommandLine): _cmd = 'skullfinder' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputLabelFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - def _list_outputs(self): + return None - outputs = self.output_spec().get() - if isdefined(self.inputs.outputLabelFile): - outputs['outputLabelFile'] = ( - os.getcwd() + '/' + self.inputs.outputLabelFile) - else: - outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') - - return outputs + def _list_outputs(self): + return l_outputs(self) class hemisplitInputSpec(CommandLineInputSpec): inputSurfaceFile = File( - mandatory=True, - desc='input surface', - argstr='-i %s') + mandatory=True, desc='input surface', argstr='-i %s') inputHemisphereLabelFile = File( - mandatory=True, - desc='input hemisphere label volume', - argstr='-l %s') + mandatory=True, desc='input hemisphere label volume', argstr='-l %s') outputLeftHemisphere = File( - mandatory=False, - desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', - argstr='--left %s', - genfile=True) + mandatory=False, desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) outputRightHemisphere = File( - mandatory=False, - desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', - argstr='--right %s', - genfile=True) + mandatory=False, desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) pialSurfaceFile = File( - desc='pial surface file -- must have same geometry as input surface', - argstr='-p %s') + desc='pial surface file -- must have same geometry as input surface', argstr='-p %s') outputLeftPialHemisphere = File( - mandatory=False, - desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', - argstr='-pl %s', - genfile=True) + mandatory=False, desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) outputRightPialHemisphere = File( - mandatory=False, - desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', - argstr='-pr %s', - genfile=True) + mandatory=False, desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) verbosity = traits.Int(desc='verbosity (0 = silent)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') @@ -923,48 +672,28 @@ class hemisplit(CommandLine): _cmd = 'hemisplit' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputLeftHemisphere': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) if name == 'outputRightHemisphere': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) if name == 'outputLeftPialHemisphere': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) if name == 'outputRightPialHemisphere': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), - "___", self._cmd, 'Output_', name, myExtension)) - - def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputLeftHemisphere): - outputs['outputLeftHemisphere'] = (os.getcwd() + '/' + - self.inputs.outputLeftHemisphere) - else: - outputs['outputLeftHemisphere'] = self._gen_filename( - 'outputLeftHemisphere') - - if isdefined(self.inputs.outputRightHemisphere): - outputs['outputRightHemisphere'] = (os.getcwd() + '/' + - self.inputs.outputRightHemisphere) - else: - outputs['outputRightHemisphere'] = self._gen_filename( - 'outputRightHemisphere') + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if isdefined(self.inputs.outputLeftPialHemisphere): - outputs['outputLeftPialHemisphere'] = ( - os.getcwd() + '/' + self.inputs.outputLeftPialHemisphere) - if isdefined(self.inputs.outputRightPialHemisphere): - outputs['outputRightPialHemisphere'] = ( - os.getcwd() + '/' + self.inputs.outputRightPialHemisphere) + return None - return outputs + def _list_outputs(self): + return l_outputs(self) # removes directory of a pathway to a file, removes extension, returns file name @@ -978,3 +707,13 @@ def getFileName(string): arr2 = dotRegex.findall(arr[0]) arr3 = slashRegex.findall(arr2[0]) return arr3[len(arr3) - 1] + + +def l_outputs(self): + outputs = self.output_spec().get() + for key in outputs: + name = self._gen_filename(key) + if not name is None: + outputs[key] = name + + return outputs From 1d49baebd8b1a73a2669c9245cdb0ae07e81a9ed Mon Sep 17 00:00:00 2001 From: Jason W Date: Thu, 3 Mar 2016 10:46:15 -0800 Subject: [PATCH 05/25] Update brainsuite.py --- nipype/interfaces/brainsuite.py | 129 ++++++++++++++++---------------- 1 file changed, 64 insertions(+), 65 deletions(-) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index 05f2373643..4728e4e020 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -11,7 +11,7 @@ ) -class bseInputSpec(CommandLineInputSpec): +class BseInputSpec(CommandLineInputSpec): inputMRIFile = File(exists=True, mandatory=True, argstr='-i %s', desc='input MRI volume', position=0) @@ -55,7 +55,7 @@ class bseInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='show timing', argstr='--timer') -class bseOutputSpec(TraitedSpec): +class BseOutputSpec(TraitedSpec): outputMRIVolume = File(desc='path/name of brain-masked MRI volume') outputMaskFile = File(desc='path/name of smooth brain mask') outputDiffusionFilter = File(desc='path/name of diffusion filter output') @@ -64,9 +64,9 @@ class bseOutputSpec(TraitedSpec): outputCortexFile = File(desc='path/name of cortex file') -class bse(CommandLine): - input_spec = bseInputSpec - output_spec = bseOutputSpec +class Bse(CommandLine): + input_spec = BseInputSpec + output_spec = BseOutputSpec _cmd = 'bse' def _gen_filename(self, name): @@ -88,16 +88,16 @@ def _list_outputs(self): return l_outputs(self) -class bfcInputSpec(CommandLineInputSpec): +class BfcInputSpec(CommandLineInputSpec): inputMRIFile = File(exists=True, mandatory=True, desc='input skull-stripped MRI volume', argstr='-i %s', position=0) + inputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) outputMRIVolume = File(mandatory=False, desc='output bias-corrected MRI volume.' 'If unspecified, output file name' 'will be auto generated.', argstr='-o %s', position=1, hash_files=False, genfile=True) - outputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) outputBiasField = File(desc='save bias field estimate', argstr='--bias %s', hash_files=False) outputMaskedBiasField = File(desc='save bias field estimate (masked)', @@ -157,17 +157,16 @@ class bfcInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='display timing information', argstr='--timer') -class bfcOutputSpec(TraitedSpec): +class BfcOutputSpec(TraitedSpec): outputMRIVolume = File(desc='path/name of output file') - outputMaskFile = File(desc='path/name of mask output file') outputBiasField = File(desc='path/name of bias field output file') outputMaskedBiasField = File(desc='path/name of masked bias field output') correctionScheduleFile = File(desc='path/name of schedule file') -class bfc(CommandLine): - input_spec = bfcInputSpec - output_spec = bfcOutputSpec +class Bfc(CommandLine): + input_spec = BfcInputSpec + output_spec = BfcOutputSpec _cmd = 'bfc' def _gen_filename(self, name): @@ -191,13 +190,13 @@ def _format_arg(self, name, spec, value): if name == 'intermediate_file_type': return spec.argstr % {"analyze": "--analyze", "nifti": "--nifti", "gzippedAnalyze": "--analyzegz", "gzippedNifti": "--niftigz"}[value] - return super(bfc, self)._format_arg(name, spec, value) + return super(Bfc, self)._format_arg(name, spec, value) def _list_outputs(self): return l_outputs(self) -class pvcInputSpec(CommandLineInputSpec): +class PvcInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') inputMaskFile = File(desc='brain mask file', argstr='-m %s') outputLabelFile = File( @@ -211,14 +210,14 @@ class pvcInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='time processing', argstr='--timer') -class pvcOutputSpec(TraitedSpec): +class PvcOutputSpec(TraitedSpec): outputLabelFile = File(desc='path/name of label file') outputTissueFractionFile = File(desc='path/name of tissue fraction file') -class pvc(CommandLine): - input_spec = pvcInputSpec - output_spec = pvcOutputSpec +class Pvc(CommandLine): + input_spec = PvcInputSpec + output_spec = PvcOutputSpec _cmd = 'pvc' def _gen_filename(self, name): @@ -240,7 +239,7 @@ def _list_outputs(self): return l_outputs(self) -class cerebroInputSpec(CommandLineInputSpec): +class CerebroInputSpec(CommandLineInputSpec): inputMRIFile = File( mandatory=True, desc='input 3D MRI volume', argstr='-i %s') inputAtlasMRIFile = File( @@ -274,16 +273,16 @@ class cerebroInputSpec(CommandLineInputSpec): desc='create a temporary directory within this directory', argstr='--tempdirbase %s') -class cerebroOutputSpec(TraitedSpec): +class CerebroOutputSpec(TraitedSpec): outputCerebrumMaskFile = File(desc='path/name of cerebrum mask file') outputLabelMaskFile = File(desc='path/name of label mask file') outputAffineTransformFile = File(desc='path/name of affine transform file') outputWarpTransformFile = File(desc='path/name of warp transform file') -class cerebro(CommandLine): - input_spec = cerebroInputSpec - output_spec = cerebroOutputSpec +class Cerebro(CommandLine): + input_spec = CerebroInputSpec + output_spec = CerebroOutputSpec _cmd = 'cerebro' def _gen_filename(self, name): @@ -306,7 +305,7 @@ def _list_outputs(self): return l_outputs(self) -class cortexInputSpec(CommandLineInputSpec): +class CortexInputSpec(CommandLineInputSpec): inputHemisphereLabelFile = File( mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') outputCerebrumMask = File( @@ -325,13 +324,13 @@ class cortexInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='timing function', argstr='--timer') -class cortexOutputSpec(TraitedSpec): +class CortexOutputSpec(TraitedSpec): outputCerebrumMask = File(desc='path/name of cerebrum mask') -class cortex(CommandLine): - input_spec = cortexInputSpec - output_spec = cortexOutputSpec +class Cortex(CommandLine): + input_spec = CortexInputSpec + output_spec = CortexOutputSpec _cmd = 'cortex' def _gen_filename(self, name): @@ -350,7 +349,7 @@ def _list_outputs(self): return l_outputs(self) -class scrubmaskInputSpec(CommandLineInputSpec): +class ScrubmaskInputSpec(CommandLineInputSpec): inputMaskFile = File( mandatory=True, desc='input structure mask file', argstr='-i %s') outputMaskFile = File( @@ -364,13 +363,13 @@ class scrubmaskInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='timing function', argstr='--timer') -class scrubmaskOutputSpec(TraitedSpec): +class ScrubmaskOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') -class scrubmask(CommandLine): - input_spec = scrubmaskInputSpec - output_spec = scrubmaskOutputSpec +class Scrubmask(CommandLine): + input_spec = ScrubmaskInputSpec + output_spec = ScrubmaskOutputSpec _cmd = 'scrubmask' def _gen_filename(self, name): @@ -388,7 +387,7 @@ def _list_outputs(self): return l_outputs(self) -class tcaInputSpec(CommandLineInputSpec): +class TcaInputSpec(CommandLineInputSpec): inputMaskFile = File( mandatory=True, desc='input mask volume', argstr='-i %s') outputMaskFile = File( @@ -403,13 +402,13 @@ class tcaInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='timing function', argstr='--timer') -class tcaOutputSpec(TraitedSpec): +class TcaOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') -class tca(CommandLine): - input_spec = tcaInputSpec - output_spec = tcaOutputSpec +class Tca(CommandLine): + input_spec = TcaInputSpec + output_spec = TcaOutputSpec _cmd = 'tca' def _gen_filename(self, name): @@ -428,7 +427,7 @@ def _list_outputs(self): return l_outputs(self) -class dewispInputSpec(CommandLineInputSpec): +class DewispInputSpec(CommandLineInputSpec): inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') outputMaskFile = File( mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) @@ -439,13 +438,13 @@ class dewispInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='time processing', argstr='--timer') -class dewispOutputSpec(TraitedSpec): +class DewispOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') -class dewisp(CommandLine): - input_spec = dewispInputSpec - output_spec = dewispOutputSpec +class Dewisp(CommandLine): + input_spec = DewispInputSpec + output_spec = DewispOutputSpec _cmd = 'dewisp' def _gen_filename(self, name): @@ -464,7 +463,7 @@ def _list_outputs(self): return l_outputs(self) -class dfsInputSpec(CommandLineInputSpec): +class DfsInputSpec(CommandLineInputSpec): inputVolumeFile = File( mandatory=True, desc='input 3D volume', argstr='-i %s') outputSurfaceFile = File( @@ -494,13 +493,13 @@ class dfsInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='timing function', argstr='--timer') -class dfsOutputSpec(TraitedSpec): +class DfsOutputSpec(TraitedSpec): outputSurfaceFile = File(desc='path/name of surface file') -class dfs(CommandLine): - input_spec = dfsInputSpec - output_spec = dfsOutputSpec +class Dfs(CommandLine): + input_spec = DfsInputSpec + output_spec = DfsOutputSpec _cmd = 'dfs' def _format_arg(self, name, spec, value): @@ -509,7 +508,7 @@ def _format_arg(self, name, spec, value): if name == 'specialTessellation': threshold = self.inputs.tessellationThreshold return spec.argstr % {"greater_than": ''.join(("-gt %f" % threshold)), "less_than": ''.join(("-lt %f" % threshold)), "equal_to": ''.join(("-eq %f" % threshold))}[value] - return super(dfs, self)._format_arg(name, spec, value) + return super(Dfs, self)._format_arg(name, spec, value) def _gen_filename(self, name): exec('is_user_defined = isdefined(self.inputs.' + name + ')') @@ -527,7 +526,7 @@ def _list_outputs(self): return l_outputs(self) -class pialmeshInputSpec(CommandLineInputSpec): +class PialmeshInputSpec(CommandLineInputSpec): inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') outputSurfaceFile = File( mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) @@ -555,7 +554,7 @@ class pialmeshInputSpec(CommandLineInputSpec): laplacianSmoothing = traits.Float( 0.025, usedefault=True, desc='apply Laplacian smoothing', argstr='--smooth %f') timer = traits.Bool(desc='show timing', argstr='--timer') - recomputNormals = traits.Bool( + recomputeNormals = traits.Bool( desc='recompute normals at each iteration', argstr='--norm') normalSmoother = traits.Float( 0.2, usedefault=True, desc='strength of normal smoother.', argstr='--nc %f') @@ -563,13 +562,13 @@ class pialmeshInputSpec(CommandLineInputSpec): desc='strength of tangential smoother.', argstr='--tc %f') -class pialmeshOutputSpec(TraitedSpec): +class PialmeshOutputSpec(TraitedSpec): outputSurfaceFile = File(desc='path/name of surface file') -class pialmesh(CommandLine): - input_spec = pialmeshInputSpec - output_spec = pialmeshOutputSpec +class Pialmesh(CommandLine): + input_spec = PialmeshInputSpec + output_spec = PialmeshOutputSpec _cmd = 'pialmesh' def _gen_filename(self, name): @@ -588,7 +587,7 @@ def _list_outputs(self): return l_outputs(self) -class skullfinderInputSpec(CommandLineInputSpec): +class SkullfinderInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='input file', argstr='-i %s') inputMaskFile = File( mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') @@ -615,13 +614,13 @@ class skullfinderInputSpec(CommandLineInputSpec): desc='perform a final opening operation on the scalp mask', argstr='--finalOpening') -class skullfinderOutputSpec(TraitedSpec): +class SkullfinderOutputSpec(TraitedSpec): outputLabelFile = File(desc='path/name of label file') -class skullfinder(CommandLine): - input_spec = skullfinderInputSpec - output_spec = skullfinderOutputSpec +class Skullfinder(CommandLine): + input_spec = SkullfinderInputSpec + output_spec = SkullfinderOutputSpec _cmd = 'skullfinder' def _gen_filename(self, name): @@ -640,7 +639,7 @@ def _list_outputs(self): return l_outputs(self) -class hemisplitInputSpec(CommandLineInputSpec): +class HemisplitInputSpec(CommandLineInputSpec): inputSurfaceFile = File( mandatory=True, desc='input surface', argstr='-i %s') inputHemisphereLabelFile = File( @@ -659,16 +658,16 @@ class hemisplitInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='timing function', argstr='--timer') -class hemisplitOutputSpec(TraitedSpec): +class HemisplitOutputSpec(TraitedSpec): outputLeftHemisphere = File(desc='path/name of left hemisphere') outputRightHemisphere = File(desc='path/name of right hemisphere') outputLeftPialHemisphere = File(desc='path/name of left pial hemisphere') outputRightPialHemisphere = File(desc='path/name of right pial hemisphere') -class hemisplit(CommandLine): - input_spec = hemisplitInputSpec - output_spec = hemisplitOutputSpec +class Hemisplit(CommandLine): + input_spec = HemisplitInputSpec + output_spec = HemisplitOutputSpec _cmd = 'hemisplit' def _gen_filename(self, name): From a6af418ebe3274e46ede0f93bfc8724844154b54 Mon Sep 17 00:00:00 2001 From: Jason W Date: Fri, 4 Mar 2016 17:24:09 -0800 Subject: [PATCH 06/25] Update brainsuite.py --- nipype/interfaces/brainsuite.py | 177 ++++++++++++-------------------- 1 file changed, 67 insertions(+), 110 deletions(-) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index 4728e4e020..f0f78e8a46 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -70,18 +70,13 @@ class Bse(CommandLine): _cmd = 'bse' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputMRIVolume': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', - getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') + return None def _list_outputs(self): @@ -170,15 +165,12 @@ class Bfc(CommandLine): _cmd = 'bfc' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputMRIVolume': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') return None @@ -221,17 +213,12 @@ class Pvc(CommandLine): _cmd = 'pvc' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) - if name == 'outputLabelFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', self._cmd, 'Output_', name, myExtension)) - if name == 'outputTissueFractionFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputLabelFile' or name == 'outputTissueFractionFile': + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') return None @@ -286,18 +273,12 @@ class Cerebro(CommandLine): _cmd = 'cerebro' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) - if name == 'outputCerebrumMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - if name == 'outputLabelMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputCerebrumMaskFile' or name == 'outputLabelMaskFile': + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') return None @@ -334,15 +315,12 @@ class Cortex(CommandLine): _cmd = 'cortex' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputCerebrumMask': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), "___", self._cmd, 'Output_', name, myExtension)) - + return getFileName(self, self.inputs.inputHemisphereLabelFile, name, '.nii.gz') return None def _list_outputs(self): @@ -373,14 +351,14 @@ class Scrubmask(CommandLine): _cmd = 'scrubmask' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') + + return None def _list_outputs(self): @@ -412,14 +390,12 @@ class Tca(CommandLine): _cmd = 'tca' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') return None @@ -448,14 +424,12 @@ class Dewisp(CommandLine): _cmd = 'dewisp' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') return None @@ -511,14 +485,12 @@ def _format_arg(self, name, spec, value): return super(Dfs, self)._format_arg(name, spec, value) def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputSurfaceFile': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputVolumeFile, name, '.dfs') return None @@ -572,14 +544,12 @@ class Pialmesh(CommandLine): _cmd = 'pialmesh' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputSurfaceFile': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputSurfaceFile, name, '.dfs') return None @@ -624,14 +594,12 @@ class Skullfinder(CommandLine): _cmd = 'skullfinder' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputLabelFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') return None @@ -671,42 +639,31 @@ class Hemisplit(CommandLine): _cmd = 'hemisplit' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn - - if name == 'outputLeftHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name == 'outputRightHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name == 'outputLeftPialHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name == 'outputRightPialHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + + if (name == 'outputLeftHemisphere' + or name == 'outputRightHemisphere' + or name == 'outputLeftPialHemisphere' + or name == 'outputRightPialHemisphere'): + return getFileName(self, self.inputs.inputSurfaceFile, name, '.dfs') return None def _list_outputs(self): return l_outputs(self) - -# removes directory of a pathway to a file, removes extension, returns file name -# up to first occurence of three consecutive underscore characters (if any) -# ex: /home/abc/testData___bseOutput_output_file.nii.gz --> testData -def getFileName(string): - underscoreRegex = regex.compile("[_]{3}") +# used to generate file names for outputs +# removes pathway and extension of inputName, returns concatenation of] +# inputName, command, name, and extension +def getFileName(self, inputName, name, extension): + fullInput = os.path.basename(inputName) dotRegex = regex.compile("[^.]+") - slashRegex = regex.compile("[^/]+") - arr = underscoreRegex.split(string) - arr2 = dotRegex.findall(arr[0]) - arr3 = slashRegex.findall(arr2[0]) - return arr3[len(arr3) - 1] - + inputNoExtension = dotRegex.findall(fullInput)[0] + return os.path.abspath( + ''.join((inputNoExtension, '_', self._cmd, '_', name, extension))) def l_outputs(self): outputs = self.output_spec().get() From 41891b44fb5d505156029fd50ac5626ae901f931 Mon Sep 17 00:00:00 2001 From: Jason W Date: Fri, 4 Mar 2016 21:12:10 -0800 Subject: [PATCH 07/25] Update brainsuite.py --- nipype/interfaces/brainsuite.py | 58 +++++++++++++++------------------ 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index f0f78e8a46..192e4e6b8c 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -13,14 +13,12 @@ class BseInputSpec(CommandLineInputSpec): - inputMRIFile = File(exists=True, mandatory=True, argstr='-i %s', - desc='input MRI volume', position=0) - outputMRIVolume = File(mandatory=False, - desc='output brain-masked MRI volume. If' + inputMRIFile = File(mandatory=True, argstr='-i %s', + desc='input MRI volume') + outputMRIVolume = File(desc='output brain-masked MRI volume. If' 'unspecified, output file name will be auto' 'generated.', - argstr='-o %s', position=1, hash_files=False, - genfile=True) + argstr='-o %s', hash_files=False, genfile=True) diffusionConstant = traits.Float(25, usedefault=True, desc='diffusion constant', argstr='-d %f') diffusionIterations = traits.Int(3, usedefault=True, @@ -36,7 +34,7 @@ class BseInputSpec(CommandLineInputSpec): desc='dilate final mask', argstr='-p') trim = traits.Bool(True, usedefault=True, desc='trim brainstem', argstr='--trim') - outputMaskFile = File(mandatory=False, desc='save smooth brain mask', + outputMaskFile = File(desc='save smooth brain mask', argstr='--mask %s', hash_files=False) outputDiffusionFilter = File(desc='diffusion filter output', argstr='--adf %s', hash_files=False) @@ -84,15 +82,13 @@ def _list_outputs(self): class BfcInputSpec(CommandLineInputSpec): - inputMRIFile = File(exists=True, mandatory=True, - desc='input skull-stripped MRI volume', - argstr='-i %s', position=0) + inputMRIFile = File(mandatory=True, + desc='input skull-stripped MRI volume', argstr='-i %s') inputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) - outputMRIVolume = File(mandatory=False, - desc='output bias-corrected MRI volume.' + outputMRIVolume = File(desc='output bias-corrected MRI volume.' 'If unspecified, output file name' 'will be auto generated.', argstr='-o %s', - position=1, hash_files=False, genfile=True) + hash_files=False, genfile=True) outputBiasField = File(desc='save bias field estimate', argstr='--bias %s', hash_files=False) outputMaskedBiasField = File(desc='save bias field estimate (masked)', @@ -191,10 +187,8 @@ def _list_outputs(self): class PvcInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') inputMaskFile = File(desc='brain mask file', argstr='-m %s') - outputLabelFile = File( - mandatory=False, desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - outputTissueFractionFile = File( - mandatory=False, desc='output tissue fraction file', argstr='-f %s', genfile=True) + outputLabelFile = File(desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + outputTissueFractionFile = File(desc='output tissue fraction file', argstr='-f %s', genfile=True) spatialPrior = traits.Float(desc='spatial prior strength', argstr='-l %f') verbosity = traits.Int(desc='verbosity level (0 = silent)', argstr='-v %d') threeClassFlag = traits.Bool( @@ -234,10 +228,10 @@ class CerebroInputSpec(CommandLineInputSpec): inputAtlasLabelFile = File( mandatory=True, desc='atlas labeling', argstr='--atlaslabels %s') inputBrainMaskFile = File(desc='brain mask file', argstr='-m %s') - outputCerebrumMaskFile = File( - mandatory=False, desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - outputLabelMaskFile = File( - mandatory=False, desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', argstr='-l %s', genfile=True) + outputCerebrumMaskFile = File(desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', + argstr='-o %s', genfile=True) + outputLabelMaskFile = File(desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', + argstr='-l %s', genfile=True) costFunction = traits.Int(2, usedefault=True, desc='0,1,2', argstr='-c %d') useCentroids = traits.Bool( desc='use centroids of data to initialize position', argstr='--centroids') @@ -290,7 +284,7 @@ class CortexInputSpec(CommandLineInputSpec): inputHemisphereLabelFile = File( mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') outputCerebrumMask = File( - mandatory=False, desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) inputTissueFractionFile = File( mandatory=True, desc='tissue fraction file (32-bit float)', argstr='-f %s') tissueFractionThreshold = traits.Float( @@ -331,7 +325,7 @@ class ScrubmaskInputSpec(CommandLineInputSpec): inputMaskFile = File( mandatory=True, desc='input structure mask file', argstr='-i %s') outputMaskFile = File( - mandatory=False, desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) backgroundFillThreshold = traits.Int( 2, usedefault=True, desc='background fill threshold', argstr='-b %d') foregroundTrimThreshold = traits.Int( @@ -369,7 +363,7 @@ class TcaInputSpec(CommandLineInputSpec): inputMaskFile = File( mandatory=True, desc='input mask volume', argstr='-i %s') outputMaskFile = File( - mandatory=False, desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) minCorrectionSize = traits.Int( 2500, usedefault=True, desc='maximum correction size', argstr='-m %d') maxCorrectionSize = traits.Int( @@ -406,7 +400,7 @@ def _list_outputs(self): class DewispInputSpec(CommandLineInputSpec): inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') outputMaskFile = File( - mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') sizeThreshold = traits.Int(desc='size threshold', argstr='-t %d') maximumIterations = traits.Int( @@ -441,7 +435,7 @@ class DfsInputSpec(CommandLineInputSpec): inputVolumeFile = File( mandatory=True, desc='input 3D volume', argstr='-i %s') outputSurfaceFile = File( - mandatory=False, desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) inputShadingVolume = File( desc='shade surface model with data from image volume', argstr='-c %s') smoothingIterations = traits.Int( @@ -501,7 +495,7 @@ def _list_outputs(self): class PialmeshInputSpec(CommandLineInputSpec): inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') outputSurfaceFile = File( - mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') inputTissueFractionFile = File( mandatory=True, desc='floating point (32) tissue fraction image', argstr='-f %s') @@ -562,7 +556,7 @@ class SkullfinderInputSpec(CommandLineInputSpec): inputMaskFile = File( mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') outputLabelFile = File( - mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') lowerThreshold = traits.Int( desc='Lower threshold for segmentation', argstr='-l %d') @@ -613,15 +607,15 @@ class HemisplitInputSpec(CommandLineInputSpec): inputHemisphereLabelFile = File( mandatory=True, desc='input hemisphere label volume', argstr='-l %s') outputLeftHemisphere = File( - mandatory=False, desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) + desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) outputRightHemisphere = File( - mandatory=False, desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) + desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) pialSurfaceFile = File( desc='pial surface file -- must have same geometry as input surface', argstr='-p %s') outputLeftPialHemisphere = File( - mandatory=False, desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) + desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) outputRightPialHemisphere = File( - mandatory=False, desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) + desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) verbosity = traits.Int(desc='verbosity (0 = silent)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') From 73f3d0430b7dc7f756bc6582d2fd9e558146523b Mon Sep 17 00:00:00 2001 From: Jason W Date: Wed, 9 Mar 2016 15:34:22 -0800 Subject: [PATCH 08/25] Update brainsuite.py Added description and doctests --- nipype/interfaces/brainsuite.py | 219 ++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index 192e4e6b8c..d49b8147a1 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -63,6 +63,23 @@ class BseOutputSpec(TraitedSpec): class Bse(CommandLine): + """ + brain surface extractor (BSE) + This program performs automated skull and scalp removal on T1-weighted MRI volumes. + + http://brainsuite.org/processing/surfaceextraction/bse/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> bse = brainsuite.Bse() + >>> bse.inputs.inputMRIFile = example_data('structural.nii') + >>> results = bse.run() #doctest: +SKIP + + """ + input_spec = BseInputSpec output_spec = BseOutputSpec _cmd = 'bse' @@ -156,6 +173,25 @@ class BfcOutputSpec(TraitedSpec): class Bfc(CommandLine): + """ + bias field corrector (BFC) + This program corrects gain variation in T1-weighted MRI. + + http://brainsuite.org/processing/surfaceextraction/bfc/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> bfc = brainsuite.Bfc() + >>> bfc.inputs.inputMRIFile = example_data('structural.nii') + >>> bfc.inputs.inputMaskFile = example_data('mask.nii') + >>> results = bfc.run() #doctest: +SKIP + + """ + + input_spec = BfcInputSpec output_spec = BfcOutputSpec _cmd = 'bfc' @@ -202,6 +238,25 @@ class PvcOutputSpec(TraitedSpec): class Pvc(CommandLine): + """ + partial volume classifier (PVC) tool. + This program performs voxel-wise tissue classification T1-weighted MRI. + Image should be skull-stripped and bias-corrected before tissue classification. + + http://brainsuite.org/processing/surfaceextraction/pvc/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> pvc = brainsuite.Pvc() + >>> pvc.inputs.inputMRIFile = example_data('structural.nii') + >>> pvc.inputs.inputMaskFile = example_data('mask.nii') + >>> results = pvc.run() #doctest: +SKIP + + """ + input_spec = PvcInputSpec output_spec = PvcOutputSpec _cmd = 'pvc' @@ -262,6 +317,28 @@ class CerebroOutputSpec(TraitedSpec): class Cerebro(CommandLine): + """ + Cerebrum/cerebellum labeling tool + This program performs automated labeling of cerebellum and cerebrum in T1 MRI. + Input MRI should be skull-stripped or a brain-only mask should be provided. + + + http://brainsuite.org/processing/surfaceextraction/cerebrum/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> cerebro = brainsuite.Cerebro() + >>> cerebro.inputs.inputMRIFile = example_data('structural.nii') + >>> cerebro.inputs.inputAtlasMRIFile = 'atlasMRIVolume.img' + >>> cerebro.inputs.inputAtlasLabelFile = 'atlasLabels.img' + >>> cerebro.inputs.inputBrainMaskFile = example_data('mask.nii') + >>> results = cerebro.run() #doctest: +SKIP + + """ + input_spec = CerebroInputSpec output_spec = CerebroOutputSpec _cmd = 'cerebro' @@ -304,6 +381,25 @@ class CortexOutputSpec(TraitedSpec): class Cortex(CommandLine): + """ + cortex extractor + This program produces a cortical mask using tissue fraction estimates + and a co-registered cerebellum/hemisphere mask. + + http://brainsuite.org/processing/surfaceextraction/cortex/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> cortex = brainsuite.Cortex() + >>> cortex.inputs.inputHemisphereLabelFile = example_data('mask.nii') + >>> cortex.inputs.inputTissueFractionFile = example_data('tissues.nii.gz') + >>> results = cortex.run() #doctest: +SKIP + + """ + input_spec = CortexInputSpec output_spec = CortexOutputSpec _cmd = 'cortex' @@ -340,6 +436,23 @@ class ScrubmaskOutputSpec(TraitedSpec): class Scrubmask(CommandLine): + """ + ScrubMask tool + scrubmask filters binary masks to trim loosely connected voxels that may + result from segmentation errors and produce bumps on tessellated surfaces. + + http://brainsuite.org/processing/surfaceextraction/scrubmask/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> scrubmask = brainsuite.Scrubmask() + >>> scrubmask.inputs.inputMaskFile = example_data('mask.nii') + >>> results = scrubmask.run() #doctest: +SKIP + + """ input_spec = ScrubmaskInputSpec output_spec = ScrubmaskOutputSpec _cmd = 'scrubmask' @@ -379,6 +492,21 @@ class TcaOutputSpec(TraitedSpec): class Tca(CommandLine): + """ + topological correction algorithm (TCA) + This program removes topological handles from a binary object. + + http://brainsuite.org/processing/surfaceextraction/tca/ + + Examples + -------- + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> tca = brainsuite.Tca() + >>> tca.inputs.inputMaskFile = example_data('mask.nii') + >>> results = tca.run() #doctest: +SKIP + + """ input_spec = TcaInputSpec output_spec = TcaOutputSpec _cmd = 'tca' @@ -413,6 +541,28 @@ class DewispOutputSpec(TraitedSpec): class Dewisp(CommandLine): + """ + dewisp + removes wispy tendril structures from cortex model binary masks. + It does so based on graph theoretic analysis of connected components, + similar to TCA. Each branch of the structure graph is analyzed to determine + pinch points that indicate a likely error in segmentation that attaches noise + to the image. The pinch threshold determines how many voxels the cross-section + can be before it is considered part of the image. + + http://brainsuite.org/processing/surfaceextraction/dewisp/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> dewisp = brainsuite.Dewisp() + >>> dewisp.inputs.inputMaskFile = example_data('mask.nii') + >>> results = dewisp.run() #doctest: +SKIP + + """ + input_spec = DewispInputSpec output_spec = DewispOutputSpec _cmd = 'dewisp' @@ -466,6 +616,23 @@ class DfsOutputSpec(TraitedSpec): class Dfs(CommandLine): + """ + Surface Generator + Generates mesh surfaces using an isosurface algorithm. + + http://brainsuite.org/processing/surfaceextraction/inner-cortical-surface/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> dfs = brainsuite.Dfs() + >>> dfs.inputs.inputVolumeFile = example_data('structural.nii') + >>> results = dfs.run() #doctest: +SKIP + + """ + input_spec = DfsInputSpec output_spec = DfsOutputSpec _cmd = 'dfs' @@ -533,6 +700,25 @@ class PialmeshOutputSpec(TraitedSpec): class Pialmesh(CommandLine): + """ + pialmesh + computes a pial surface model using an inner WM/GM mesh and a tissue fraction map. + + http://brainsuite.org/processing/surfaceextraction/pial/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> pialmesh = brainsuite.Pialmesh() + >>> pialmesh.inputs.inputSurfaceFile = 'input_mesh.dfs' + >>> pialmesh.inputs.inputTissueFractionFile = 'frac_file.nii.gz' + >>> pialmesh.inputs.inputMaskFile = example_data('mask.nii') + >>> results = pialmesh.run() #doctest: +SKIP + + """ + input_spec = PialmeshInputSpec output_spec = PialmeshOutputSpec _cmd = 'pialmesh' @@ -583,6 +769,20 @@ class SkullfinderOutputSpec(TraitedSpec): class Skullfinder(CommandLine): + """ + Skull and scalp segmentation algorithm. + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> skullfinder = brainsuite.Skullfinder() + >>> skullfinder.inputs.inputMRIFile = example_data('structural.nii') + >>> skullfinder.inputs.inputMaskFile = example_data('mask.nii') + >>> results = skullfinder.run() #doctest: +SKIP + + """ input_spec = SkullfinderInputSpec output_spec = SkullfinderOutputSpec _cmd = 'skullfinder' @@ -628,6 +828,25 @@ class HemisplitOutputSpec(TraitedSpec): class Hemisplit(CommandLine): + """ + Hemisphere splitter + Splits a surface object into two separate surfaces given an input label volume. + Each vertex is labeled left or right based on the labels being odd (left) or even (right). + The largest contour on the split surface is then found and used as the separation between left and right. + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> hemisplit = brainsuite.Hemisplit() + >>> hemisplit.inputs.inputSurfaceFile = 'input_surf.dfs' + >>> hemisplit.inputs.inputHemisphereLabelFile = 'label.nii' + >>> hemisplit.inputs.pialSurfaceFile = 'pial.dfs' + >>> results = hemisplit.run() #doctest: +SKIP + + """ + input_spec = HemisplitInputSpec output_spec = HemisplitOutputSpec _cmd = 'hemisplit' From ced85588df5beb0233fbac0162fa0276ece46f1b Mon Sep 17 00:00:00 2001 From: jason-wg Date: Mon, 21 Dec 2015 12:34:41 -0800 Subject: [PATCH 09/25] Create brainsuite.py I created an interface for Brainsuite's command line tools. I'd like it to be included in nipype builds installed per the instructions on the nipype website. --- nipype/interfaces/brainsuite.py | 711 ++++++++++++++++++++++++++++++++ 1 file changed, 711 insertions(+) create mode 100644 nipype/interfaces/brainsuite.py diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py new file mode 100644 index 0000000000..01eb3f39ff --- /dev/null +++ b/nipype/interfaces/brainsuite.py @@ -0,0 +1,711 @@ +import os +import re as regex + +from nipype.interfaces.base import( + TraitedSpec, + CommandLineInputSpec, + CommandLine, + File, + traits, + isdefined, +) + + +class bseInputSpec(CommandLineInputSpec): + + inputMRIFile = File(exists=True, mandatory=True, argstr='-i %s', desc='input MRI volume', position=0) + + outputMRIVolume = File(mandatory=False, desc='output brain-masked MRI volume. If unspecified, output file name will be auto generated.', argstr='-o %s', position=1, hash_files=False, genfile=True) + + diffusionConstant = traits.Float(25, usedefault=True, desc='diffusion constant [default if unspecified: 25]' , argstr='-d %f') + + diffusionIterations = traits.Int(3, usedefault=True, desc='diffusion iterations [default if unspecified: 3]', argstr='-n %d') + + edgeDetectionConstant = traits.Float(0.64, usedefault=True, desc='edge detection constant [default if unspecified: 0.64]', argstr='-s %f') + + radius = traits.Float(1, usedefault=True, desc='radius of erosion/dilation filter [default if unspecified: 1]', argstr='-r %f') + + dilateFinalMask = traits.Bool(True, usedefault=True, desc='dilate final mask [default if unspecified: True]', argstr='-p') + + trim = traits.Bool(True, usedefault=True, desc='trim brainstem [default if unspecified: True]', argstr='--trim') + + outputMaskFile = File(mandatory=False, desc='save smooth brain mask' , argstr='--mask %s', hash_files=False) + + outputDiffusionFilter = File(desc='diffusion filter output', argstr='--adf %s', hash_files=False) + + outputEdgeMap = File(desc='edge map output', argstr='--edge %s', hash_files=False) + + outputDetailedBrainMask = File(desc='save detailed brain mask', argstr='--hires %s', hash_files=False) + + outputCortexFile = File(desc='cortex file', argstr='--cortex %s', hash_files=False) + + verbosityLevel = traits.Float(1, usedefault=True, desc=' verbosity level (0=silent) [default if unspecified: 1]', argstr='-v %f') + + noRotate = traits.Bool(True, usedefault=True, desc='retain original orientation (default behavior will auto-rotate input NII files to LPI orientation) [default if unspecified: True]', argstr='--norotate') + + timer = traits.Bool(desc='show timing', argstr='--timer') + + +class bseOutputSpec(TraitedSpec): + outputMRIVolume = File(desc='path/name of brain-masked MRI volume') + outputMaskFile = File(desc='path/name of smooth brain mask') + outputDiffusionFilter = File(desc='path/name of diffusion filter output') + outputEdgeMap = File(desc='path/name of edge map output') + outputDetailedBrainMask = File(desc='path/name of detailed brain mask') + outputCortexFile = File(desc='path/name of cortex file') + + +class bse(CommandLine): + input_spec = bseInputSpec + output_spec = bseOutputSpec + _cmd = 'bse' + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputMRIVolume): + outputs['outputMRIVolume'] = (os.getcwd() + '/' + self.inputs.outputMRIVolume) + else: + outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') + + + if isdefined(self.inputs.outputMaskFile): + outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + if isdefined(self.inputs.outputDiffusionFilter): + outputs['outputDiffusionFilter'] = (os.getcwd() + '/' + self.inputs.outputDiffusionFilter) + if isdefined(self.inputs.outputEdgeMap): + outputs['outputEdgeMap'] = (os.getcwd() + '/' + self.inputs.outputEdgeMap) + if isdefined(self.inputs.outputDetailedBrainMask): + outputs['outputDetailedBrainMask'] = (os.getcwd() + '/' + self.inputs.outputDetailedBrainMask) + if isdefined(self.inputs.outputCortexFile): + outputs['outputCortexFile'] = (os.getcwd() + '/' + self.inputs.outputCortexFile) + + return outputs + + def _gen_filename(self, name): + if name=='outputMRIVolume': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + + + + +class bfcInputSpec(CommandLineInputSpec): + inputMRIFile = File(exists = True, mandatory=True, desc='input skull-stripped MRI volume', argstr='-i %s', position=0) + + outputMRIVolume = File(mandatory=False, desc='output bias-corrected MRI volume. If unspecified, output file name will be auto generated.', argstr='-o %s', position=1, hash_files=False, genfile=True) + + outputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) + + outputBiasField = File(desc='save bias field estimate', argstr='--bias %s', hash_files=False) + + outputMaskedBiasField = File(desc='save bias field estimate (masked)', argstr='--maskedbias %s', hash_files=False) + + histogramRadius = traits.Int(desc='histogram radius (voxels)', argstr='-r %d') + + biasEstimateSpacing = traits.Int(desc='bias sample spacing (voxels)', argstr='-s %d') + + controlPointSpacing = traits.Int(desc='control point spacing (voxels)', argstr='-c %d') + + splineLambda = traits.Float(desc='spline stiffness weighting parameter', argstr='-w %f') + + histogramType = traits.Enum('ellipse', 'block', desc="Options for type of histogram\nellipse: use ellipsoid for ROI histogram\nblock:use block for ROI histogram", argstr='%s') + + iterativeMode = traits.Bool(desc='iterative mode (overrides -r, -s, -c, -w settings)', argstr='--iterate') + + correctionScheduleFile = File(desc='list of parameters ', argstr='--schedule %s') + + biasFieldEstimatesOutputPrefix = traits.Str(desc='save iterative bias field estimates as .n.field.nii.gz', argstr='--biasprefix %s') + + correctedImagesOutputPrefix = traits.Str(desc='save iterative corrected images as .n.bfc.nii.gz', argstr='--prefix %s') + + correctWholeVolume = traits.Bool(desc='apply correction field to entire volume', argstr='--extrapolate') + + minBias = traits.Float(0.5, usedefault=True, desc='minimum allowed bias value [default if unspecified: 0.5]', argstr='-L %f') + + maxBias = traits.Float(1.5, usedefault=True, desc='maximum allowed bias value [default if unspecified: 1.5]', argstr='-U %f') + + biasRange = traits.Enum("low", "medium", "high", desc="Preset options for bias_model\nlow: small bias model [0.95,1.05]\nmedium: medium bias model [0.90,1.10]\nhigh: high bias model [0.80,1.20]", argstr='%s') + intermediate_file_type = traits.Enum("analyze", "nifti", "gzippedAnalyze", "gzippedNifti", desc="Options for the format in which intermediate files are generated", argstr='%s') + + convergenceThreshold = traits.Float(desc='convergence threshold', argstr='--eps %f') + + biasEstimateConvergenceThreshold = traits.Float(desc='bias estimate convergence threshold (values > 0.1 disable)', argstr='--beps %f') + + verbosityLevel = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') + + timer = traits.Bool(desc='display timing information', argstr='--timer') + + + +class bfcOutputSpec(TraitedSpec): + outputMRIVolume = File(desc='path/name of output file') + outputMaskFile = File(desc='path/name of mask output file') + outputBiasField = File(desc='path/name of bias field output file') + outputMaskedBiasField = File(desc='path/name of masked bias field output') + correctionScheduleFile = File(desc='path/name of schedule file') + +class bfc(CommandLine): + input_spec = bfcInputSpec + output_spec = bfcOutputSpec + _cmd = 'bfc' + + def _gen_filename(self, name): + if name=='outputMRIVolume': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _format_arg(self, name, spec, value): + if name == 'histogramType': + return spec.argstr%{"ellipse":"--ellipse" , "block":"--block"}[value] + if name == 'biasRange': + return spec.argstr%{"low":"--low" , "medium":"--medium", "high":"--high"}[value] + if name == 'intermediate_file_type': + return spec.argstr%{"analyze":"--analyze" , "nifti":"--nifti", "gzippedAnalyze":"--analyzegz", "gzippedNifti":"--niftigz"}[value] + + return super(bfc, self)._format_arg(name, spec, value) + + + + def _list_outputs(self): + outputs = self.output_spec().get() + + if isdefined(self.inputs.outputMRIVolume): + outputs['outputMRIVolume'] = (os.getcwd() + '/' + self.inputs.outputMRIVolume) + else: + outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') + + + if isdefined(self.inputs.outputMaskFile): + outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + if isdefined(self.inputs.outputBiasField): + outputs['outputBiasField'] = (os.getcwd() + '/' + self.inputs.outputBiasField) + if isdefined(self.inputs.outputMaskedBiasField): + outputs['outputMaskedBiasField'] = (os.getcwd() + '/' + self.inputs.outputMaskedBiasField) + if isdefined(self.inputs.correctionScheduleFile): + outputs['correctionScheduleFile'] = (os.getcwd() + '/' + self.inputs.correctionScheduleFile) + + return outputs + + + + + + + +class pvcInputSpec(CommandLineInputSpec): + inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') + inputMaskFile = File(desc='brain mask file', argstr='-m %s') + outputLabelFile = File(mandatory=False, desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + outputTissueFractionFile = File(mandatory=False, desc='output tissue fraction file', argstr='-f %s', genfile=True) + spatialPrior = traits.Float(desc='spatial prior strength', argstr='-l %f') + verbosity = traits.Int(desc='verbosity level (0 = silent)', argstr='-v %d') + threeClassFlag = traits.Bool(desc='use a three-class (CSF=0,GM=1,WM=2) labeling', argstr='-3') + timer = traits.Bool(desc='time processing', argstr='--timer') + +class pvcOutputSpec(TraitedSpec): + outputLabelFile = File(desc='path/name of label file') + outputTissueFractionFile = File(desc='path/name of tissue fraction file') + +class pvc(CommandLine): + input_spec = pvcInputSpec + output_spec = pvcOutputSpec + _cmd = 'pvc' + + + def _gen_filename(self, name): + if name=='outputLabelFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', self._cmd, 'Output_', name, myExtension)) + if name=='outputTissueFractionFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputLabelFile): + outputs['outputLabelFile'] = (os.getcwd() + '/' + self.inputs.outputLabelFile) + else: + outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') + + if isdefined(self.inputs.outputTissueFractionFile): + outputs['outputTissueFractionFile'] = (os.getcwd() + '/' + self.inputs.outputTissueFractionFile) + else: + outputs['outputTissueFractionFile'] = self._gen_filename('outputTissueFractionFile') + + return outputs + + + + + + +class cerebroInputSpec(CommandLineInputSpec): + inputMRIFile = File(mandatory=True, desc='input 3D MRI volume', argstr='-i %s') + inputAtlasMRIFile = File(mandatory=True, desc='atlas MRI volume', argstr='--atlas %s') + inputAtlasLabelFile = File(mandatory=True, desc='atlas labeling', argstr='--atlaslabels %s') + inputBrainMaskFile = File(desc='brain mask file', argstr='-m %s') + outputCerebrumMaskFile = File(mandatory=False, desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + outputLabelMaskFile = File(mandatory=False, desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', argstr='-l %s', genfile=True) + costFunction = traits.Int(2, usedefault=True, desc='0,1,2 [default if unspecified: 2]', argstr='-c %d') + useCentroids = traits.Bool(desc='use centroids of data to initialize position', argstr='--centroids') + outputAffineTransformFile = File(desc='save affine transform to file.', argstr='--air %s') + outputWarpTransformFile = File(desc='save warp transform to file.', argstr='--warp %s') + verbosity = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') + linearConvergence = traits.Float(desc='linear convergence', argstr='--linconv %f') + warpLabel = traits.Int(desc='warp order (2,3,4,5,6,7,8)', argstr='--warplevel %d') + warpConvergence = traits.Float(desc='warp convergence', argstr='--warpconv %f') + keepTempFiles = traits.Bool(desc="don't remove temporary files", argstr='--keep') + tempDirectory = traits.Str(desc='specify directory to use for temporary files', argstr='--tempdir %s') + tempDirectoryBase = traits.Str(desc='create a temporary directory within this directory', argstr='--tempdirbase %s') + + +class cerebroOutputSpec(TraitedSpec): + outputCerebrumMaskFile = File(desc='path/name of cerebrum mask file') + outputLabelMaskFile = File(desc='path/name of label mask file') + outputAffineTransformFile = File(desc='path/name of affine transform file') + outputWarpTransformFile = File(desc='path/name of warp transform file') + + +class cerebro(CommandLine): + input_spec = cerebroInputSpec + output_spec = cerebroOutputSpec + _cmd = 'cerebro' + + def _gen_filename(self, name): + if name=='outputCerebrumMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + if name=='outputLabelMaskFile': + myExtension= '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputCerebrumMaskFile): + outputs['outputCerebrumMaskFile'] = (os.getcwd() + '/' + self.inputs.outputCerebrumMaskFile) + else: + outputs['outputCerebrumMaskFile'] = self._gen_filename('outputCerebrumMaskFile') + + + if isdefined(self.inputs.outputLabelMaskFile): + outputs['outputLabelMaskFile'] = (os.getcwd() + '/' + self.inputs.outputLabelMaskFile) + else: + outputs['outputLabelMaskFile'] = self._gen_filename('outputLabelMaskFile') + + + if isdefined(self.inputs.outputAffineTransformFile): + outputs['outputAffineTransformFile'] = (os.getcwd() + '/' + self.inputs.outputAffineTransformFile) + if isdefined(self.inputs.outputWarpTransformFile): + outputs['outputWarpTransformFile'] = (os.getcwd() + '/' + self.inputs.outputWarpTransformFile) + + return outputs + + + + + + +class cortexInputSpec(CommandLineInputSpec): + inputHemisphereLabelFile = File(mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') + outputCerebrumMask = File(mandatory=False, desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + inputTissueFractionFile = File(mandatory=True, desc='tissue fraction file (32-bit float)', argstr='-f %s') + tissueFractionThreshold = traits.Float(50.0, usedefault=True, desc='tissue fraction threshold (percentage) [default if unspecified: 50]', argstr='-p %f') + computeWGBoundary = traits.Bool(True, usedefault=True, desc='compute WM/GM boundary [default if unspecified: True]', argstr='-w') + computeGCBoundary = traits.Bool(desc='compute GM/CSF boundary', argstr='-g') + includeAllSubcorticalAreas = traits.Bool(True, usedefault=True, esc='include all subcortical areas in WM mask [default if unspecified: True]', argstr='-a') + verbosity = traits.Int(desc='verbosity level', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + +class cortexOutputSpec(TraitedSpec): + outputCerebrumMask = File(desc='path/name of cerebrum mask') + + +class cortex(CommandLine): + input_spec = cortexInputSpec + output_spec = cortexOutputSpec + _cmd = 'cortex' + + def _gen_filename(self, name): + if name=='outputCerebrumMask': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputCerebrumMask): + outputs['outputCerebrumMask'] = (os.getcwd() + '/' + self.inputs.outputCerebrumMask) + else: + outputs['outputCerebrumMask'] = self._gen_filename('outputCerebrumMask') + + + + return outputs + + + + + + + +class scrubmaskInputSpec(CommandLineInputSpec): + inputMaskFile = File(mandatory=True, desc='input structure mask file', argstr='-i %s') + outputMaskFile = File(mandatory=False, desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + backgroundFillThreshold = traits.Int(2, usedefault=True, desc='background fill threshold [default if unspecified: 2]', argstr='-b %d') + foregroundTrimThreshold = traits.Int(0, usedefault=True, desc='foreground trim threshold [default if unspecified: 0]', argstr='-f %d') + numberIterations = traits.Int(desc='number of iterations', argstr='-n %d') + verbosity = traits.Int(desc='verbosity (0=silent)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + +class scrubmaskOutputSpec(TraitedSpec): + outputMaskFile = File(desc='path/name of mask file') + + +class scrubmask(CommandLine): + input_spec = scrubmaskInputSpec + output_spec = scrubmaskOutputSpec + _cmd = 'scrubmask' + + + def _gen_filename(self, name): + if name=='outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputMaskFile): + outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + else: + outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') + + return outputs + + + + + + + +class tcaInputSpec(CommandLineInputSpec): + inputMaskFile = File(mandatory=True, desc='input mask volume', argstr='-i %s') + outputMaskFile = File(mandatory=False, desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + minCorrectionSize = traits.Int(2500, usedefault=True, desc='maximum correction size [default if unspecified: 2500]', argstr='-m %d') + maxCorrectionSize = traits.Int(desc='minimum correction size', argstr='-n %d') + foregroundDelta = traits.Int(20, usedefault=True, desc='foreground delta [default if unspecified: 20]', argstr='--delta %d') + verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + +class tcaOutputSpec(TraitedSpec): + outputMaskFile = File(desc='path/name of mask file') + + +class tca(CommandLine): + input_spec = tcaInputSpec + output_spec = tcaOutputSpec + _cmd = 'tca' + + + + def _gen_filename(self, name): + if name=='outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputMaskFile): + outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + else: + outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') + + return outputs + + + + + + +class dewispInputSpec(CommandLineInputSpec): + inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') + outputMaskFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + verbosity = traits.Int(desc='verbosity', argstr='-v %d') + sizeThreshold = traits.Int(desc='size threshold', argstr='-t %d') + maximumIterations = traits.Int(desc='maximum number of iterations', argstr='-n %d') + timer = traits.Bool(desc='time processing', argstr='--timer') + +class dewispOutputSpec(TraitedSpec): + outputMaskFile = File(desc='path/name of mask file') + + +class dewisp(CommandLine): + input_spec = dewispInputSpec + output_spec = dewispOutputSpec + _cmd = 'dewisp' + + + def _gen_filename(self, name): + if name=='outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputMaskFile): + outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + else: + outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') + + return outputs + + + + + + + + + +class dfsInputSpec(CommandLineInputSpec): + inputVolumeFile = File(mandatory=True, desc='input 3D volume', argstr='-i %s') + outputSurfaceFile = File(mandatory=False, desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + inputShadingVolume = File(desc='shade surface model with data from image volume', argstr='-c %s') + smoothingIterations = traits.Int(10, usedefault=True, desc='number of smoothing iterations [default if unspecified: 10]', argstr='-n %d') + smoothingConstant = traits.Float(0.5, usedefault=True, desc='smoothing constant [default if unspecified: 0.5]', argstr='-a %f') + curvatureWeighting = traits.Float(5.0, usedefault=True, desc='curvature weighting [default if unspecified: 5.0]', argstr='-w %f') + scalingPercentile = traits.Float(desc='scaling percentile', argstr='-f %f') + nonZeroTessellation = traits.Bool(desc='tessellate non-zero voxels', argstr='-nz', xor=('nonZeroTessellation', 'specialTessellation')) + tessellationThreshold = traits.Float(desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%f') + specialTessellation = traits.Enum('greater_than', 'less_than', 'equal_to', desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%s', xor=('nonZeroTessellation', 'specialTessellation'), requires=['tessellationThreshold'], position=-1) + zeroPadFlag = traits.Bool(desc='zero-pad volume (avoids clipping at edges)', argstr='-z') + noNormalsFlag = traits.Bool(desc='do not compute vertex normals', argstr='--nonormals') + postSmoothFlag = traits.Bool(desc='smooth vertices after coloring', argstr='--postsmooth') + verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + +class dfsOutputSpec(TraitedSpec): + outputSurfaceFile = File(desc='path/name of surface file') + +class dfs(CommandLine): + input_spec = dfsInputSpec + output_spec = dfsOutputSpec + _cmd = 'dfs' + + def _format_arg(self, name, spec, value): + if name == 'tessellationThreshold': + return '' #blank argstr + if name == 'specialTessellation': + threshold = self.inputs.tessellationThreshold + return spec.argstr%{"greater_than":''.join(("-gt %f" % threshold)), "less_than":''.join(("-lt %f" % threshold)) , "equal_to":''.join(("-eq %f" % threshold))}[value] + return super(dfs, self)._format_arg(name, spec, value) + + + def _gen_filename(self, name): + if name=='outputSurfaceFile': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputSurfaceFile): + outputs['outputSurfaceFile'] = (os.getcwd() + '/' + self.inputs.outputSurfaceFile) + else: + outputs['outputSurfaceFile'] = self._gen_filename('outputSurfaceFile') + + return outputs + + + + +class pialmeshInputSpec(CommandLineInputSpec): + inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') + outputSurfaceFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + verbosity = traits.Int(desc='verbosity', argstr='-v %d') + inputTissueFractionFile = File(mandatory=True, desc='floating point (32) tissue fraction image', argstr='-f %s') + numIterations = traits.Int(100, usedefault=True, desc='number of iterations [default if unspecified: 100]', argstr='-n %d') + searchRadius = traits.Float(1, usedefault=True, desc='search radius [default if unspecified: 1]', argstr='-r %f') + stepSize = traits.Float(0.4, usedefault=True, desc='step size [default if unspecified: 0.4]', argstr='-s %f') + inputMaskFile = File(mandatory=True, desc='restrict growth to mask file region', argstr='-m %s') + maxThickness = traits.Float(20, usedefault=True, desc='maximum allowed tissue thickness [default if unspecified: 20]', argstr='--max %f') + tissueThreshold = traits.Float(1.05, usedefault=True, desc='tissue threshold [default if unspecified: 1.05]', argstr='-t %f') +# output interval is not an output -- it specifies how frequently the output surfaces are generated + outputInterval = traits.Int(10, usedefault=True, desc='output interval [default if unspecified: 10]', argstr='--interval %d') + exportPrefix = traits.Str(desc='prefix for exporting surfaces if interval is set', argstr='--prefix %s') + laplacianSmoothing = traits.Float(0.025, usedefault=True, desc='apply Laplacian smoothing [default if unspecified: 0.025]', argstr='--smooth %f') + timer = traits.Bool(desc='show timing', argstr='--timer') + recomputNormals = traits.Bool(desc='recompute normals at each iteration', argstr='--norm') + normalSmoother = traits.Float(0.2, usedefault=True, desc='strength of normal smoother. [default if unspecified: 0.2]', argstr='--nc %f') + tangentSmoother = traits.Float(desc='strength of tangential smoother.', argstr='--tc %f') + + +class pialmeshOutputSpec(TraitedSpec): + outputSurfaceFile = File(desc='path/name of surface file') + + +class pialmesh(CommandLine): + input_spec = pialmeshInputSpec + output_spec = pialmeshOutputSpec + _cmd = 'pialmesh' + + + def _gen_filename(self, name): + if name=='outputSurfaceFile': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputSurfaceFile): + outputs['outputSurfaceFile'] = (os.getcwd() + '/' + self.inputs.outputSurfaceFile) + else: + outputs['outputSurfaceFile'] = self._gen_filename('outputSurfaceFile') + + return outputs + + + + + + + + +class skullfinderInputSpec(CommandLineInputSpec): + inputMRIFile = File(mandatory=True, desc='input file', argstr='-i %s') + inputMaskFile = File(mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') + outputLabelFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + verbosity = traits.Int(desc='verbosity', argstr='-v %d') + lowerThreshold = traits.Int(desc='Lower threshold for segmentation', argstr='-l %d') + upperThreshold = traits.Int(desc='Upper threshold for segmentation', argstr='-u %d') + surfaceFilePrefix = traits.Str(desc='if specified, generate surface files for brain, skull, and scalp', argstr='-s %s') + bgLabelValue = traits.Int(desc='background label value (0-255)', argstr='--bglabel %d') + scalpLabelValue = traits.Int(desc='scalp label value (0-255)', argstr='--scalplabel %d') + skullLabelValue = traits.Int(desc='skull label value (0-255)', argstr='--skulllabel %d') + spaceLabelValue = traits.Int(desc='space label value (0-255)', argstr='--spacelabel %d') + brainLabelValue = traits.Int(desc='brain label value (0-255)', argstr='--brainlabel %d') + performFinalOpening = traits.Bool(desc='perform a final opening operation on the scalp mask', argstr='--finalOpening') + +class skullfinderOutputSpec(TraitedSpec): + outputLabelFile = File(desc='path/name of label file') + + +class skullfinder(CommandLine): + input_spec = skullfinderInputSpec + output_spec = skullfinderOutputSpec + _cmd = 'skullfinder' + + + def _gen_filename(self, name): + if name=='outputLabelFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputLabelFile): + outputs['outputLabelFile'] = (os.getcwd() + '/' + self.inputs.outputLabelFile) + else: + outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') + + return outputs + + + + + + +class hemisplitInputSpec(CommandLineInputSpec): + inputSurfaceFile = File(mandatory=True, desc='input surface', argstr='-i %s') + inputHemisphereLabelFile = File(mandatory=True, desc='input hemisphere label volume', argstr='-l %s') + outputLeftHemisphere = File(mandatory=False, desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) + outputRightHemisphere = File(mandatory=False, desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) + pialSurfaceFile = File(desc='pial surface file -- must have same geometry as input surface', argstr='-p %s') + outputLeftPialHemisphere = File(mandatory=False, desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) + outputRightPialHemisphere = File(mandatory=False, desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) + verbosity = traits.Int(desc='verbosity (0 = silent)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + + + +class hemisplitOutputSpec(TraitedSpec): + outputLeftHemisphere = File(desc='path/name of left hemisphere') + outputRightHemisphere = File(desc='path/name of right hemisphere') + outputLeftPialHemisphere = File(desc='path/name of left pial hemisphere') + outputRightPialHemisphere = File(desc='path/name of right pial hemisphere') + + +class hemisplit(CommandLine): + input_spec = hemisplitInputSpec + output_spec = hemisplitOutputSpec + _cmd = 'hemisplit' + + + + def _gen_filename(self, name): + if name=='outputLeftHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + if name=='outputRightHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + if name=='outputLeftPialHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + if name=='outputRightPialHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + + + def _list_outputs(self): + + outputs = self.output_spec().get() + if isdefined(self.inputs.outputLeftHemisphere): + outputs['outputLeftHemisphere'] = (os.getcwd() + '/' + self.inputs.outputLeftHemisphere) + else: + outputs['outputLeftHemisphere'] = self._gen_filename('outputLeftHemisphere') + + if isdefined(self.inputs.outputRightHemisphere): + outputs['outputRightHemisphere'] = (os.getcwd() + '/' + self.inputs.outputRightHemisphere) + else: + outputs['outputRightHemisphere'] = self._gen_filename('outputRightHemisphere') + + + + if isdefined(self.inputs.outputLeftPialHemisphere): + outputs['outputLeftPialHemisphere'] = (os.getcwd() + '/' + self.inputs.outputLeftPialHemisphere) + if isdefined(self.inputs.outputRightPialHemisphere): + outputs['outputRightPialHemisphere'] = (os.getcwd() + '/' + self.inputs.outputRightPialHemisphere) + + return outputs + + +#removes directory of a pathway to a file, removes extension, returns file name up to first occurence of three consecutive underscore characters (if any) +#ex: /home/abc/testData___bseOutput_output_file.nii.gz --> testData +def getFileName(string): + underscoreRegex = regex.compile("[^___]+") + dotRegex = regex.compile("[^.]+") + slashRegex = regex.compile("[^/]+") + arr = underscoreRegex.findall(string) + arr2 = dotRegex.findall(arr[0]); + arr3 = slashRegex.findall(arr2[0]) + return arr3[len(arr3) - 1] From 5b97dc56a13bb001f8cd7c3f85d6e9a3621d0a67 Mon Sep 17 00:00:00 2001 From: jason-wg Date: Thu, 24 Dec 2015 19:25:28 -0800 Subject: [PATCH 10/25] FIX proposed for S3io When I tried running this code, type(outputs[key]) was never == list or == str, so the method, self.s3tolocal, never got called. When I tried debugging, type(outputs[key]) turned out to be --- nipype/interfaces/io.py | 599 ++++++++++------------------------------ 1 file changed, 149 insertions(+), 450 deletions(-) diff --git a/nipype/interfaces/io.py b/nipype/interfaces/io.py index 6f0ad3bc32..ed5c0b5f9f 100644 --- a/nipype/interfaces/io.py +++ b/nipype/interfaces/io.py @@ -134,54 +134,7 @@ def _add_output_traits(self, base): return base -# Class to track percentage of S3 file upload -class ProgressPercentage(object): - ''' - Callable class instsance (via __call__ method) that displays - upload percentage of a file to S3 - ''' - - def __init__(self, filename): - ''' - ''' - - # Import packages - import threading - - # Initialize data attributes - self._filename = filename - self._size = float(os.path.getsize(filename)) - self._seen_so_far = 0 - self._lock = threading.Lock() - - def __call__(self, bytes_amount): - ''' - ''' - - # Import packages - import sys - - # With the lock on, print upload status - with self._lock: - self._seen_so_far += bytes_amount - if self._size != 0: - percentage = (self._seen_so_far / self._size) * 100 - else: - percentage = 0 - progress_str = '%d / %d (%.2f%%)\r'\ - % (self._seen_so_far, self._size, percentage) - - # Write to stdout - sys.stdout.write(progress_str) - sys.stdout.flush() - - -# DataSink inputs class DataSinkInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec): - ''' - ''' - - # Init inputspec data attributes base_directory = Directory( desc='Path to the base directory for storing data.') container = traits.Str( @@ -193,32 +146,17 @@ class DataSinkInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec): desc=('List of 2-tuples reflecting string ' 'to substitute and string to replace ' 'it with')) - regexp_substitutions = \ - InputMultiPath(traits.Tuple(traits.Str, traits.Str), - desc=('List of 2-tuples reflecting a pair of a '\ - 'Python regexp pattern and a replacement '\ - 'string. Invoked after string `substitutions`')) + regexp_substitutions = InputMultiPath(traits.Tuple(traits.Str, traits.Str), + desc=('List of 2-tuples reflecting a pair ' + 'of a Python regexp pattern and a ' + 'replacement string. Invoked after ' + 'string `substitutions`')) _outputs = traits.Dict(traits.Str, value={}, usedefault=True) remove_dest_dir = traits.Bool(False, usedefault=True, desc='remove dest directory when copying dirs') - # AWS S3 data attributes - creds_path = traits.Str(desc='Filepath to AWS credentials file for S3 bucket '\ - 'access; if not specified, the credentials will '\ - 'be taken from the AWS_ACCESS_KEY_ID and '\ - 'AWS_SECRET_ACCESS_KEY environment variables') - encrypt_bucket_keys = traits.Bool(desc='Flag indicating whether to use S3 '\ - 'server-side AES-256 encryption') - # Set this if user wishes to override the bucket with their own - bucket = traits.Generic(mandatory=False, - desc='Boto3 S3 bucket for manual override of bucket') - # Set this if user wishes to have local copy of files as well - local_copy = traits.Str(desc='Copy files locally as well as to S3 bucket') - - # Set call-able inputs attributes def __setattr__(self, key, value): - if key not in self.copyable_trait_names(): if not isdefined(value): super(DataSinkInputSpec, self).__setattr__(key, value) @@ -229,14 +167,11 @@ def __setattr__(self, key, value): super(DataSinkInputSpec, self).__setattr__(key, value) -# DataSink outputs class DataSinkOutputSpec(TraitedSpec): - # Init out file out_file = traits.Any(desc='datasink output') -# Custom DataSink class class DataSink(IOBase): """ Generic datasink module to store structured outputs @@ -298,12 +233,9 @@ class DataSink(IOBase): >>> ds.run() # doctest: +SKIP """ - - # Give obj .inputs and .outputs input_spec = DataSinkInputSpec output_spec = DataSinkOutputSpec - # Initialization method to set up datasink def __init__(self, infields=None, force_run=True, **kwargs): """ Parameters @@ -325,7 +257,6 @@ def __init__(self, infields=None, force_run=True, **kwargs): if force_run: self._always_run = True - # Get destination paths def _get_dst(self, src): # If path is directory with trailing os.path.sep, # then remove that for a more robust behavior @@ -349,7 +280,6 @@ def _get_dst(self, src): dst = dst[1:] return dst - # Substitute paths in substitutions dictionary parameter def _substitute(self, pathstr): pathstr_ = pathstr if isdefined(self.inputs.substitutions): @@ -370,377 +300,50 @@ def _substitute(self, pathstr): iflogger.info('sub: %s -> %s' % (pathstr_, pathstr)) return pathstr - # Check for s3 in base directory - def _check_s3_base_dir(self): - ''' - Method to see if the datasink's base directory specifies an - S3 bucket path; if it does, it parses the path for the bucket - name in the form 's3://bucket_name/...' and returns it - - Parameters - ---------- - - Returns - ------- - s3_flag : boolean - flag indicating whether the base_directory contained an - S3 bucket path - bucket_name : string - name of the S3 bucket to connect to; if the base directory - is not a valid S3 path, defaults to '' - ''' - - # Init variables - s3_str = 's3://' - bucket_name = '' - base_directory = self.inputs.base_directory - - if not isdefined(base_directory): - s3_flag = False - return s3_flag, bucket_name - - # Explicitly lower-case the "s3" - if base_directory.lower().startswith(s3_str): - base_dir_sp = base_directory.split('/') - base_dir_sp[0] = base_dir_sp[0].lower() - base_directory = '/'.join(base_dir_sp) - - # Check if 's3://' in base dir - if base_directory.startswith(s3_str): - # Expects bucket name to be 's3://bucket_name/base_dir/..' - bucket_name = base_directory.split(s3_str)[1].split('/')[0] - s3_flag = True - # Otherwise it's just a normal datasink - else: - s3_flag = False - - # Return s3_flag - return s3_flag, bucket_name - - # Function to return AWS secure environment variables - def _return_aws_keys(self): - ''' - Method to return AWS access key id and secret access key using - credentials found in a local file. - - Parameters - ---------- - self : nipype.interfaces.io.DataSink - self for instance method - - Returns - ------- - aws_access_key_id : string - string of the AWS access key ID - aws_secret_access_key : string - string of the AWS secret access key - ''' - - # Import packages - import os - - # Init variables - creds_path = self.inputs.creds_path - - # Check if creds exist - if creds_path and os.path.exists(creds_path): - with open(creds_path, 'r') as creds_in: - # Grab csv rows - row1 = creds_in.readline() - row2 = creds_in.readline() - - # Are they root or user keys - if 'User Name' in row1: - # And split out for keys - aws_access_key_id = row2.split(',')[1] - aws_secret_access_key = row2.split(',')[2] - elif 'AWSAccessKeyId' in row1: - # And split out for keys - aws_access_key_id = row1.split('=')[1] - aws_secret_access_key = row2.split('=')[1] - else: - err_msg = 'Credentials file not recognized, check file is correct' - raise Exception(err_msg) - - # Strip any carriage return/line feeds - aws_access_key_id = aws_access_key_id.replace('\r', '').replace('\n', '') - aws_secret_access_key = aws_secret_access_key.replace('\r', '').replace('\n', '') - else: - aws_access_key_id = os.getenv('AWS_ACCESS_KEY_ID') - aws_secret_access_key = os.getenv('AWS_SECRET_ACCESS_KEY') - - # Return keys - return aws_access_key_id, aws_secret_access_key - - # Fetch bucket object - def _fetch_bucket(self, bucket_name): - ''' - Method to return a bucket object which can be used to interact - with an AWS S3 bucket using credentials found in a local file. - - Parameters - ---------- - self : nipype.interfaces.io.DataSink - self for instance method - bucket_name : string - string corresponding to the name of the bucket on S3 - - Returns - ------- - bucket : boto3.resources.factory.s3.Bucket - boto3 s3 Bucket object which is used to interact with files - in an S3 bucket on AWS - ''' - - # Import packages - import logging - - try: - import boto3 - import botocore - except ImportError as exc: - err_msg = 'Boto3 package is not installed - install boto3 and '\ - 'try again.' - raise Exception(err_msg) - - # Init variables - creds_path = self.inputs.creds_path - iflogger = logging.getLogger('interface') - - # Get AWS credentials - try: - aws_access_key_id, aws_secret_access_key = \ - self._return_aws_keys() - except Exception as exc: - err_msg = 'There was a problem extracting the AWS credentials '\ - 'from the credentials file provided: %s. Error:\n%s'\ - % (creds_path, exc) - raise Exception(err_msg) - - # Try and get AWS credentials if a creds_path is specified - if aws_access_key_id and aws_secret_access_key: - # Init connection - iflogger.info('Connecting to S3 bucket: %s with credentials...'\ - % bucket_name) - # Use individual session for each instance of DataSink - # Better when datasinks are being used in multi-threading, see: - # http://boto3.readthedocs.org/en/latest/guide/resources.html#multithreading - session = boto3.session.Session(aws_access_key_id=aws_access_key_id, - aws_secret_access_key=aws_secret_access_key) - s3_resource = session.resource('s3', use_ssl=True) - - # Otherwise, connect anonymously - else: - iflogger.info('Connecting to AWS: %s anonymously...'\ - % bucket_name) - session = boto3.session.Session() - s3_resource = session.resource('s3', use_ssl=True) - s3_resource.meta.client.meta.events.register('choose-signer.s3.*', - botocore.handlers.disable_signing) - - # Explicitly declare a secure SSL connection for bucket object - bucket = s3_resource.Bucket(bucket_name) - - # And try fetch the bucket with the name argument - try: - s3_resource.meta.client.head_bucket(Bucket=bucket_name) - except botocore.exceptions.ClientError as exc: - error_code = int(exc.response['Error']['Code']) - if error_code == 403: - err_msg = 'Access to bucket: %s is denied; check credentials'\ - % bucket_name - raise Exception(err_msg) - elif error_code == 404: - err_msg = 'Bucket: %s does not exist; check spelling and try '\ - 'again' % bucket_name - raise Exception(err_msg) - else: - err_msg = 'Unable to connect to bucket: %s. Error message:\n%s'\ - % (bucket_name, exc) - except Exception as exc: - err_msg = 'Unable to connect to bucket: %s. Error message:\n%s'\ - % (bucket_name, exc) - raise Exception(err_msg) - - # Return the bucket - return bucket - - # Send up to S3 method - def _upload_to_s3(self, bucket, src, dst): - ''' - Method to upload outputs to S3 bucket instead of on local disk - ''' - - # Import packages - import hashlib - import logging - import os - - from botocore.exceptions import ClientError - - # Init variables - iflogger = logging.getLogger('interface') - s3_str = 's3://' - s3_prefix = s3_str + bucket.name - - # Explicitly lower-case the "s3" - if dst.lower().startswith(s3_str): - dst_sp = dst.split('/') - dst_sp[0] = dst_sp[0].lower() - dst = '/'.join(dst_sp) - - # If src is a directory, collect files (this assumes dst is a dir too) - if os.path.isdir(src): - src_files = [] - for root, dirs, files in os.walk(src): - src_files.extend([os.path.join(root, fil) for fil in files]) - # Make the dst files have the dst folder as base dir - dst_files = [os.path.join(dst, src_f.split(src)[1]) \ - for src_f in src_files] - else: - src_files = [src] - dst_files = [dst] - - # Iterate over src and copy to dst - for src_idx, src_f in enumerate(src_files): - # Get destination filename/keyname - dst_f = dst_files[src_idx] - dst_k = dst_f.replace(s3_prefix, '').lstrip('/') - - # See if same file is already up there - try: - dst_obj = bucket.Object(key=dst_k) - dst_md5 = dst_obj.e_tag.strip('"') - - # See if same file is already there - src_read = open(src_f, 'rb').read() - src_md5 = hashlib.md5(src_read).hexdigest() - # Move to next loop iteration - if dst_md5 == src_md5: - iflogger.info('File %s already exists on S3, skipping...' % dst_f) - continue - else: - iflogger.info('Overwriting previous S3 file...') - - except ClientError: - iflogger.info('New file to S3') - - # Copy file up to S3 (either encrypted or not) - iflogger.info('Uploading %s to S3 bucket, %s, as %s...'\ - % (src_f, bucket.name, dst_f)) - if self.inputs.encrypt_bucket_keys: - extra_args = {'ServerSideEncryption' : 'AES256'} - else: - extra_args = {} - bucket.upload_file(src_f, dst_k, ExtraArgs=extra_args, - Callback=ProgressPercentage(src_f)) - - # List outputs, main run routine def _list_outputs(self): """Execute this module. """ - - # Init variables - iflogger = logging.getLogger('interface') outputs = self.output_spec().get() out_files = [] - # Use hardlink - use_hardlink = str2bool(config.get('execution', 'try_hard_link_datasink')) - - # Set local output directory if specified - if isdefined(self.inputs.local_copy): - outdir = self.inputs.local_copy - else: - outdir = self.inputs.base_directory - # If base directory isn't given, assume current directory - if not isdefined(outdir): - outdir = '.' - - # Check if base directory reflects S3 bucket upload - s3_flag, bucket_name = self._check_s3_base_dir() - if s3_flag: - s3dir = self.inputs.base_directory - # If user overrides bucket object, use that - if self.inputs.bucket: - bucket = self.inputs.bucket - # Otherwise fetch bucket object using name - else: - try: - bucket = self._fetch_bucket(bucket_name) - # If encountering an exception during bucket access, set output - # base directory to a local folder - except Exception as exc: - s3dir = '' - if not isdefined(self.inputs.local_copy): - local_out_exception = os.path.join(os.path.expanduser('~'), - 's3_datasink_' + bucket_name) - outdir = local_out_exception - # Log local copying directory - iflogger.info('Access to S3 failed! Storing outputs locally at: '\ - '%s\nError: %s' %(outdir, exc)) - else: - s3dir = '' - - # If container input is given, append that to outdir + outdir = self.inputs.base_directory + if not isdefined(outdir): + outdir = '.' + outdir = os.path.abspath(outdir) if isdefined(self.inputs.container): outdir = os.path.join(outdir, self.inputs.container) - s3dir = os.path.join(s3dir, self.inputs.container) - - # If sinking to local folder - if outdir != s3dir: - outdir = os.path.abspath(outdir) - # Create the directory if it doesn't exist - if not os.path.exists(outdir): - try: - os.makedirs(outdir) - except OSError as inst: - if 'File exists' in inst: - pass - else: - raise(inst) - - # Iterate through outputs attributes {key : path(s)} - for key, files in self.inputs._outputs.items(): + if not os.path.exists(outdir): + try: + os.makedirs(outdir) + except OSError as inst: + if 'File exists' in inst: + pass + else: + raise(inst) + use_hardlink = str2bool(config.get('execution', + 'try_hard_link_datasink')) + for key, files in list(self.inputs._outputs.items()): if not isdefined(files): continue iflogger.debug("key: %s files: %s" % (key, str(files))) files = filename_to_list(files) tempoutdir = outdir - if s3_flag: - s3tempoutdir = s3dir for d in key.split('.'): if d[0] == '@': continue tempoutdir = os.path.join(tempoutdir, d) - if s3_flag: - s3tempoutdir = os.path.join(s3tempoutdir, d) # flattening list if isinstance(files, list): if isinstance(files[0], list): files = [item for sublist in files for item in sublist] - # Iterate through passed-in source files for src in filename_to_list(files): - # Format src and dst files src = os.path.abspath(src) - if not os.path.isfile(src): - src = os.path.join(src, '') - dst = self._get_dst(src) - if s3_flag: - s3dst = os.path.join(s3tempoutdir, dst) - s3dst = self._substitute(s3dst) - dst = os.path.join(tempoutdir, dst) - dst = self._substitute(dst) - path, _ = os.path.split(dst) - - # If we're uploading to S3 - if s3_flag: - self._upload_to_s3(bucket, src, s3dst) - out_files.append(s3dst) - # Otherwise, copy locally src -> dst - if not s3_flag or isdefined(self.inputs.local_copy): - # Create output directory if it doesnt exist + if os.path.isfile(src): + dst = self._get_dst(src) + dst = os.path.join(tempoutdir, dst) + dst = self._substitute(dst) + path, _ = os.path.split(dst) if not os.path.exists(path): try: os.makedirs(path) @@ -749,31 +352,130 @@ def _list_outputs(self): pass else: raise(inst) - # If src is a file, copy it to dst - if os.path.isfile(src): - iflogger.debug('copyfile: %s %s' % (src, dst)) - copyfile(src, dst, copy=True, hashmethod='content', - use_hardlink=use_hardlink) - out_files.append(dst) - # If src is a directory, copy entire contents to dst dir - elif os.path.isdir(src): - if os.path.exists(dst) and self.inputs.remove_dest_dir: - iflogger.debug('removing: %s' % dst) - shutil.rmtree(dst) - iflogger.debug('copydir: %s %s' % (src, dst)) - copytree(src, dst) - out_files.append(dst) - - # Return outputs dictionary + iflogger.debug("copyfile: %s %s" % (src, dst)) + copyfile(src, dst, copy=True, hashmethod='content', + use_hardlink=use_hardlink) + out_files.append(dst) + elif os.path.isdir(src): + dst = self._get_dst(os.path.join(src, '')) + dst = os.path.join(tempoutdir, dst) + dst = self._substitute(dst) + path, _ = os.path.split(dst) + if not os.path.exists(path): + try: + os.makedirs(path) + except OSError as inst: + if 'File exists' in inst: + pass + else: + raise(inst) + if os.path.exists(dst) and self.inputs.remove_dest_dir: + iflogger.debug("removing: %s" % dst) + shutil.rmtree(dst) + iflogger.debug("copydir: %s %s" % (src, dst)) + copytree(src, dst) + out_files.append(dst) outputs['out_file'] = out_files return outputs +class S3DataSinkInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec): + testing = traits.Bool(False, usedefault=True, + desc='Flag for using local fakes3 server.' + ' (for testing purposes only)') + anon = traits.Bool(False, usedefault=True, + desc='Use anonymous connection to s3') + bucket = traits.Str(mandatory=True, + desc='Amazon S3 bucket where your data is stored') + bucket_path = traits.Str('', usedefault=True, + desc='Location within your bucket to store ' + 'data.') + base_directory = Directory( + desc='Path to the base directory for storing data.') + container = traits.Str( + desc='Folder within base directory in which to store output') + parameterization = traits.Bool(True, usedefault=True, + desc='store output in parametrized structure') + strip_dir = Directory(desc='path to strip out of filename') + substitutions = InputMultiPath(traits.Tuple(traits.Str, traits.Str), + desc=('List of 2-tuples reflecting string ' + 'to substitute and string to replace ' + 'it with')) + regexp_substitutions = InputMultiPath(traits.Tuple(traits.Str, traits.Str), + desc=('List of 2-tuples reflecting a pair ' + 'of a Python regexp pattern and a ' + 'replacement string. Invoked after ' + 'string `substitutions`')) + + _outputs = traits.Dict(traits.Str, value={}, usedefault=True) + remove_dest_dir = traits.Bool(False, usedefault=True, + desc='remove dest directory when copying dirs') + + def __setattr__(self, key, value): + if key not in self.copyable_trait_names(): + if not isdefined(value): + super(S3DataSinkInputSpec, self).__setattr__(key, value) + self._outputs[key] = value + else: + if key in self._outputs: + self._outputs[key] = value + super(S3DataSinkInputSpec, self).__setattr__(key, value) + + +class S3DataSink(DataSink): + """ Works exactly like DataSink, except the specified files will + also be uploaded to Amazon S3 storage in the specified bucket + and location. 'bucket_path' is the s3 analog for + 'base_directory'. + + """ + input_spec = S3DataSinkInputSpec + + def _list_outputs(self): + """Execute this module. + """ + outputs = super(S3DataSink, self)._list_outputs() + + self.localtos3(outputs['out_file']) + + return outputs + + def localtos3(self, paths): + if self.inputs.testing: + conn = S3Connection(anon=True, is_secure=False, port=4567, + host='localhost', + calling_format=OrdinaryCallingFormat()) + + else: + conn = S3Connection(anon=self.inputs.anon) + bkt = conn.get_bucket(self.inputs.bucket) + s3paths = [] + + for path in paths: + # convert local path to s3 path + bd_index = path.find(self.inputs.base_directory) + if bd_index != -1: # base_directory is in path, maintain directory structure + s3path = path[bd_index + len(self.inputs.base_directory):] # cut out base directory + if s3path[0] == os.path.sep: + s3path = s3path[1:] + else: # base_directory isn't in path, simply place all files in bucket_path folder + s3path = os.path.split(path)[1] # take filename from path + s3path = os.path.join(self.inputs.bucket_path, s3path) + if s3path[-1] == os.path.sep: + s3path = s3path[:-1] + s3paths.append(s3path) + + k = boto.s3.key.Key(bkt) + k.key = s3path + k.set_contents_from_filename(path) + + return s3paths + + class S3DataGrabberInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec): anon = traits.Bool(False, usedefault=True, - desc='Use anonymous connection to s3. If this is set to True, boto may print' + - ' a urlopen error, but this does not prevent data from being downloaded.') + desc='Use anonymous connection to s3') region = traits.Str('us-east-1', usedefault=True, desc='Region of s3 bucket') bucket = traits.Str(mandatory=True, @@ -954,17 +656,14 @@ def _list_outputs(self): # Outputs are currently stored as locations on S3. # We must convert to the local location specified # and download the files. - for key,val in outputs.iteritems(): - #This will basically be either list-like or string-like: - #if it has the __iter__ attribute, it's list-like (list, - #tuple, numpy array) and we iterate through each of its - #values. If it doesn't, it's string-like (string, - #unicode), and we convert that value directly. - if hasattr(val,'__iter__'): - for i,path in enumerate(val): + for key in outputs: + if type(outputs[key]) == list: + paths = outputs[key] + for i in range(len(paths)): + path = paths[i] outputs[key][i] = self.s3tolocal(path, bkt) - else: - outputs[key] = self.s3tolocal(val, bkt) + elif type(outputs[key]) == str: + outputs[key] = self.s3tolocal(outputs[key], bkt) return outputs From 15755bddf31400c55ba876c41430b426784c4f6b Mon Sep 17 00:00:00 2001 From: jason-wg Date: Wed, 6 Jan 2016 15:04:11 -0800 Subject: [PATCH 11/25] Update brainsuite.py I updated the formatting to comply with the PEP8 style guide (The exception is that some lines run over 79 characters) As for instantiating names, the reason I approached it this way is to shorten the names of outputs that ran through multiple steps of processing using brainsuite command line tools. Is it fine to leave the instantiation of outputs how it is now? --- nipype/interfaces/brainsuite.py | 957 ++++++++++++++++++++------------ 1 file changed, 613 insertions(+), 344 deletions(-) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index 01eb3f39ff..99a6405909 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -13,36 +13,46 @@ class bseInputSpec(CommandLineInputSpec): - inputMRIFile = File(exists=True, mandatory=True, argstr='-i %s', desc='input MRI volume', position=0) - - outputMRIVolume = File(mandatory=False, desc='output brain-masked MRI volume. If unspecified, output file name will be auto generated.', argstr='-o %s', position=1, hash_files=False, genfile=True) - - diffusionConstant = traits.Float(25, usedefault=True, desc='diffusion constant [default if unspecified: 25]' , argstr='-d %f') - - diffusionIterations = traits.Int(3, usedefault=True, desc='diffusion iterations [default if unspecified: 3]', argstr='-n %d') - - edgeDetectionConstant = traits.Float(0.64, usedefault=True, desc='edge detection constant [default if unspecified: 0.64]', argstr='-s %f') - - radius = traits.Float(1, usedefault=True, desc='radius of erosion/dilation filter [default if unspecified: 1]', argstr='-r %f') - - dilateFinalMask = traits.Bool(True, usedefault=True, desc='dilate final mask [default if unspecified: True]', argstr='-p') - - trim = traits.Bool(True, usedefault=True, desc='trim brainstem [default if unspecified: True]', argstr='--trim') - - outputMaskFile = File(mandatory=False, desc='save smooth brain mask' , argstr='--mask %s', hash_files=False) - - outputDiffusionFilter = File(desc='diffusion filter output', argstr='--adf %s', hash_files=False) - - outputEdgeMap = File(desc='edge map output', argstr='--edge %s', hash_files=False) - - outputDetailedBrainMask = File(desc='save detailed brain mask', argstr='--hires %s', hash_files=False) - - outputCortexFile = File(desc='cortex file', argstr='--cortex %s', hash_files=False) - - verbosityLevel = traits.Float(1, usedefault=True, desc=' verbosity level (0=silent) [default if unspecified: 1]', argstr='-v %f') - - noRotate = traits.Bool(True, usedefault=True, desc='retain original orientation (default behavior will auto-rotate input NII files to LPI orientation) [default if unspecified: True]', argstr='--norotate') - + inputMRIFile = File(exists=True, mandatory=True, argstr='-i %s', + desc='input MRI volume', position=0) + outputMRIVolume = File(mandatory=False, + desc='output brain-masked MRI volume. If' + 'unspecified, output file name will be auto' + 'generated.', + argstr='-o %s', position=1, hash_files=False, + genfile=True) + diffusionConstant = traits.Float(25, usedefault=True, + desc='diffusion constant', argstr='-d %f') + diffusionIterations = traits.Int(3, usedefault=True, + desc='diffusion iterations', + argstr='-n %d') + edgeDetectionConstant = traits.Float(0.64, usedefault=True, + desc='edge detection constant', + argstr='-s %f') + radius = traits.Float(1, usedefault=True, + desc='radius of erosion/dilation filter', + argstr='-r %f') + dilateFinalMask = traits.Bool(True, usedefault=True, + desc='dilate final mask', argstr='-p') + trim = traits.Bool(True, usedefault=True, desc='trim brainstem', + argstr='--trim') + outputMaskFile = File(mandatory=False, desc='save smooth brain mask', + argstr='--mask %s', hash_files=False) + outputDiffusionFilter = File(desc='diffusion filter output', + argstr='--adf %s', hash_files=False) + outputEdgeMap = File(desc='edge map output', argstr='--edge %s', + hash_files=False) + outputDetailedBrainMask = File(desc='save detailed brain mask', + argstr='--hires %s', hash_files=False) + outputCortexFile = File(desc='cortex file', argstr='--cortex %s', + hash_files=False) + verbosityLevel = traits.Float(1, usedefault=True, + desc=' verbosity level (0=silent)', + argstr='-v %f') + noRotate = traits.Bool(True, usedefault=True, + desc='retain original orientation' + '(default behavior will auto-rotate input NII files' + 'to LPI orientation)', argstr='--norotate') timer = traits.Bool(desc='show timing', argstr='--timer') @@ -53,7 +63,7 @@ class bseOutputSpec(TraitedSpec): outputEdgeMap = File(desc='path/name of edge map output') outputDetailedBrainMask = File(desc='path/name of detailed brain mask') outputCortexFile = File(desc='path/name of cortex file') - + class bse(CommandLine): input_spec = bseInputSpec @@ -61,84 +71,111 @@ class bse(CommandLine): _cmd = 'bse' def _list_outputs(self): - + outputs = self.output_spec().get() if isdefined(self.inputs.outputMRIVolume): - outputs['outputMRIVolume'] = (os.getcwd() + '/' + self.inputs.outputMRIVolume) + outputs['outputMRIVolume'] = (os.getcwd() + '/' + + self.inputs.outputMRIVolume) else: outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') - - + if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + outputs['outputMaskFile'] = (os.getcwd() + '/' + + self.inputs.outputMaskFile) if isdefined(self.inputs.outputDiffusionFilter): - outputs['outputDiffusionFilter'] = (os.getcwd() + '/' + self.inputs.outputDiffusionFilter) + outputs['outputDiffusionFilter'] = (os.getcwd() + '/' + + self.inputs.outputDiffusionFilter) if isdefined(self.inputs.outputEdgeMap): - outputs['outputEdgeMap'] = (os.getcwd() + '/' + self.inputs.outputEdgeMap) + outputs['outputEdgeMap'] = (os.getcwd() + '/' + + self.inputs.outputEdgeMap) if isdefined(self.inputs.outputDetailedBrainMask): - outputs['outputDetailedBrainMask'] = (os.getcwd() + '/' + self.inputs.outputDetailedBrainMask) + outputs['outputDetailedBrainMask'] = (os.getcwd() + '/' + + self.inputs.outputDetailedBrainMask) if isdefined(self.inputs.outputCortexFile): - outputs['outputCortexFile'] = (os.getcwd() + '/' + self.inputs.outputCortexFile) - + outputs['outputCortexFile'] = (os.getcwd() + '/' + + self.inputs.outputCortexFile) + return outputs - + def _gen_filename(self, name): - if name=='outputMRIVolume': + if name == 'outputMRIVolume': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - - - + return ''.join((os.getcwd(), '/', + getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) class bfcInputSpec(CommandLineInputSpec): - inputMRIFile = File(exists = True, mandatory=True, desc='input skull-stripped MRI volume', argstr='-i %s', position=0) - - outputMRIVolume = File(mandatory=False, desc='output bias-corrected MRI volume. If unspecified, output file name will be auto generated.', argstr='-o %s', position=1, hash_files=False, genfile=True) - + inputMRIFile = File(exists=True, mandatory=True, + desc='input skull-stripped MRI volume', + argstr='-i %s', position=0) + outputMRIVolume = File(mandatory=False, + desc='output bias-corrected MRI volume.' + 'If unspecified, output file name' + 'will be auto generated.', argstr='-o %s', + position=1, hash_files=False, genfile=True) outputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) - - outputBiasField = File(desc='save bias field estimate', argstr='--bias %s', hash_files=False) - - outputMaskedBiasField = File(desc='save bias field estimate (masked)', argstr='--maskedbias %s', hash_files=False) - - histogramRadius = traits.Int(desc='histogram radius (voxels)', argstr='-r %d') - - biasEstimateSpacing = traits.Int(desc='bias sample spacing (voxels)', argstr='-s %d') - - controlPointSpacing = traits.Int(desc='control point spacing (voxels)', argstr='-c %d') - - splineLambda = traits.Float(desc='spline stiffness weighting parameter', argstr='-w %f') - - histogramType = traits.Enum('ellipse', 'block', desc="Options for type of histogram\nellipse: use ellipsoid for ROI histogram\nblock:use block for ROI histogram", argstr='%s') - - iterativeMode = traits.Bool(desc='iterative mode (overrides -r, -s, -c, -w settings)', argstr='--iterate') - - correctionScheduleFile = File(desc='list of parameters ', argstr='--schedule %s') - - biasFieldEstimatesOutputPrefix = traits.Str(desc='save iterative bias field estimates as .n.field.nii.gz', argstr='--biasprefix %s') - - correctedImagesOutputPrefix = traits.Str(desc='save iterative corrected images as .n.bfc.nii.gz', argstr='--prefix %s') - - correctWholeVolume = traits.Bool(desc='apply correction field to entire volume', argstr='--extrapolate') - - minBias = traits.Float(0.5, usedefault=True, desc='minimum allowed bias value [default if unspecified: 0.5]', argstr='-L %f') - - maxBias = traits.Float(1.5, usedefault=True, desc='maximum allowed bias value [default if unspecified: 1.5]', argstr='-U %f') - - biasRange = traits.Enum("low", "medium", "high", desc="Preset options for bias_model\nlow: small bias model [0.95,1.05]\nmedium: medium bias model [0.90,1.10]\nhigh: high bias model [0.80,1.20]", argstr='%s') - intermediate_file_type = traits.Enum("analyze", "nifti", "gzippedAnalyze", "gzippedNifti", desc="Options for the format in which intermediate files are generated", argstr='%s') - - convergenceThreshold = traits.Float(desc='convergence threshold', argstr='--eps %f') - - biasEstimateConvergenceThreshold = traits.Float(desc='bias estimate convergence threshold (values > 0.1 disable)', argstr='--beps %f') - - verbosityLevel = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') - + outputBiasField = File(desc='save bias field estimate', + argstr='--bias %s', hash_files=False) + outputMaskedBiasField = File(desc='save bias field estimate (masked)', + argstr='--maskedbias %s', hash_files=False) + histogramRadius = traits.Int(desc='histogram radius (voxels)', + argstr='-r %d') + biasEstimateSpacing = traits.Int(desc='bias sample spacing (voxels)', + argstr='-s %d') + controlPointSpacing = traits.Int(desc='control point spacing (voxels)', + argstr='-c %d') + splineLambda = traits.Float(desc='spline stiffness weighting parameter', + argstr='-w %f') + histogramType = traits.Enum('ellipse', 'block', + desc='Options for type of histogram\nellipse:' + 'use ellipsoid for ROI histogram\nblock' + ':use block for ROI histogram', + argstr='%s') + iterativeMode = traits.Bool(desc='iterative mode (overrides -r, -s, -c,' + '-w settings)', + argstr='--iterate') + correctionScheduleFile = File(desc='list of parameters ', + argstr='--schedule %s') + biasFieldEstimatesOutputPrefix = traits.Str(desc='save iterative bias' + 'field estimates as' + '.n.field.nii.gz', + argstr='--biasprefix %s') + correctedImagesOutputPrefix = traits.Str(desc='save iterative corrected' + 'images as' + '.n.bfc.nii.gz', + argstr='--prefix %s') + correctWholeVolume = traits.Bool(desc='apply correction field to entire' + 'volume', argstr='--extrapolate') + minBias = traits.Float(0.5, usedefault=True, desc='minimum allowed bias' + 'value', + argstr='-L %f') + maxBias = traits.Float(1.5, usedefault=True, desc='maximum allowed bias' '' + 'value', + argstr='-U %f') + biasRange = traits.Enum("low", "medium", "high", + desc='Preset options for bias_model\n' + 'low: small bias model [0.95,1.05]\n' + 'medium: medium bias model [0.90,1.10]\n' + 'high: high bias model [0.80,1.20]', + argstr='%s') + intermediate_file_type = traits.Enum("analyze", "nifti", + "gzippedAnalyze", "gzippedNifti", + desc='Options for the format in' + 'which intermediate files are' "" + 'generated', + argstr='%s') + convergenceThreshold = traits.Float(desc='convergence threshold', + argstr='--eps %f') + biasEstimateConvergenceThreshold = traits.Float( + desc='bias estimate convergence threshold (values > 0.1 disable)', + argstr='--beps %f') + verbosityLevel = traits.Int( + desc='verbosity level (0=silent)', + argstr='-v %d') timer = traits.Bool(desc='display timing information', argstr='--timer') - - + class bfcOutputSpec(TraitedSpec): outputMRIVolume = File(desc='path/name of output file') outputMaskFile = File(desc='path/name of mask output file') @@ -146,121 +183,169 @@ class bfcOutputSpec(TraitedSpec): outputMaskedBiasField = File(desc='path/name of masked bias field output') correctionScheduleFile = File(desc='path/name of schedule file') + class bfc(CommandLine): input_spec = bfcInputSpec output_spec = bfcOutputSpec _cmd = 'bfc' - + def _gen_filename(self, name): - if name=='outputMRIVolume': + if name == 'outputMRIVolume': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) def _format_arg(self, name, spec, value): if name == 'histogramType': - return spec.argstr%{"ellipse":"--ellipse" , "block":"--block"}[value] + return spec.argstr % { + "ellipse": "--ellipse", "block": "--block"}[value] if name == 'biasRange': - return spec.argstr%{"low":"--low" , "medium":"--medium", "high":"--high"}[value] + return spec.argstr % {"low": "--low", + "medium": "--medium", "high": "--high"}[value] if name == 'intermediate_file_type': - return spec.argstr%{"analyze":"--analyze" , "nifti":"--nifti", "gzippedAnalyze":"--analyzegz", "gzippedNifti":"--niftigz"}[value] + return spec.argstr % {"analyze": "--analyze", "nifti": "--nifti", + "gzippedAnalyze": "--analyzegz", "gzippedNifti": "--niftigz"}[value] return super(bfc, self)._format_arg(name, spec, value) - - def _list_outputs(self): outputs = self.output_spec().get() - + if isdefined(self.inputs.outputMRIVolume): - outputs['outputMRIVolume'] = (os.getcwd() + '/' + self.inputs.outputMRIVolume) + outputs['outputMRIVolume'] = ( + os.getcwd() + '/' + self.inputs.outputMRIVolume) else: outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + outputs['outputMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputMaskFile) if isdefined(self.inputs.outputBiasField): - outputs['outputBiasField'] = (os.getcwd() + '/' + self.inputs.outputBiasField) + outputs['outputBiasField'] = ( + os.getcwd() + '/' + self.inputs.outputBiasField) if isdefined(self.inputs.outputMaskedBiasField): - outputs['outputMaskedBiasField'] = (os.getcwd() + '/' + self.inputs.outputMaskedBiasField) + outputs['outputMaskedBiasField'] = ( + os.getcwd() + '/' + self.inputs.outputMaskedBiasField) if isdefined(self.inputs.correctionScheduleFile): - outputs['correctionScheduleFile'] = (os.getcwd() + '/' + self.inputs.correctionScheduleFile) - - return outputs - - - - + outputs['correctionScheduleFile'] = ( + os.getcwd() + '/' + self.inputs.correctionScheduleFile) + return outputs class pvcInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') inputMaskFile = File(desc='brain mask file', argstr='-m %s') - outputLabelFile = File(mandatory=False, desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - outputTissueFractionFile = File(mandatory=False, desc='output tissue fraction file', argstr='-f %s', genfile=True) + outputLabelFile = File( + mandatory=False, + desc='output label file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + outputTissueFractionFile = File( + mandatory=False, + desc='output tissue fraction file', + argstr='-f %s', + genfile=True) spatialPrior = traits.Float(desc='spatial prior strength', argstr='-l %f') verbosity = traits.Int(desc='verbosity level (0 = silent)', argstr='-v %d') - threeClassFlag = traits.Bool(desc='use a three-class (CSF=0,GM=1,WM=2) labeling', argstr='-3') + threeClassFlag = traits.Bool( + desc='use a three-class (CSF=0,GM=1,WM=2) labeling', + argstr='-3') timer = traits.Bool(desc='time processing', argstr='--timer') + class pvcOutputSpec(TraitedSpec): outputLabelFile = File(desc='path/name of label file') outputTissueFractionFile = File(desc='path/name of tissue fraction file') + class pvc(CommandLine): input_spec = pvcInputSpec output_spec = pvcOutputSpec _cmd = 'pvc' - def _gen_filename(self, name): - if name=='outputLabelFile': + if name == 'outputLabelFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', self._cmd, 'Output_', name, myExtension)) - if name=='outputTissueFractionFile': + return ''.join((os.getcwd(), '/', self._cmd, + 'Output_', name, myExtension)) + if name == 'outputTissueFractionFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputLabelFile): - outputs['outputLabelFile'] = (os.getcwd() + '/' + self.inputs.outputLabelFile) + outputs['outputLabelFile'] = ( + os.getcwd() + '/' + self.inputs.outputLabelFile) else: outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') if isdefined(self.inputs.outputTissueFractionFile): - outputs['outputTissueFractionFile'] = (os.getcwd() + '/' + self.inputs.outputTissueFractionFile) + outputs['outputTissueFractionFile'] = ( + os.getcwd() + '/' + self.inputs.outputTissueFractionFile) else: - outputs['outputTissueFractionFile'] = self._gen_filename('outputTissueFractionFile') + outputs['outputTissueFractionFile'] = self._gen_filename( + 'outputTissueFractionFile') return outputs - - - - class cerebroInputSpec(CommandLineInputSpec): - inputMRIFile = File(mandatory=True, desc='input 3D MRI volume', argstr='-i %s') - inputAtlasMRIFile = File(mandatory=True, desc='atlas MRI volume', argstr='--atlas %s') - inputAtlasLabelFile = File(mandatory=True, desc='atlas labeling', argstr='--atlaslabels %s') + inputMRIFile = File( + mandatory=True, + desc='input 3D MRI volume', + argstr='-i %s') + inputAtlasMRIFile = File( + mandatory=True, + desc='atlas MRI volume', + argstr='--atlas %s') + inputAtlasLabelFile = File( + mandatory=True, + desc='atlas labeling', + argstr='--atlaslabels %s') inputBrainMaskFile = File(desc='brain mask file', argstr='-m %s') - outputCerebrumMaskFile = File(mandatory=False, desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - outputLabelMaskFile = File(mandatory=False, desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', argstr='-l %s', genfile=True) - costFunction = traits.Int(2, usedefault=True, desc='0,1,2 [default if unspecified: 2]', argstr='-c %d') - useCentroids = traits.Bool(desc='use centroids of data to initialize position', argstr='--centroids') - outputAffineTransformFile = File(desc='save affine transform to file.', argstr='--air %s') - outputWarpTransformFile = File(desc='save warp transform to file.', argstr='--warp %s') + outputCerebrumMaskFile = File( + mandatory=False, + desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + outputLabelMaskFile = File( + mandatory=False, + desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', + argstr='-l %s', + genfile=True) + costFunction = traits.Int(2, usedefault=True, desc='0,1,2', argstr='-c %d') + useCentroids = traits.Bool( + desc='use centroids of data to initialize position', + argstr='--centroids') + outputAffineTransformFile = File( + desc='save affine transform to file.', + argstr='--air %s') + outputWarpTransformFile = File( + desc='save warp transform to file.', + argstr='--warp %s') verbosity = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') - linearConvergence = traits.Float(desc='linear convergence', argstr='--linconv %f') - warpLabel = traits.Int(desc='warp order (2,3,4,5,6,7,8)', argstr='--warplevel %d') - warpConvergence = traits.Float(desc='warp convergence', argstr='--warpconv %f') - keepTempFiles = traits.Bool(desc="don't remove temporary files", argstr='--keep') - tempDirectory = traits.Str(desc='specify directory to use for temporary files', argstr='--tempdir %s') - tempDirectoryBase = traits.Str(desc='create a temporary directory within this directory', argstr='--tempdirbase %s') + linearConvergence = traits.Float( + desc='linear convergence', + argstr='--linconv %f') + warpLabel = traits.Int( + desc='warp order (2,3,4,5,6,7,8)', + argstr='--warplevel %d') + warpConvergence = traits.Float( + desc='warp convergence', + argstr='--warpconv %f') + keepTempFiles = traits.Bool( + desc="don't remove temporary files", + argstr='--keep') + tempDirectory = traits.Str( + desc='specify directory to use for temporary files', + argstr='--tempdir %s') + tempDirectoryBase = traits.Str( + desc='create a temporary directory within this directory', + argstr='--tempdirbase %s') class cerebroOutputSpec(TraitedSpec): @@ -276,51 +361,77 @@ class cerebro(CommandLine): _cmd = 'cerebro' def _gen_filename(self, name): - if name=='outputCerebrumMaskFile': + if name == 'outputCerebrumMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - if name=='outputLabelMaskFile': - myExtension= '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputLabelMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) + def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputCerebrumMaskFile): - outputs['outputCerebrumMaskFile'] = (os.getcwd() + '/' + self.inputs.outputCerebrumMaskFile) + outputs['outputCerebrumMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputCerebrumMaskFile) else: - outputs['outputCerebrumMaskFile'] = self._gen_filename('outputCerebrumMaskFile') - + outputs['outputCerebrumMaskFile'] = self._gen_filename( + 'outputCerebrumMaskFile') if isdefined(self.inputs.outputLabelMaskFile): - outputs['outputLabelMaskFile'] = (os.getcwd() + '/' + self.inputs.outputLabelMaskFile) + outputs['outputLabelMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputLabelMaskFile) else: - outputs['outputLabelMaskFile'] = self._gen_filename('outputLabelMaskFile') - + outputs['outputLabelMaskFile'] = self._gen_filename( + 'outputLabelMaskFile') if isdefined(self.inputs.outputAffineTransformFile): - outputs['outputAffineTransformFile'] = (os.getcwd() + '/' + self.inputs.outputAffineTransformFile) + outputs['outputAffineTransformFile'] = ( + os.getcwd() + '/' + self.inputs.outputAffineTransformFile) if isdefined(self.inputs.outputWarpTransformFile): - outputs['outputWarpTransformFile'] = (os.getcwd() + '/' + self.inputs.outputWarpTransformFile) + outputs['outputWarpTransformFile'] = ( + os.getcwd() + '/' + self.inputs.outputWarpTransformFile) return outputs - - - - class cortexInputSpec(CommandLineInputSpec): - inputHemisphereLabelFile = File(mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') - outputCerebrumMask = File(mandatory=False, desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - inputTissueFractionFile = File(mandatory=True, desc='tissue fraction file (32-bit float)', argstr='-f %s') - tissueFractionThreshold = traits.Float(50.0, usedefault=True, desc='tissue fraction threshold (percentage) [default if unspecified: 50]', argstr='-p %f') - computeWGBoundary = traits.Bool(True, usedefault=True, desc='compute WM/GM boundary [default if unspecified: True]', argstr='-w') - computeGCBoundary = traits.Bool(desc='compute GM/CSF boundary', argstr='-g') - includeAllSubcorticalAreas = traits.Bool(True, usedefault=True, esc='include all subcortical areas in WM mask [default if unspecified: True]', argstr='-a') + inputHemisphereLabelFile = File( + mandatory=True, + desc='hemisphere / lobe label volume', + argstr='-h %s') + outputCerebrumMask = File( + mandatory=False, + desc='output structure mask. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + inputTissueFractionFile = File( + mandatory=True, + desc='tissue fraction file (32-bit float)', + argstr='-f %s') + tissueFractionThreshold = traits.Float( + 50.0, + usedefault=True, + desc='tissue fraction threshold (percentage)', + argstr='-p %f') + computeWGBoundary = traits.Bool( + True, + usedefault=True, + desc='compute WM/GM boundary', + argstr='-w') + computeGCBoundary = traits.Bool( + desc='compute GM/CSF boundary', argstr='-g') + includeAllSubcorticalAreas = traits.Bool( + True, + usedefault=True, + esc='include all subcortical areas in WM mask', + argstr='-a') verbosity = traits.Int(desc='verbosity level', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') + class cortexOutputSpec(TraitedSpec): outputCerebrumMask = File(desc='path/name of cerebrum mask') @@ -331,38 +442,49 @@ class cortex(CommandLine): _cmd = 'cortex' def _gen_filename(self, name): - if name=='outputCerebrumMask': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), "___", self._cmd, 'Output_', name, myExtension)) - + if name == 'outputCerebrumMask': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputCerebrumMask): - outputs['outputCerebrumMask'] = (os.getcwd() + '/' + self.inputs.outputCerebrumMask) + outputs['outputCerebrumMask'] = ( + os.getcwd() + '/' + self.inputs.outputCerebrumMask) else: - outputs['outputCerebrumMask'] = self._gen_filename('outputCerebrumMask') - - + outputs['outputCerebrumMask'] = self._gen_filename( + 'outputCerebrumMask') return outputs - - - - - class scrubmaskInputSpec(CommandLineInputSpec): - inputMaskFile = File(mandatory=True, desc='input structure mask file', argstr='-i %s') - outputMaskFile = File(mandatory=False, desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - backgroundFillThreshold = traits.Int(2, usedefault=True, desc='background fill threshold [default if unspecified: 2]', argstr='-b %d') - foregroundTrimThreshold = traits.Int(0, usedefault=True, desc='foreground trim threshold [default if unspecified: 0]', argstr='-f %d') + inputMaskFile = File( + mandatory=True, + desc='input structure mask file', + argstr='-i %s') + outputMaskFile = File( + mandatory=False, + desc='output structure mask file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + backgroundFillThreshold = traits.Int( + 2, + usedefault=True, + desc='background fill threshold', + argstr='-b %d') + foregroundTrimThreshold = traits.Int( + 0, + usedefault=True, + desc='foreground trim threshold', + argstr='-f %d') numberIterations = traits.Int(desc='number of iterations', argstr='-n %d') verbosity = traits.Int(desc='verbosity (0=silent)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') + class scrubmaskOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') @@ -372,38 +494,51 @@ class scrubmask(CommandLine): output_spec = scrubmaskOutputSpec _cmd = 'scrubmask' - def _gen_filename(self, name): - if name=='outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) - + if name == 'outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + outputs['outputMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputMaskFile) else: outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') return outputs - - - - - class tcaInputSpec(CommandLineInputSpec): - inputMaskFile = File(mandatory=True, desc='input mask volume', argstr='-i %s') - outputMaskFile = File(mandatory=False, desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - minCorrectionSize = traits.Int(2500, usedefault=True, desc='maximum correction size [default if unspecified: 2500]', argstr='-m %d') - maxCorrectionSize = traits.Int(desc='minimum correction size', argstr='-n %d') - foregroundDelta = traits.Int(20, usedefault=True, desc='foreground delta [default if unspecified: 20]', argstr='--delta %d') + inputMaskFile = File( + mandatory=True, + desc='input mask volume', + argstr='-i %s') + outputMaskFile = File( + mandatory=False, + desc='output mask volume. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + minCorrectionSize = traits.Int( + 2500, + usedefault=True, + desc='maximum correction size', + argstr='-m %d') + maxCorrectionSize = traits.Int( + desc='minimum correction size', + argstr='-n %d') + foregroundDelta = traits.Int( + 20, + usedefault=True, + desc='foreground delta', + argstr='--delta %d') verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') + class tcaOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') @@ -413,38 +548,39 @@ class tca(CommandLine): output_spec = tcaOutputSpec _cmd = 'tca' - - def _gen_filename(self, name): - if name=='outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) - - + if name == 'outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + outputs['outputMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputMaskFile) else: outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') return outputs - - - - class dewispInputSpec(CommandLineInputSpec): inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') - outputMaskFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + outputMaskFile = File( + mandatory=False, + desc='output file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') sizeThreshold = traits.Int(desc='size threshold', argstr='-t %d') - maximumIterations = traits.Int(desc='maximum number of iterations', argstr='-n %d') + maximumIterations = traits.Int( + desc='maximum number of iterations', + argstr='-n %d') timer = traits.Bool(desc='time processing', argstr='--timer') + class dewispOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') @@ -454,51 +590,91 @@ class dewisp(CommandLine): output_spec = dewispOutputSpec _cmd = 'dewisp' - def _gen_filename(self, name): - if name=='outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) - + if name == 'outputMaskFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + self.inputs.outputMaskFile) + outputs['outputMaskFile'] = ( + os.getcwd() + '/' + self.inputs.outputMaskFile) else: outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') return outputs - - - - - - - class dfsInputSpec(CommandLineInputSpec): - inputVolumeFile = File(mandatory=True, desc='input 3D volume', argstr='-i %s') - outputSurfaceFile = File(mandatory=False, desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - inputShadingVolume = File(desc='shade surface model with data from image volume', argstr='-c %s') - smoothingIterations = traits.Int(10, usedefault=True, desc='number of smoothing iterations [default if unspecified: 10]', argstr='-n %d') - smoothingConstant = traits.Float(0.5, usedefault=True, desc='smoothing constant [default if unspecified: 0.5]', argstr='-a %f') - curvatureWeighting = traits.Float(5.0, usedefault=True, desc='curvature weighting [default if unspecified: 5.0]', argstr='-w %f') + inputVolumeFile = File( + mandatory=True, + desc='input 3D volume', + argstr='-i %s') + outputSurfaceFile = File( + mandatory=False, + desc='output surface mesh file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) + inputShadingVolume = File( + desc='shade surface model with data from image volume', + argstr='-c %s') + smoothingIterations = traits.Int( + 10, + usedefault=True, + desc='number of smoothing iterations', + argstr='-n %d') + smoothingConstant = traits.Float( + 0.5, + usedefault=True, + desc='smoothing constant', + argstr='-a %f') + curvatureWeighting = traits.Float( + 5.0, + usedefault=True, + desc='curvature weighting', + argstr='-w %f') scalingPercentile = traits.Float(desc='scaling percentile', argstr='-f %f') - nonZeroTessellation = traits.Bool(desc='tessellate non-zero voxels', argstr='-nz', xor=('nonZeroTessellation', 'specialTessellation')) - tessellationThreshold = traits.Float(desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%f') - specialTessellation = traits.Enum('greater_than', 'less_than', 'equal_to', desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%s', xor=('nonZeroTessellation', 'specialTessellation'), requires=['tessellationThreshold'], position=-1) - zeroPadFlag = traits.Bool(desc='zero-pad volume (avoids clipping at edges)', argstr='-z') - noNormalsFlag = traits.Bool(desc='do not compute vertex normals', argstr='--nonormals') - postSmoothFlag = traits.Bool(desc='smooth vertices after coloring', argstr='--postsmooth') + nonZeroTessellation = traits.Bool( + desc='tessellate non-zero voxels', + argstr='-nz', + xor=( + 'nonZeroTessellation', + 'specialTessellation')) + tessellationThreshold = traits.Float( + desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', + argstr='%f') + specialTessellation = traits.Enum( + 'greater_than', + 'less_than', + 'equal_to', + desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', + argstr='%s', + xor=( + 'nonZeroTessellation', + 'specialTessellation'), + requires=['tessellationThreshold'], + position=- + 1) + zeroPadFlag = traits.Bool( + desc='zero-pad volume (avoids clipping at edges)', + argstr='-z') + noNormalsFlag = traits.Bool( + desc='do not compute vertex normals', + argstr='--nonormals') + postSmoothFlag = traits.Bool( + desc='smooth vertices after coloring', + argstr='--postsmooth') verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') + class dfsOutputSpec(TraitedSpec): outputSurfaceFile = File(desc='path/name of surface file') + class dfs(CommandLine): input_spec = dfsInputSpec output_spec = dfsOutputSpec @@ -506,51 +682,100 @@ class dfs(CommandLine): def _format_arg(self, name, spec, value): if name == 'tessellationThreshold': - return '' #blank argstr + return '' # blank argstr if name == 'specialTessellation': threshold = self.inputs.tessellationThreshold - return spec.argstr%{"greater_than":''.join(("-gt %f" % threshold)), "less_than":''.join(("-lt %f" % threshold)) , "equal_to":''.join(("-eq %f" % threshold))}[value] + return spec.argstr % {"greater_than": ''.join(("-gt %f" % threshold)), "less_than": ''.join( + ("-lt %f" % threshold)), "equal_to": ''.join(("-eq %f" % threshold))}[value] return super(dfs, self)._format_arg(name, spec, value) - def _gen_filename(self, name): - if name=='outputSurfaceFile': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputSurfaceFile': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), + "___", self._cmd, 'Output_', name, myExtension)) - def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputSurfaceFile): - outputs['outputSurfaceFile'] = (os.getcwd() + '/' + self.inputs.outputSurfaceFile) + outputs['outputSurfaceFile'] = ( + os.getcwd() + '/' + self.inputs.outputSurfaceFile) else: - outputs['outputSurfaceFile'] = self._gen_filename('outputSurfaceFile') + outputs['outputSurfaceFile'] = self._gen_filename( + 'outputSurfaceFile') return outputs - - class pialmeshInputSpec(CommandLineInputSpec): inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') - outputSurfaceFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + outputSurfaceFile = File( + mandatory=False, + desc='output file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') - inputTissueFractionFile = File(mandatory=True, desc='floating point (32) tissue fraction image', argstr='-f %s') - numIterations = traits.Int(100, usedefault=True, desc='number of iterations [default if unspecified: 100]', argstr='-n %d') - searchRadius = traits.Float(1, usedefault=True, desc='search radius [default if unspecified: 1]', argstr='-r %f') - stepSize = traits.Float(0.4, usedefault=True, desc='step size [default if unspecified: 0.4]', argstr='-s %f') - inputMaskFile = File(mandatory=True, desc='restrict growth to mask file region', argstr='-m %s') - maxThickness = traits.Float(20, usedefault=True, desc='maximum allowed tissue thickness [default if unspecified: 20]', argstr='--max %f') - tissueThreshold = traits.Float(1.05, usedefault=True, desc='tissue threshold [default if unspecified: 1.05]', argstr='-t %f') -# output interval is not an output -- it specifies how frequently the output surfaces are generated - outputInterval = traits.Int(10, usedefault=True, desc='output interval [default if unspecified: 10]', argstr='--interval %d') - exportPrefix = traits.Str(desc='prefix for exporting surfaces if interval is set', argstr='--prefix %s') - laplacianSmoothing = traits.Float(0.025, usedefault=True, desc='apply Laplacian smoothing [default if unspecified: 0.025]', argstr='--smooth %f') + inputTissueFractionFile = File( + mandatory=True, + desc='floating point (32) tissue fraction image', + argstr='-f %s') + numIterations = traits.Int( + 100, + usedefault=True, + desc='number of iterations', + argstr='-n %d') + searchRadius = traits.Float( + 1, + usedefault=True, + desc='search radius', + argstr='-r %f') + stepSize = traits.Float( + 0.4, + usedefault=True, + desc='step size', + argstr='-s %f') + inputMaskFile = File( + mandatory=True, + desc='restrict growth to mask file region', + argstr='-m %s') + maxThickness = traits.Float( + 20, + usedefault=True, + desc='maximum allowed tissue thickness', + argstr='--max %f') + tissueThreshold = traits.Float( + 1.05, + usedefault=True, + desc='tissue threshold', + argstr='-t %f') +# output interval is not an output -- it specifies how frequently the +# output surfaces are generated + outputInterval = traits.Int( + 10, + usedefault=True, + desc='output interval', + argstr='--interval %d') + exportPrefix = traits.Str( + desc='prefix for exporting surfaces if interval is set', + argstr='--prefix %s') + laplacianSmoothing = traits.Float( + 0.025, + usedefault=True, + desc='apply Laplacian smoothing', + argstr='--smooth %f') timer = traits.Bool(desc='show timing', argstr='--timer') - recomputNormals = traits.Bool(desc='recompute normals at each iteration', argstr='--norm') - normalSmoother = traits.Float(0.2, usedefault=True, desc='strength of normal smoother. [default if unspecified: 0.2]', argstr='--nc %f') - tangentSmoother = traits.Float(desc='strength of tangential smoother.', argstr='--tc %f') + recomputNormals = traits.Bool( + desc='recompute normals at each iteration', + argstr='--norm') + normalSmoother = traits.Float( + 0.2, + usedefault=True, + desc='strength of normal smoother.', + argstr='--nc %f') + tangentSmoother = traits.Float( + desc='strength of tangential smoother.', + argstr='--tc %f') class pialmeshOutputSpec(TraitedSpec): @@ -562,45 +787,65 @@ class pialmesh(CommandLine): output_spec = pialmeshOutputSpec _cmd = 'pialmesh' - def _gen_filename(self, name): - if name=='outputSurfaceFile': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - - + if name == 'outputSurfaceFile': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputSurfaceFile): - outputs['outputSurfaceFile'] = (os.getcwd() + '/' + self.inputs.outputSurfaceFile) + outputs['outputSurfaceFile'] = ( + os.getcwd() + '/' + self.inputs.outputSurfaceFile) else: - outputs['outputSurfaceFile'] = self._gen_filename('outputSurfaceFile') + outputs['outputSurfaceFile'] = self._gen_filename( + 'outputSurfaceFile') return outputs - - - - - - class skullfinderInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='input file', argstr='-i %s') - inputMaskFile = File(mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') - outputLabelFile = File(mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + inputMaskFile = File( + mandatory=True, + desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', + argstr='-m %s') + outputLabelFile = File( + mandatory=False, + desc='output file. If unspecified, output file name will be auto generated.', + argstr='-o %s', + genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') - lowerThreshold = traits.Int(desc='Lower threshold for segmentation', argstr='-l %d') - upperThreshold = traits.Int(desc='Upper threshold for segmentation', argstr='-u %d') - surfaceFilePrefix = traits.Str(desc='if specified, generate surface files for brain, skull, and scalp', argstr='-s %s') - bgLabelValue = traits.Int(desc='background label value (0-255)', argstr='--bglabel %d') - scalpLabelValue = traits.Int(desc='scalp label value (0-255)', argstr='--scalplabel %d') - skullLabelValue = traits.Int(desc='skull label value (0-255)', argstr='--skulllabel %d') - spaceLabelValue = traits.Int(desc='space label value (0-255)', argstr='--spacelabel %d') - brainLabelValue = traits.Int(desc='brain label value (0-255)', argstr='--brainlabel %d') - performFinalOpening = traits.Bool(desc='perform a final opening operation on the scalp mask', argstr='--finalOpening') + lowerThreshold = traits.Int( + desc='Lower threshold for segmentation', + argstr='-l %d') + upperThreshold = traits.Int( + desc='Upper threshold for segmentation', + argstr='-u %d') + surfaceFilePrefix = traits.Str( + desc='if specified, generate surface files for brain, skull, and scalp', + argstr='-s %s') + bgLabelValue = traits.Int( + desc='background label value (0-255)', + argstr='--bglabel %d') + scalpLabelValue = traits.Int( + desc='scalp label value (0-255)', + argstr='--scalplabel %d') + skullLabelValue = traits.Int( + desc='skull label value (0-255)', + argstr='--skulllabel %d') + spaceLabelValue = traits.Int( + desc='space label value (0-255)', + argstr='--spacelabel %d') + brainLabelValue = traits.Int( + desc='brain label value (0-255)', + argstr='--brainlabel %d') + performFinalOpening = traits.Bool( + desc='perform a final opening operation on the scalp mask', + argstr='--finalOpening') + class skullfinderOutputSpec(TraitedSpec): outputLabelFile = File(desc='path/name of label file') @@ -611,42 +856,60 @@ class skullfinder(CommandLine): output_spec = skullfinderOutputSpec _cmd = 'skullfinder' - def _gen_filename(self, name): - if name=='outputLabelFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - - + if name == 'outputLabelFile': + myExtension = '.nii.gz' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): - outputs = self.output_spec().get() - if isdefined(self.inputs.outputLabelFile): - outputs['outputLabelFile'] = (os.getcwd() + '/' + self.inputs.outputLabelFile) - else: - outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') - - return outputs - - - + outputs = self.output_spec().get() + if isdefined(self.inputs.outputLabelFile): + outputs['outputLabelFile'] = ( + os.getcwd() + '/' + self.inputs.outputLabelFile) + else: + outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') + return outputs class hemisplitInputSpec(CommandLineInputSpec): - inputSurfaceFile = File(mandatory=True, desc='input surface', argstr='-i %s') - inputHemisphereLabelFile = File(mandatory=True, desc='input hemisphere label volume', argstr='-l %s') - outputLeftHemisphere = File(mandatory=False, desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) - outputRightHemisphere = File(mandatory=False, desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) - pialSurfaceFile = File(desc='pial surface file -- must have same geometry as input surface', argstr='-p %s') - outputLeftPialHemisphere = File(mandatory=False, desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) - outputRightPialHemisphere = File(mandatory=False, desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) + inputSurfaceFile = File( + mandatory=True, + desc='input surface', + argstr='-i %s') + inputHemisphereLabelFile = File( + mandatory=True, + desc='input hemisphere label volume', + argstr='-l %s') + outputLeftHemisphere = File( + mandatory=False, + desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', + argstr='--left %s', + genfile=True) + outputRightHemisphere = File( + mandatory=False, + desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', + argstr='--right %s', + genfile=True) + pialSurfaceFile = File( + desc='pial surface file -- must have same geometry as input surface', + argstr='-p %s') + outputLeftPialHemisphere = File( + mandatory=False, + desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', + argstr='-pl %s', + genfile=True) + outputRightPialHemisphere = File( + mandatory=False, + desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', + argstr='-pr %s', + genfile=True) verbosity = traits.Int(desc='verbosity (0 = silent)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') - - + class hemisplitOutputSpec(TraitedSpec): outputLeftHemisphere = File(desc='path/name of left hemisphere') outputRightHemisphere = File(desc='path/name of right hemisphere') @@ -659,53 +922,59 @@ class hemisplit(CommandLine): output_spec = hemisplitOutputSpec _cmd = 'hemisplit' - - def _gen_filename(self, name): - if name=='outputLeftHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name=='outputRightHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name=='outputLeftPialHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name=='outputRightPialHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - + if name == 'outputLeftHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), + "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputRightHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), + "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputLeftPialHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), + "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputRightPialHemisphere': + myExtension = '.dfs' + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), + "___", self._cmd, 'Output_', name, myExtension)) def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.outputLeftHemisphere): - outputs['outputLeftHemisphere'] = (os.getcwd() + '/' + self.inputs.outputLeftHemisphere) + outputs['outputLeftHemisphere'] = (os.getcwd() + '/' + + self.inputs.outputLeftHemisphere) else: - outputs['outputLeftHemisphere'] = self._gen_filename('outputLeftHemisphere') + outputs['outputLeftHemisphere'] = self._gen_filename( + 'outputLeftHemisphere') if isdefined(self.inputs.outputRightHemisphere): - outputs['outputRightHemisphere'] = (os.getcwd() + '/' + self.inputs.outputRightHemisphere) + outputs['outputRightHemisphere'] = (os.getcwd() + '/' + + self.inputs.outputRightHemisphere) else: - outputs['outputRightHemisphere'] = self._gen_filename('outputRightHemisphere') - - + outputs['outputRightHemisphere'] = self._gen_filename( + 'outputRightHemisphere') if isdefined(self.inputs.outputLeftPialHemisphere): - outputs['outputLeftPialHemisphere'] = (os.getcwd() + '/' + self.inputs.outputLeftPialHemisphere) + outputs['outputLeftPialHemisphere'] = ( + os.getcwd() + '/' + self.inputs.outputLeftPialHemisphere) if isdefined(self.inputs.outputRightPialHemisphere): - outputs['outputRightPialHemisphere'] = (os.getcwd() + '/' + self.inputs.outputRightPialHemisphere) + outputs['outputRightPialHemisphere'] = ( + os.getcwd() + '/' + self.inputs.outputRightPialHemisphere) return outputs -#removes directory of a pathway to a file, removes extension, returns file name up to first occurence of three consecutive underscore characters (if any) -#ex: /home/abc/testData___bseOutput_output_file.nii.gz --> testData +# removes directory of a pathway to a file, removes extension, returns file name +# up to first occurence of three consecutive underscore characters (if any) +# ex: /home/abc/testData___bseOutput_output_file.nii.gz --> testData def getFileName(string): - underscoreRegex = regex.compile("[^___]+") + underscoreRegex = regex.compile("[_]{3}") dotRegex = regex.compile("[^.]+") slashRegex = regex.compile("[^/]+") - arr = underscoreRegex.findall(string) - arr2 = dotRegex.findall(arr[0]); + arr = underscoreRegex.split(string) + arr2 = dotRegex.findall(arr[0]) arr3 = slashRegex.findall(arr2[0]) return arr3[len(arr3) - 1] From 2b09a3eb8a4de6b956f7a0985d83e9fca36373a6 Mon Sep 17 00:00:00 2001 From: Jason W Date: Fri, 22 Jan 2016 14:45:33 -0800 Subject: [PATCH 12/25] Update brainsuite.py Added l_outputs function to simplify insantiation of output names/reduce repetition in code --- nipype/interfaces/brainsuite.py | 685 ++++++++++---------------------- 1 file changed, 212 insertions(+), 473 deletions(-) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index 99a6405909..05f2373643 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -49,8 +49,7 @@ class bseInputSpec(CommandLineInputSpec): verbosityLevel = traits.Float(1, usedefault=True, desc=' verbosity level (0=silent)', argstr='-v %f') - noRotate = traits.Bool(True, usedefault=True, - desc='retain original orientation' + noRotate = traits.Bool(desc='retain original orientation' '(default behavior will auto-rotate input NII files' 'to LPI orientation)', argstr='--norotate') timer = traits.Bool(desc='show timing', argstr='--timer') @@ -70,39 +69,23 @@ class bse(CommandLine): output_spec = bseOutputSpec _cmd = 'bse' - def _list_outputs(self): + def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') - outputs = self.output_spec().get() - if isdefined(self.inputs.outputMRIVolume): - outputs['outputMRIVolume'] = (os.getcwd() + '/' + - self.inputs.outputMRIVolume) - else: - outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') - - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = (os.getcwd() + '/' + - self.inputs.outputMaskFile) - if isdefined(self.inputs.outputDiffusionFilter): - outputs['outputDiffusionFilter'] = (os.getcwd() + '/' + - self.inputs.outputDiffusionFilter) - if isdefined(self.inputs.outputEdgeMap): - outputs['outputEdgeMap'] = (os.getcwd() + '/' + - self.inputs.outputEdgeMap) - if isdefined(self.inputs.outputDetailedBrainMask): - outputs['outputDetailedBrainMask'] = (os.getcwd() + '/' + - self.inputs.outputDetailedBrainMask) - if isdefined(self.inputs.outputCortexFile): - outputs['outputCortexFile'] = (os.getcwd() + '/' + - self.inputs.outputCortexFile) - - return outputs + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + + return toReturn - def _gen_filename(self, name): if name == 'outputMRIVolume': myExtension = '.nii.gz' return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + return None + + def _list_outputs(self): + return l_outputs(self) class bfcInputSpec(CommandLineInputSpec): @@ -168,11 +151,9 @@ class bfcInputSpec(CommandLineInputSpec): convergenceThreshold = traits.Float(desc='convergence threshold', argstr='--eps %f') biasEstimateConvergenceThreshold = traits.Float( - desc='bias estimate convergence threshold (values > 0.1 disable)', - argstr='--beps %f') + desc='bias estimate convergence threshold (values > 0.1 disable)', argstr='--beps %f') verbosityLevel = traits.Int( - desc='verbosity level (0=silent)', - argstr='-v %d') + desc='verbosity level (0=silent)', argstr='-v %d') timer = traits.Bool(desc='display timing information', argstr='--timer') @@ -190,67 +171,43 @@ class bfc(CommandLine): _cmd = 'bfc' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputMRIVolume': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + + return None def _format_arg(self, name, spec, value): if name == 'histogramType': - return spec.argstr % { - "ellipse": "--ellipse", "block": "--block"}[value] + return spec.argstr % {"ellipse": "--ellipse", "block": "--block"}[value] if name == 'biasRange': - return spec.argstr % {"low": "--low", - "medium": "--medium", "high": "--high"}[value] + return spec.argstr % {"low": "--low", "medium": "--medium", "high": "--high"}[value] if name == 'intermediate_file_type': - return spec.argstr % {"analyze": "--analyze", "nifti": "--nifti", - "gzippedAnalyze": "--analyzegz", "gzippedNifti": "--niftigz"}[value] + return spec.argstr % {"analyze": "--analyze", "nifti": "--nifti", "gzippedAnalyze": "--analyzegz", "gzippedNifti": "--niftigz"}[value] return super(bfc, self)._format_arg(name, spec, value) def _list_outputs(self): - outputs = self.output_spec().get() - - if isdefined(self.inputs.outputMRIVolume): - outputs['outputMRIVolume'] = ( - os.getcwd() + '/' + self.inputs.outputMRIVolume) - else: - outputs['outputMRIVolume'] = self._gen_filename('outputMRIVolume') - - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputMaskFile) - if isdefined(self.inputs.outputBiasField): - outputs['outputBiasField'] = ( - os.getcwd() + '/' + self.inputs.outputBiasField) - if isdefined(self.inputs.outputMaskedBiasField): - outputs['outputMaskedBiasField'] = ( - os.getcwd() + '/' + self.inputs.outputMaskedBiasField) - if isdefined(self.inputs.correctionScheduleFile): - outputs['correctionScheduleFile'] = ( - os.getcwd() + '/' + self.inputs.correctionScheduleFile) - - return outputs + return l_outputs(self) class pvcInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') inputMaskFile = File(desc='brain mask file', argstr='-m %s') outputLabelFile = File( - mandatory=False, - desc='output label file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) outputTissueFractionFile = File( - mandatory=False, - desc='output tissue fraction file', - argstr='-f %s', - genfile=True) + mandatory=False, desc='output tissue fraction file', argstr='-f %s', genfile=True) spatialPrior = traits.Float(desc='spatial prior strength', argstr='-l %f') verbosity = traits.Int(desc='verbosity level (0 = silent)', argstr='-v %d') threeClassFlag = traits.Bool( - desc='use a three-class (CSF=0,GM=1,WM=2) labeling', - argstr='-3') + desc='use a three-class (CSF=0,GM=1,WM=2) labeling', argstr='-3') timer = traits.Bool(desc='time processing', argstr='--timer') @@ -265,87 +222,56 @@ class pvc(CommandLine): _cmd = 'pvc' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputLabelFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', self._cmd, - 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', self._cmd, 'Output_', name, myExtension)) if name == 'outputTissueFractionFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) - - def _list_outputs(self): + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - outputs = self.output_spec().get() - if isdefined(self.inputs.outputLabelFile): - outputs['outputLabelFile'] = ( - os.getcwd() + '/' + self.inputs.outputLabelFile) - else: - outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') + return None - if isdefined(self.inputs.outputTissueFractionFile): - outputs['outputTissueFractionFile'] = ( - os.getcwd() + '/' + self.inputs.outputTissueFractionFile) - else: - outputs['outputTissueFractionFile'] = self._gen_filename( - 'outputTissueFractionFile') - - return outputs + def _list_outputs(self): + return l_outputs(self) class cerebroInputSpec(CommandLineInputSpec): inputMRIFile = File( - mandatory=True, - desc='input 3D MRI volume', - argstr='-i %s') + mandatory=True, desc='input 3D MRI volume', argstr='-i %s') inputAtlasMRIFile = File( - mandatory=True, - desc='atlas MRI volume', - argstr='--atlas %s') + mandatory=True, desc='atlas MRI volume', argstr='--atlas %s') inputAtlasLabelFile = File( - mandatory=True, - desc='atlas labeling', - argstr='--atlaslabels %s') + mandatory=True, desc='atlas labeling', argstr='--atlaslabels %s') inputBrainMaskFile = File(desc='brain mask file', argstr='-m %s') outputCerebrumMaskFile = File( - mandatory=False, - desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) outputLabelMaskFile = File( - mandatory=False, - desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', - argstr='-l %s', - genfile=True) + mandatory=False, desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', argstr='-l %s', genfile=True) costFunction = traits.Int(2, usedefault=True, desc='0,1,2', argstr='-c %d') useCentroids = traits.Bool( - desc='use centroids of data to initialize position', - argstr='--centroids') + desc='use centroids of data to initialize position', argstr='--centroids') outputAffineTransformFile = File( - desc='save affine transform to file.', - argstr='--air %s') + desc='save affine transform to file.', argstr='--air %s') outputWarpTransformFile = File( - desc='save warp transform to file.', - argstr='--warp %s') + desc='save warp transform to file.', argstr='--warp %s') verbosity = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') linearConvergence = traits.Float( - desc='linear convergence', - argstr='--linconv %f') + desc='linear convergence', argstr='--linconv %f') warpLabel = traits.Int( - desc='warp order (2,3,4,5,6,7,8)', - argstr='--warplevel %d') + desc='warp order (2,3,4,5,6,7,8)', argstr='--warplevel %d') warpConvergence = traits.Float( - desc='warp convergence', - argstr='--warpconv %f') + desc='warp convergence', argstr='--warpconv %f') keepTempFiles = traits.Bool( - desc="don't remove temporary files", - argstr='--keep') + desc="don't remove temporary files", argstr='--keep') tempDirectory = traits.Str( - desc='specify directory to use for temporary files', - argstr='--tempdir %s') + desc='specify directory to use for temporary files', argstr='--tempdir %s') tempDirectoryBase = traits.Str( - desc='create a temporary directory within this directory', - argstr='--tempdirbase %s') + desc='create a temporary directory within this directory', argstr='--tempdirbase %s') class cerebroOutputSpec(TraitedSpec): @@ -361,73 +287,40 @@ class cerebro(CommandLine): _cmd = 'cerebro' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputCerebrumMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) if name == 'outputLabelMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) - - def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputCerebrumMaskFile): - outputs['outputCerebrumMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputCerebrumMaskFile) - else: - outputs['outputCerebrumMaskFile'] = self._gen_filename( - 'outputCerebrumMaskFile') + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - if isdefined(self.inputs.outputLabelMaskFile): - outputs['outputLabelMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputLabelMaskFile) - else: - outputs['outputLabelMaskFile'] = self._gen_filename( - 'outputLabelMaskFile') + return None - if isdefined(self.inputs.outputAffineTransformFile): - outputs['outputAffineTransformFile'] = ( - os.getcwd() + '/' + self.inputs.outputAffineTransformFile) - if isdefined(self.inputs.outputWarpTransformFile): - outputs['outputWarpTransformFile'] = ( - os.getcwd() + '/' + self.inputs.outputWarpTransformFile) - - return outputs + def _list_outputs(self): + return l_outputs(self) class cortexInputSpec(CommandLineInputSpec): inputHemisphereLabelFile = File( - mandatory=True, - desc='hemisphere / lobe label volume', - argstr='-h %s') + mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') outputCerebrumMask = File( - mandatory=False, - desc='output structure mask. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) inputTissueFractionFile = File( - mandatory=True, - desc='tissue fraction file (32-bit float)', - argstr='-f %s') + mandatory=True, desc='tissue fraction file (32-bit float)', argstr='-f %s') tissueFractionThreshold = traits.Float( - 50.0, - usedefault=True, - desc='tissue fraction threshold (percentage)', - argstr='-p %f') + 50.0, usedefault=True, desc='tissue fraction threshold (percentage)', argstr='-p %f') computeWGBoundary = traits.Bool( - True, - usedefault=True, - desc='compute WM/GM boundary', - argstr='-w') + True, usedefault=True, desc='compute WM/GM boundary', argstr='-w') computeGCBoundary = traits.Bool( desc='compute GM/CSF boundary', argstr='-g') includeAllSubcorticalAreas = traits.Bool( - True, - usedefault=True, - esc='include all subcortical areas in WM mask', - argstr='-a') + True, usedefault=True, esc='include all subcortical areas in WM mask', argstr='-a') verbosity = traits.Int(desc='verbosity level', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') @@ -442,44 +335,30 @@ class cortex(CommandLine): _cmd = 'cortex' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputCerebrumMask': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), "___", self._cmd, 'Output_', name, myExtension)) - def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputCerebrumMask): - outputs['outputCerebrumMask'] = ( - os.getcwd() + '/' + self.inputs.outputCerebrumMask) - else: - outputs['outputCerebrumMask'] = self._gen_filename( - 'outputCerebrumMask') + return None - return outputs + def _list_outputs(self): + return l_outputs(self) class scrubmaskInputSpec(CommandLineInputSpec): inputMaskFile = File( - mandatory=True, - desc='input structure mask file', - argstr='-i %s') + mandatory=True, desc='input structure mask file', argstr='-i %s') outputMaskFile = File( - mandatory=False, - desc='output structure mask file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) backgroundFillThreshold = traits.Int( - 2, - usedefault=True, - desc='background fill threshold', - argstr='-b %d') + 2, usedefault=True, desc='background fill threshold', argstr='-b %d') foregroundTrimThreshold = traits.Int( - 0, - usedefault=True, - desc='foreground trim threshold', - argstr='-f %d') + 0, usedefault=True, desc='foreground trim threshold', argstr='-f %d') numberIterations = traits.Int(desc='number of iterations', argstr='-n %d') verbosity = traits.Int(desc='verbosity (0=silent)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') @@ -495,46 +374,31 @@ class scrubmask(CommandLine): _cmd = 'scrubmask' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + return None def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputMaskFile) - else: - outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') - - return outputs + return l_outputs(self) class tcaInputSpec(CommandLineInputSpec): inputMaskFile = File( - mandatory=True, - desc='input mask volume', - argstr='-i %s') + mandatory=True, desc='input mask volume', argstr='-i %s') outputMaskFile = File( - mandatory=False, - desc='output mask volume. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) minCorrectionSize = traits.Int( - 2500, - usedefault=True, - desc='maximum correction size', - argstr='-m %d') + 2500, usedefault=True, desc='maximum correction size', argstr='-m %d') maxCorrectionSize = traits.Int( - desc='minimum correction size', - argstr='-n %d') + desc='minimum correction size', argstr='-n %d') foregroundDelta = traits.Int( - 20, - usedefault=True, - desc='foreground delta', - argstr='--delta %d') + 20, usedefault=True, desc='foreground delta', argstr='--delta %d') verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') @@ -549,35 +413,29 @@ class tca(CommandLine): _cmd = 'tca' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) - def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputMaskFile) - else: - outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') + return None - return outputs + def _list_outputs(self): + return l_outputs(self) class dewispInputSpec(CommandLineInputSpec): inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') outputMaskFile = File( - mandatory=False, - desc='output file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') sizeThreshold = traits.Int(desc='size threshold', argstr='-t %d') maximumIterations = traits.Int( - desc='maximum number of iterations', - argstr='-n %d') + desc='maximum number of iterations', argstr='-n %d') timer = traits.Bool(desc='time processing', argstr='--timer') @@ -591,82 +449,47 @@ class dewisp(CommandLine): _cmd = 'dewisp' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputMaskFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) - def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputMaskFile): - outputs['outputMaskFile'] = ( - os.getcwd() + '/' + self.inputs.outputMaskFile) - else: - outputs['outputMaskFile'] = self._gen_filename('outputMaskFile') + return None - return outputs + def _list_outputs(self): + return l_outputs(self) class dfsInputSpec(CommandLineInputSpec): inputVolumeFile = File( - mandatory=True, - desc='input 3D volume', - argstr='-i %s') + mandatory=True, desc='input 3D volume', argstr='-i %s') outputSurfaceFile = File( - mandatory=False, - desc='output surface mesh file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) inputShadingVolume = File( - desc='shade surface model with data from image volume', - argstr='-c %s') + desc='shade surface model with data from image volume', argstr='-c %s') smoothingIterations = traits.Int( - 10, - usedefault=True, - desc='number of smoothing iterations', - argstr='-n %d') + 10, usedefault=True, desc='number of smoothing iterations', argstr='-n %d') smoothingConstant = traits.Float( - 0.5, - usedefault=True, - desc='smoothing constant', - argstr='-a %f') + 0.5, usedefault=True, desc='smoothing constant', argstr='-a %f') curvatureWeighting = traits.Float( - 5.0, - usedefault=True, - desc='curvature weighting', - argstr='-w %f') + 5.0, usedefault=True, desc='curvature weighting', argstr='-w %f') scalingPercentile = traits.Float(desc='scaling percentile', argstr='-f %f') nonZeroTessellation = traits.Bool( - desc='tessellate non-zero voxels', - argstr='-nz', - xor=( - 'nonZeroTessellation', - 'specialTessellation')) + desc='tessellate non-zero voxels', argstr='-nz', xor=('nonZeroTessellation', 'specialTessellation')) tessellationThreshold = traits.Float( - desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', - argstr='%f') - specialTessellation = traits.Enum( - 'greater_than', - 'less_than', - 'equal_to', - desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', - argstr='%s', - xor=( - 'nonZeroTessellation', - 'specialTessellation'), - requires=['tessellationThreshold'], - position=- - 1) + desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%f') + specialTessellation = traits.Enum('greater_than', 'less_than', 'equal_to', desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%s', xor=( + 'nonZeroTessellation', 'specialTessellation'), requires=['tessellationThreshold'], position=-1) zeroPadFlag = traits.Bool( - desc='zero-pad volume (avoids clipping at edges)', - argstr='-z') + desc='zero-pad volume (avoids clipping at edges)', argstr='-z') noNormalsFlag = traits.Bool( - desc='do not compute vertex normals', - argstr='--nonormals') + desc='do not compute vertex normals', argstr='--nonormals') postSmoothFlag = traits.Bool( - desc='smooth vertices after coloring', - argstr='--postsmooth') + desc='smooth vertices after coloring', argstr='--postsmooth') verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') @@ -685,97 +508,59 @@ def _format_arg(self, name, spec, value): return '' # blank argstr if name == 'specialTessellation': threshold = self.inputs.tessellationThreshold - return spec.argstr % {"greater_than": ''.join(("-gt %f" % threshold)), "less_than": ''.join( - ("-lt %f" % threshold)), "equal_to": ''.join(("-eq %f" % threshold))}[value] + return spec.argstr % {"greater_than": ''.join(("-gt %f" % threshold)), "less_than": ''.join(("-lt %f" % threshold)), "equal_to": ''.join(("-eq %f" % threshold))}[value] return super(dfs, self)._format_arg(name, spec, value) def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputSurfaceFile': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), - "___", self._cmd, 'Output_', name, myExtension)) - - def _list_outputs(self): + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), "___", self._cmd, 'Output_', name, myExtension)) - outputs = self.output_spec().get() - if isdefined(self.inputs.outputSurfaceFile): - outputs['outputSurfaceFile'] = ( - os.getcwd() + '/' + self.inputs.outputSurfaceFile) - else: - outputs['outputSurfaceFile'] = self._gen_filename( - 'outputSurfaceFile') + return None - return outputs + def _list_outputs(self): + return l_outputs(self) class pialmeshInputSpec(CommandLineInputSpec): inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') outputSurfaceFile = File( - mandatory=False, - desc='output file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') inputTissueFractionFile = File( - mandatory=True, - desc='floating point (32) tissue fraction image', - argstr='-f %s') + mandatory=True, desc='floating point (32) tissue fraction image', argstr='-f %s') numIterations = traits.Int( - 100, - usedefault=True, - desc='number of iterations', - argstr='-n %d') + 100, usedefault=True, desc='number of iterations', argstr='-n %d') searchRadius = traits.Float( - 1, - usedefault=True, - desc='search radius', - argstr='-r %f') - stepSize = traits.Float( - 0.4, - usedefault=True, - desc='step size', - argstr='-s %f') + 1, usedefault=True, desc='search radius', argstr='-r %f') + stepSize = traits.Float(0.4, usedefault=True, + desc='step size', argstr='-s %f') inputMaskFile = File( - mandatory=True, - desc='restrict growth to mask file region', - argstr='-m %s') + mandatory=True, desc='restrict growth to mask file region', argstr='-m %s') maxThickness = traits.Float( - 20, - usedefault=True, - desc='maximum allowed tissue thickness', - argstr='--max %f') + 20, usedefault=True, desc='maximum allowed tissue thickness', argstr='--max %f') tissueThreshold = traits.Float( - 1.05, - usedefault=True, - desc='tissue threshold', - argstr='-t %f') + 1.05, usedefault=True, desc='tissue threshold', argstr='-t %f') # output interval is not an output -- it specifies how frequently the # output surfaces are generated outputInterval = traits.Int( - 10, - usedefault=True, - desc='output interval', - argstr='--interval %d') + 10, usedefault=True, desc='output interval', argstr='--interval %d') exportPrefix = traits.Str( - desc='prefix for exporting surfaces if interval is set', - argstr='--prefix %s') + desc='prefix for exporting surfaces if interval is set', argstr='--prefix %s') laplacianSmoothing = traits.Float( - 0.025, - usedefault=True, - desc='apply Laplacian smoothing', - argstr='--smooth %f') + 0.025, usedefault=True, desc='apply Laplacian smoothing', argstr='--smooth %f') timer = traits.Bool(desc='show timing', argstr='--timer') recomputNormals = traits.Bool( - desc='recompute normals at each iteration', - argstr='--norm') + desc='recompute normals at each iteration', argstr='--norm') normalSmoother = traits.Float( - 0.2, - usedefault=True, - desc='strength of normal smoother.', - argstr='--nc %f') + 0.2, usedefault=True, desc='strength of normal smoother.', argstr='--nc %f') tangentSmoother = traits.Float( - desc='strength of tangential smoother.', - argstr='--tc %f') + desc='strength of tangential smoother.', argstr='--tc %f') class pialmeshOutputSpec(TraitedSpec): @@ -788,63 +573,46 @@ class pialmesh(CommandLine): _cmd = 'pialmesh' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputSurfaceFile': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), - "___", self._cmd, 'Output_', name, myExtension)) - - def _list_outputs(self): + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - outputs = self.output_spec().get() - if isdefined(self.inputs.outputSurfaceFile): - outputs['outputSurfaceFile'] = ( - os.getcwd() + '/' + self.inputs.outputSurfaceFile) - else: - outputs['outputSurfaceFile'] = self._gen_filename( - 'outputSurfaceFile') + return None - return outputs + def _list_outputs(self): + return l_outputs(self) class skullfinderInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='input file', argstr='-i %s') inputMaskFile = File( - mandatory=True, - desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', - argstr='-m %s') + mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') outputLabelFile = File( - mandatory=False, - desc='output file. If unspecified, output file name will be auto generated.', - argstr='-o %s', - genfile=True) + mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') lowerThreshold = traits.Int( - desc='Lower threshold for segmentation', - argstr='-l %d') + desc='Lower threshold for segmentation', argstr='-l %d') upperThreshold = traits.Int( - desc='Upper threshold for segmentation', - argstr='-u %d') + desc='Upper threshold for segmentation', argstr='-u %d') surfaceFilePrefix = traits.Str( - desc='if specified, generate surface files for brain, skull, and scalp', - argstr='-s %s') + desc='if specified, generate surface files for brain, skull, and scalp', argstr='-s %s') bgLabelValue = traits.Int( - desc='background label value (0-255)', - argstr='--bglabel %d') + desc='background label value (0-255)', argstr='--bglabel %d') scalpLabelValue = traits.Int( - desc='scalp label value (0-255)', - argstr='--scalplabel %d') + desc='scalp label value (0-255)', argstr='--scalplabel %d') skullLabelValue = traits.Int( - desc='skull label value (0-255)', - argstr='--skulllabel %d') + desc='skull label value (0-255)', argstr='--skulllabel %d') spaceLabelValue = traits.Int( - desc='space label value (0-255)', - argstr='--spacelabel %d') + desc='space label value (0-255)', argstr='--spacelabel %d') brainLabelValue = traits.Int( - desc='brain label value (0-255)', - argstr='--brainlabel %d') + desc='brain label value (0-255)', argstr='--brainlabel %d') performFinalOpening = traits.Bool( - desc='perform a final opening operation on the scalp mask', - argstr='--finalOpening') + desc='perform a final opening operation on the scalp mask', argstr='--finalOpening') class skullfinderOutputSpec(TraitedSpec): @@ -857,55 +625,36 @@ class skullfinder(CommandLine): _cmd = 'skullfinder' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputLabelFile': myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - def _list_outputs(self): + return None - outputs = self.output_spec().get() - if isdefined(self.inputs.outputLabelFile): - outputs['outputLabelFile'] = ( - os.getcwd() + '/' + self.inputs.outputLabelFile) - else: - outputs['outputLabelFile'] = self._gen_filename('outputLabelFile') - - return outputs + def _list_outputs(self): + return l_outputs(self) class hemisplitInputSpec(CommandLineInputSpec): inputSurfaceFile = File( - mandatory=True, - desc='input surface', - argstr='-i %s') + mandatory=True, desc='input surface', argstr='-i %s') inputHemisphereLabelFile = File( - mandatory=True, - desc='input hemisphere label volume', - argstr='-l %s') + mandatory=True, desc='input hemisphere label volume', argstr='-l %s') outputLeftHemisphere = File( - mandatory=False, - desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', - argstr='--left %s', - genfile=True) + mandatory=False, desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) outputRightHemisphere = File( - mandatory=False, - desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', - argstr='--right %s', - genfile=True) + mandatory=False, desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) pialSurfaceFile = File( - desc='pial surface file -- must have same geometry as input surface', - argstr='-p %s') + desc='pial surface file -- must have same geometry as input surface', argstr='-p %s') outputLeftPialHemisphere = File( - mandatory=False, - desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', - argstr='-pl %s', - genfile=True) + mandatory=False, desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) outputRightPialHemisphere = File( - mandatory=False, - desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', - argstr='-pr %s', - genfile=True) + mandatory=False, desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) verbosity = traits.Int(desc='verbosity (0 = silent)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') @@ -923,48 +672,28 @@ class hemisplit(CommandLine): _cmd = 'hemisplit' def _gen_filename(self, name): + exec('is_user_defined = isdefined(self.inputs.' + name + ')') + if is_user_defined: + exec("toReturn = os.path.abspath(self.inputs." + name + ")") + return toReturn + if name == 'outputLeftHemisphere': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) if name == 'outputRightHemisphere': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) if name == 'outputLeftPialHemisphere': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), - "___", self._cmd, 'Output_', name, myExtension)) + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) if name == 'outputRightPialHemisphere': myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), - "___", self._cmd, 'Output_', name, myExtension)) - - def _list_outputs(self): - - outputs = self.output_spec().get() - if isdefined(self.inputs.outputLeftHemisphere): - outputs['outputLeftHemisphere'] = (os.getcwd() + '/' + - self.inputs.outputLeftHemisphere) - else: - outputs['outputLeftHemisphere'] = self._gen_filename( - 'outputLeftHemisphere') - - if isdefined(self.inputs.outputRightHemisphere): - outputs['outputRightHemisphere'] = (os.getcwd() + '/' + - self.inputs.outputRightHemisphere) - else: - outputs['outputRightHemisphere'] = self._gen_filename( - 'outputRightHemisphere') + return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if isdefined(self.inputs.outputLeftPialHemisphere): - outputs['outputLeftPialHemisphere'] = ( - os.getcwd() + '/' + self.inputs.outputLeftPialHemisphere) - if isdefined(self.inputs.outputRightPialHemisphere): - outputs['outputRightPialHemisphere'] = ( - os.getcwd() + '/' + self.inputs.outputRightPialHemisphere) + return None - return outputs + def _list_outputs(self): + return l_outputs(self) # removes directory of a pathway to a file, removes extension, returns file name @@ -978,3 +707,13 @@ def getFileName(string): arr2 = dotRegex.findall(arr[0]) arr3 = slashRegex.findall(arr2[0]) return arr3[len(arr3) - 1] + + +def l_outputs(self): + outputs = self.output_spec().get() + for key in outputs: + name = self._gen_filename(key) + if not name is None: + outputs[key] = name + + return outputs From eee86ffa6edd5cb46ef16d204bdee2c1a17b94f9 Mon Sep 17 00:00:00 2001 From: Jason W Date: Thu, 3 Mar 2016 10:46:15 -0800 Subject: [PATCH 13/25] Update brainsuite.py --- nipype/interfaces/brainsuite.py | 129 ++++++++++++++++---------------- 1 file changed, 64 insertions(+), 65 deletions(-) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index 05f2373643..4728e4e020 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -11,7 +11,7 @@ ) -class bseInputSpec(CommandLineInputSpec): +class BseInputSpec(CommandLineInputSpec): inputMRIFile = File(exists=True, mandatory=True, argstr='-i %s', desc='input MRI volume', position=0) @@ -55,7 +55,7 @@ class bseInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='show timing', argstr='--timer') -class bseOutputSpec(TraitedSpec): +class BseOutputSpec(TraitedSpec): outputMRIVolume = File(desc='path/name of brain-masked MRI volume') outputMaskFile = File(desc='path/name of smooth brain mask') outputDiffusionFilter = File(desc='path/name of diffusion filter output') @@ -64,9 +64,9 @@ class bseOutputSpec(TraitedSpec): outputCortexFile = File(desc='path/name of cortex file') -class bse(CommandLine): - input_spec = bseInputSpec - output_spec = bseOutputSpec +class Bse(CommandLine): + input_spec = BseInputSpec + output_spec = BseOutputSpec _cmd = 'bse' def _gen_filename(self, name): @@ -88,16 +88,16 @@ def _list_outputs(self): return l_outputs(self) -class bfcInputSpec(CommandLineInputSpec): +class BfcInputSpec(CommandLineInputSpec): inputMRIFile = File(exists=True, mandatory=True, desc='input skull-stripped MRI volume', argstr='-i %s', position=0) + inputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) outputMRIVolume = File(mandatory=False, desc='output bias-corrected MRI volume.' 'If unspecified, output file name' 'will be auto generated.', argstr='-o %s', position=1, hash_files=False, genfile=True) - outputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) outputBiasField = File(desc='save bias field estimate', argstr='--bias %s', hash_files=False) outputMaskedBiasField = File(desc='save bias field estimate (masked)', @@ -157,17 +157,16 @@ class bfcInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='display timing information', argstr='--timer') -class bfcOutputSpec(TraitedSpec): +class BfcOutputSpec(TraitedSpec): outputMRIVolume = File(desc='path/name of output file') - outputMaskFile = File(desc='path/name of mask output file') outputBiasField = File(desc='path/name of bias field output file') outputMaskedBiasField = File(desc='path/name of masked bias field output') correctionScheduleFile = File(desc='path/name of schedule file') -class bfc(CommandLine): - input_spec = bfcInputSpec - output_spec = bfcOutputSpec +class Bfc(CommandLine): + input_spec = BfcInputSpec + output_spec = BfcOutputSpec _cmd = 'bfc' def _gen_filename(self, name): @@ -191,13 +190,13 @@ def _format_arg(self, name, spec, value): if name == 'intermediate_file_type': return spec.argstr % {"analyze": "--analyze", "nifti": "--nifti", "gzippedAnalyze": "--analyzegz", "gzippedNifti": "--niftigz"}[value] - return super(bfc, self)._format_arg(name, spec, value) + return super(Bfc, self)._format_arg(name, spec, value) def _list_outputs(self): return l_outputs(self) -class pvcInputSpec(CommandLineInputSpec): +class PvcInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') inputMaskFile = File(desc='brain mask file', argstr='-m %s') outputLabelFile = File( @@ -211,14 +210,14 @@ class pvcInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='time processing', argstr='--timer') -class pvcOutputSpec(TraitedSpec): +class PvcOutputSpec(TraitedSpec): outputLabelFile = File(desc='path/name of label file') outputTissueFractionFile = File(desc='path/name of tissue fraction file') -class pvc(CommandLine): - input_spec = pvcInputSpec - output_spec = pvcOutputSpec +class Pvc(CommandLine): + input_spec = PvcInputSpec + output_spec = PvcOutputSpec _cmd = 'pvc' def _gen_filename(self, name): @@ -240,7 +239,7 @@ def _list_outputs(self): return l_outputs(self) -class cerebroInputSpec(CommandLineInputSpec): +class CerebroInputSpec(CommandLineInputSpec): inputMRIFile = File( mandatory=True, desc='input 3D MRI volume', argstr='-i %s') inputAtlasMRIFile = File( @@ -274,16 +273,16 @@ class cerebroInputSpec(CommandLineInputSpec): desc='create a temporary directory within this directory', argstr='--tempdirbase %s') -class cerebroOutputSpec(TraitedSpec): +class CerebroOutputSpec(TraitedSpec): outputCerebrumMaskFile = File(desc='path/name of cerebrum mask file') outputLabelMaskFile = File(desc='path/name of label mask file') outputAffineTransformFile = File(desc='path/name of affine transform file') outputWarpTransformFile = File(desc='path/name of warp transform file') -class cerebro(CommandLine): - input_spec = cerebroInputSpec - output_spec = cerebroOutputSpec +class Cerebro(CommandLine): + input_spec = CerebroInputSpec + output_spec = CerebroOutputSpec _cmd = 'cerebro' def _gen_filename(self, name): @@ -306,7 +305,7 @@ def _list_outputs(self): return l_outputs(self) -class cortexInputSpec(CommandLineInputSpec): +class CortexInputSpec(CommandLineInputSpec): inputHemisphereLabelFile = File( mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') outputCerebrumMask = File( @@ -325,13 +324,13 @@ class cortexInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='timing function', argstr='--timer') -class cortexOutputSpec(TraitedSpec): +class CortexOutputSpec(TraitedSpec): outputCerebrumMask = File(desc='path/name of cerebrum mask') -class cortex(CommandLine): - input_spec = cortexInputSpec - output_spec = cortexOutputSpec +class Cortex(CommandLine): + input_spec = CortexInputSpec + output_spec = CortexOutputSpec _cmd = 'cortex' def _gen_filename(self, name): @@ -350,7 +349,7 @@ def _list_outputs(self): return l_outputs(self) -class scrubmaskInputSpec(CommandLineInputSpec): +class ScrubmaskInputSpec(CommandLineInputSpec): inputMaskFile = File( mandatory=True, desc='input structure mask file', argstr='-i %s') outputMaskFile = File( @@ -364,13 +363,13 @@ class scrubmaskInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='timing function', argstr='--timer') -class scrubmaskOutputSpec(TraitedSpec): +class ScrubmaskOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') -class scrubmask(CommandLine): - input_spec = scrubmaskInputSpec - output_spec = scrubmaskOutputSpec +class Scrubmask(CommandLine): + input_spec = ScrubmaskInputSpec + output_spec = ScrubmaskOutputSpec _cmd = 'scrubmask' def _gen_filename(self, name): @@ -388,7 +387,7 @@ def _list_outputs(self): return l_outputs(self) -class tcaInputSpec(CommandLineInputSpec): +class TcaInputSpec(CommandLineInputSpec): inputMaskFile = File( mandatory=True, desc='input mask volume', argstr='-i %s') outputMaskFile = File( @@ -403,13 +402,13 @@ class tcaInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='timing function', argstr='--timer') -class tcaOutputSpec(TraitedSpec): +class TcaOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') -class tca(CommandLine): - input_spec = tcaInputSpec - output_spec = tcaOutputSpec +class Tca(CommandLine): + input_spec = TcaInputSpec + output_spec = TcaOutputSpec _cmd = 'tca' def _gen_filename(self, name): @@ -428,7 +427,7 @@ def _list_outputs(self): return l_outputs(self) -class dewispInputSpec(CommandLineInputSpec): +class DewispInputSpec(CommandLineInputSpec): inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') outputMaskFile = File( mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) @@ -439,13 +438,13 @@ class dewispInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='time processing', argstr='--timer') -class dewispOutputSpec(TraitedSpec): +class DewispOutputSpec(TraitedSpec): outputMaskFile = File(desc='path/name of mask file') -class dewisp(CommandLine): - input_spec = dewispInputSpec - output_spec = dewispOutputSpec +class Dewisp(CommandLine): + input_spec = DewispInputSpec + output_spec = DewispOutputSpec _cmd = 'dewisp' def _gen_filename(self, name): @@ -464,7 +463,7 @@ def _list_outputs(self): return l_outputs(self) -class dfsInputSpec(CommandLineInputSpec): +class DfsInputSpec(CommandLineInputSpec): inputVolumeFile = File( mandatory=True, desc='input 3D volume', argstr='-i %s') outputSurfaceFile = File( @@ -494,13 +493,13 @@ class dfsInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='timing function', argstr='--timer') -class dfsOutputSpec(TraitedSpec): +class DfsOutputSpec(TraitedSpec): outputSurfaceFile = File(desc='path/name of surface file') -class dfs(CommandLine): - input_spec = dfsInputSpec - output_spec = dfsOutputSpec +class Dfs(CommandLine): + input_spec = DfsInputSpec + output_spec = DfsOutputSpec _cmd = 'dfs' def _format_arg(self, name, spec, value): @@ -509,7 +508,7 @@ def _format_arg(self, name, spec, value): if name == 'specialTessellation': threshold = self.inputs.tessellationThreshold return spec.argstr % {"greater_than": ''.join(("-gt %f" % threshold)), "less_than": ''.join(("-lt %f" % threshold)), "equal_to": ''.join(("-eq %f" % threshold))}[value] - return super(dfs, self)._format_arg(name, spec, value) + return super(Dfs, self)._format_arg(name, spec, value) def _gen_filename(self, name): exec('is_user_defined = isdefined(self.inputs.' + name + ')') @@ -527,7 +526,7 @@ def _list_outputs(self): return l_outputs(self) -class pialmeshInputSpec(CommandLineInputSpec): +class PialmeshInputSpec(CommandLineInputSpec): inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') outputSurfaceFile = File( mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) @@ -555,7 +554,7 @@ class pialmeshInputSpec(CommandLineInputSpec): laplacianSmoothing = traits.Float( 0.025, usedefault=True, desc='apply Laplacian smoothing', argstr='--smooth %f') timer = traits.Bool(desc='show timing', argstr='--timer') - recomputNormals = traits.Bool( + recomputeNormals = traits.Bool( desc='recompute normals at each iteration', argstr='--norm') normalSmoother = traits.Float( 0.2, usedefault=True, desc='strength of normal smoother.', argstr='--nc %f') @@ -563,13 +562,13 @@ class pialmeshInputSpec(CommandLineInputSpec): desc='strength of tangential smoother.', argstr='--tc %f') -class pialmeshOutputSpec(TraitedSpec): +class PialmeshOutputSpec(TraitedSpec): outputSurfaceFile = File(desc='path/name of surface file') -class pialmesh(CommandLine): - input_spec = pialmeshInputSpec - output_spec = pialmeshOutputSpec +class Pialmesh(CommandLine): + input_spec = PialmeshInputSpec + output_spec = PialmeshOutputSpec _cmd = 'pialmesh' def _gen_filename(self, name): @@ -588,7 +587,7 @@ def _list_outputs(self): return l_outputs(self) -class skullfinderInputSpec(CommandLineInputSpec): +class SkullfinderInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='input file', argstr='-i %s') inputMaskFile = File( mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') @@ -615,13 +614,13 @@ class skullfinderInputSpec(CommandLineInputSpec): desc='perform a final opening operation on the scalp mask', argstr='--finalOpening') -class skullfinderOutputSpec(TraitedSpec): +class SkullfinderOutputSpec(TraitedSpec): outputLabelFile = File(desc='path/name of label file') -class skullfinder(CommandLine): - input_spec = skullfinderInputSpec - output_spec = skullfinderOutputSpec +class Skullfinder(CommandLine): + input_spec = SkullfinderInputSpec + output_spec = SkullfinderOutputSpec _cmd = 'skullfinder' def _gen_filename(self, name): @@ -640,7 +639,7 @@ def _list_outputs(self): return l_outputs(self) -class hemisplitInputSpec(CommandLineInputSpec): +class HemisplitInputSpec(CommandLineInputSpec): inputSurfaceFile = File( mandatory=True, desc='input surface', argstr='-i %s') inputHemisphereLabelFile = File( @@ -659,16 +658,16 @@ class hemisplitInputSpec(CommandLineInputSpec): timer = traits.Bool(desc='timing function', argstr='--timer') -class hemisplitOutputSpec(TraitedSpec): +class HemisplitOutputSpec(TraitedSpec): outputLeftHemisphere = File(desc='path/name of left hemisphere') outputRightHemisphere = File(desc='path/name of right hemisphere') outputLeftPialHemisphere = File(desc='path/name of left pial hemisphere') outputRightPialHemisphere = File(desc='path/name of right pial hemisphere') -class hemisplit(CommandLine): - input_spec = hemisplitInputSpec - output_spec = hemisplitOutputSpec +class Hemisplit(CommandLine): + input_spec = HemisplitInputSpec + output_spec = HemisplitOutputSpec _cmd = 'hemisplit' def _gen_filename(self, name): From 8964e79e9f5f2e2b5ffd263982a902c1315cd148 Mon Sep 17 00:00:00 2001 From: Jason W Date: Fri, 4 Mar 2016 17:24:09 -0800 Subject: [PATCH 14/25] Update brainsuite.py --- nipype/interfaces/brainsuite.py | 177 ++++++++++++-------------------- 1 file changed, 67 insertions(+), 110 deletions(-) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index 4728e4e020..f0f78e8a46 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -70,18 +70,13 @@ class Bse(CommandLine): _cmd = 'bse' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputMRIVolume': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', - getFileName(self.inputs.inputMRIFile), - "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') + return None def _list_outputs(self): @@ -170,15 +165,12 @@ class Bfc(CommandLine): _cmd = 'bfc' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputMRIVolume': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') return None @@ -221,17 +213,12 @@ class Pvc(CommandLine): _cmd = 'pvc' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) - if name == 'outputLabelFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', self._cmd, 'Output_', name, myExtension)) - if name == 'outputTissueFractionFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputLabelFile' or name == 'outputTissueFractionFile': + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') return None @@ -286,18 +273,12 @@ class Cerebro(CommandLine): _cmd = 'cerebro' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) - if name == 'outputCerebrumMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) - if name == 'outputLabelMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + if name == 'outputCerebrumMaskFile' or name == 'outputLabelMaskFile': + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') return None @@ -334,15 +315,12 @@ class Cortex(CommandLine): _cmd = 'cortex' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputCerebrumMask': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputHemisphereLabelFile), "___", self._cmd, 'Output_', name, myExtension)) - + return getFileName(self, self.inputs.inputHemisphereLabelFile, name, '.nii.gz') return None def _list_outputs(self): @@ -373,14 +351,14 @@ class Scrubmask(CommandLine): _cmd = 'scrubmask' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') + + return None def _list_outputs(self): @@ -412,14 +390,12 @@ class Tca(CommandLine): _cmd = 'tca' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') return None @@ -448,14 +424,12 @@ class Dewisp(CommandLine): _cmd = 'dewisp' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputMaskFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMaskFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') return None @@ -511,14 +485,12 @@ def _format_arg(self, name, spec, value): return super(Dfs, self)._format_arg(name, spec, value) def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputSurfaceFile': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputVolumeFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputVolumeFile, name, '.dfs') return None @@ -572,14 +544,12 @@ class Pialmesh(CommandLine): _cmd = 'pialmesh' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputSurfaceFile': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputSurfaceFile, name, '.dfs') return None @@ -624,14 +594,12 @@ class Skullfinder(CommandLine): _cmd = 'skullfinder' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) if name == 'outputLabelFile': - myExtension = '.nii.gz' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputMRIFile), "___", self._cmd, 'Output_', name, myExtension)) + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') return None @@ -671,42 +639,31 @@ class Hemisplit(CommandLine): _cmd = 'hemisplit' def _gen_filename(self, name): - exec('is_user_defined = isdefined(self.inputs.' + name + ')') - if is_user_defined: - exec("toReturn = os.path.abspath(self.inputs." + name + ")") - return toReturn - - if name == 'outputLeftHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name == 'outputRightHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name == 'outputLeftPialHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) - if name == 'outputRightPialHemisphere': - myExtension = '.dfs' - return ''.join((os.getcwd(), '/', getFileName(self.inputs.inputSurfaceFile), "___", self._cmd, 'Output_', name, myExtension)) + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + + if (name == 'outputLeftHemisphere' + or name == 'outputRightHemisphere' + or name == 'outputLeftPialHemisphere' + or name == 'outputRightPialHemisphere'): + return getFileName(self, self.inputs.inputSurfaceFile, name, '.dfs') return None def _list_outputs(self): return l_outputs(self) - -# removes directory of a pathway to a file, removes extension, returns file name -# up to first occurence of three consecutive underscore characters (if any) -# ex: /home/abc/testData___bseOutput_output_file.nii.gz --> testData -def getFileName(string): - underscoreRegex = regex.compile("[_]{3}") +# used to generate file names for outputs +# removes pathway and extension of inputName, returns concatenation of] +# inputName, command, name, and extension +def getFileName(self, inputName, name, extension): + fullInput = os.path.basename(inputName) dotRegex = regex.compile("[^.]+") - slashRegex = regex.compile("[^/]+") - arr = underscoreRegex.split(string) - arr2 = dotRegex.findall(arr[0]) - arr3 = slashRegex.findall(arr2[0]) - return arr3[len(arr3) - 1] - + inputNoExtension = dotRegex.findall(fullInput)[0] + return os.path.abspath( + ''.join((inputNoExtension, '_', self._cmd, '_', name, extension))) def l_outputs(self): outputs = self.output_spec().get() From 88842540086e0447ea3ccaeec8921d5869ce5be2 Mon Sep 17 00:00:00 2001 From: Jason W Date: Fri, 4 Mar 2016 21:12:10 -0800 Subject: [PATCH 15/25] Update brainsuite.py --- nipype/interfaces/brainsuite.py | 58 +++++++++++++++------------------ 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index f0f78e8a46..192e4e6b8c 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -13,14 +13,12 @@ class BseInputSpec(CommandLineInputSpec): - inputMRIFile = File(exists=True, mandatory=True, argstr='-i %s', - desc='input MRI volume', position=0) - outputMRIVolume = File(mandatory=False, - desc='output brain-masked MRI volume. If' + inputMRIFile = File(mandatory=True, argstr='-i %s', + desc='input MRI volume') + outputMRIVolume = File(desc='output brain-masked MRI volume. If' 'unspecified, output file name will be auto' 'generated.', - argstr='-o %s', position=1, hash_files=False, - genfile=True) + argstr='-o %s', hash_files=False, genfile=True) diffusionConstant = traits.Float(25, usedefault=True, desc='diffusion constant', argstr='-d %f') diffusionIterations = traits.Int(3, usedefault=True, @@ -36,7 +34,7 @@ class BseInputSpec(CommandLineInputSpec): desc='dilate final mask', argstr='-p') trim = traits.Bool(True, usedefault=True, desc='trim brainstem', argstr='--trim') - outputMaskFile = File(mandatory=False, desc='save smooth brain mask', + outputMaskFile = File(desc='save smooth brain mask', argstr='--mask %s', hash_files=False) outputDiffusionFilter = File(desc='diffusion filter output', argstr='--adf %s', hash_files=False) @@ -84,15 +82,13 @@ def _list_outputs(self): class BfcInputSpec(CommandLineInputSpec): - inputMRIFile = File(exists=True, mandatory=True, - desc='input skull-stripped MRI volume', - argstr='-i %s', position=0) + inputMRIFile = File(mandatory=True, + desc='input skull-stripped MRI volume', argstr='-i %s') inputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) - outputMRIVolume = File(mandatory=False, - desc='output bias-corrected MRI volume.' + outputMRIVolume = File(desc='output bias-corrected MRI volume.' 'If unspecified, output file name' 'will be auto generated.', argstr='-o %s', - position=1, hash_files=False, genfile=True) + hash_files=False, genfile=True) outputBiasField = File(desc='save bias field estimate', argstr='--bias %s', hash_files=False) outputMaskedBiasField = File(desc='save bias field estimate (masked)', @@ -191,10 +187,8 @@ def _list_outputs(self): class PvcInputSpec(CommandLineInputSpec): inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') inputMaskFile = File(desc='brain mask file', argstr='-m %s') - outputLabelFile = File( - mandatory=False, desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - outputTissueFractionFile = File( - mandatory=False, desc='output tissue fraction file', argstr='-f %s', genfile=True) + outputLabelFile = File(desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + outputTissueFractionFile = File(desc='output tissue fraction file', argstr='-f %s', genfile=True) spatialPrior = traits.Float(desc='spatial prior strength', argstr='-l %f') verbosity = traits.Int(desc='verbosity level (0 = silent)', argstr='-v %d') threeClassFlag = traits.Bool( @@ -234,10 +228,10 @@ class CerebroInputSpec(CommandLineInputSpec): inputAtlasLabelFile = File( mandatory=True, desc='atlas labeling', argstr='--atlaslabels %s') inputBrainMaskFile = File(desc='brain mask file', argstr='-m %s') - outputCerebrumMaskFile = File( - mandatory=False, desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - outputLabelMaskFile = File( - mandatory=False, desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', argstr='-l %s', genfile=True) + outputCerebrumMaskFile = File(desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', + argstr='-o %s', genfile=True) + outputLabelMaskFile = File(desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', + argstr='-l %s', genfile=True) costFunction = traits.Int(2, usedefault=True, desc='0,1,2', argstr='-c %d') useCentroids = traits.Bool( desc='use centroids of data to initialize position', argstr='--centroids') @@ -290,7 +284,7 @@ class CortexInputSpec(CommandLineInputSpec): inputHemisphereLabelFile = File( mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') outputCerebrumMask = File( - mandatory=False, desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) inputTissueFractionFile = File( mandatory=True, desc='tissue fraction file (32-bit float)', argstr='-f %s') tissueFractionThreshold = traits.Float( @@ -331,7 +325,7 @@ class ScrubmaskInputSpec(CommandLineInputSpec): inputMaskFile = File( mandatory=True, desc='input structure mask file', argstr='-i %s') outputMaskFile = File( - mandatory=False, desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) backgroundFillThreshold = traits.Int( 2, usedefault=True, desc='background fill threshold', argstr='-b %d') foregroundTrimThreshold = traits.Int( @@ -369,7 +363,7 @@ class TcaInputSpec(CommandLineInputSpec): inputMaskFile = File( mandatory=True, desc='input mask volume', argstr='-i %s') outputMaskFile = File( - mandatory=False, desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) minCorrectionSize = traits.Int( 2500, usedefault=True, desc='maximum correction size', argstr='-m %d') maxCorrectionSize = traits.Int( @@ -406,7 +400,7 @@ def _list_outputs(self): class DewispInputSpec(CommandLineInputSpec): inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') outputMaskFile = File( - mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') sizeThreshold = traits.Int(desc='size threshold', argstr='-t %d') maximumIterations = traits.Int( @@ -441,7 +435,7 @@ class DfsInputSpec(CommandLineInputSpec): inputVolumeFile = File( mandatory=True, desc='input 3D volume', argstr='-i %s') outputSurfaceFile = File( - mandatory=False, desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) inputShadingVolume = File( desc='shade surface model with data from image volume', argstr='-c %s') smoothingIterations = traits.Int( @@ -501,7 +495,7 @@ def _list_outputs(self): class PialmeshInputSpec(CommandLineInputSpec): inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') outputSurfaceFile = File( - mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') inputTissueFractionFile = File( mandatory=True, desc='floating point (32) tissue fraction image', argstr='-f %s') @@ -562,7 +556,7 @@ class SkullfinderInputSpec(CommandLineInputSpec): inputMaskFile = File( mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') outputLabelFile = File( - mandatory=False, desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) verbosity = traits.Int(desc='verbosity', argstr='-v %d') lowerThreshold = traits.Int( desc='Lower threshold for segmentation', argstr='-l %d') @@ -613,15 +607,15 @@ class HemisplitInputSpec(CommandLineInputSpec): inputHemisphereLabelFile = File( mandatory=True, desc='input hemisphere label volume', argstr='-l %s') outputLeftHemisphere = File( - mandatory=False, desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) + desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) outputRightHemisphere = File( - mandatory=False, desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) + desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) pialSurfaceFile = File( desc='pial surface file -- must have same geometry as input surface', argstr='-p %s') outputLeftPialHemisphere = File( - mandatory=False, desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) + desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) outputRightPialHemisphere = File( - mandatory=False, desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) + desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) verbosity = traits.Int(desc='verbosity (0 = silent)', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') From 29057c8819144d03e56630851c3d8916c5208865 Mon Sep 17 00:00:00 2001 From: Jason W Date: Wed, 9 Mar 2016 15:34:22 -0800 Subject: [PATCH 16/25] Update brainsuite.py Added description and doctests --- nipype/interfaces/brainsuite.py | 219 ++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py index 192e4e6b8c..d49b8147a1 100644 --- a/nipype/interfaces/brainsuite.py +++ b/nipype/interfaces/brainsuite.py @@ -63,6 +63,23 @@ class BseOutputSpec(TraitedSpec): class Bse(CommandLine): + """ + brain surface extractor (BSE) + This program performs automated skull and scalp removal on T1-weighted MRI volumes. + + http://brainsuite.org/processing/surfaceextraction/bse/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> bse = brainsuite.Bse() + >>> bse.inputs.inputMRIFile = example_data('structural.nii') + >>> results = bse.run() #doctest: +SKIP + + """ + input_spec = BseInputSpec output_spec = BseOutputSpec _cmd = 'bse' @@ -156,6 +173,25 @@ class BfcOutputSpec(TraitedSpec): class Bfc(CommandLine): + """ + bias field corrector (BFC) + This program corrects gain variation in T1-weighted MRI. + + http://brainsuite.org/processing/surfaceextraction/bfc/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> bfc = brainsuite.Bfc() + >>> bfc.inputs.inputMRIFile = example_data('structural.nii') + >>> bfc.inputs.inputMaskFile = example_data('mask.nii') + >>> results = bfc.run() #doctest: +SKIP + + """ + + input_spec = BfcInputSpec output_spec = BfcOutputSpec _cmd = 'bfc' @@ -202,6 +238,25 @@ class PvcOutputSpec(TraitedSpec): class Pvc(CommandLine): + """ + partial volume classifier (PVC) tool. + This program performs voxel-wise tissue classification T1-weighted MRI. + Image should be skull-stripped and bias-corrected before tissue classification. + + http://brainsuite.org/processing/surfaceextraction/pvc/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> pvc = brainsuite.Pvc() + >>> pvc.inputs.inputMRIFile = example_data('structural.nii') + >>> pvc.inputs.inputMaskFile = example_data('mask.nii') + >>> results = pvc.run() #doctest: +SKIP + + """ + input_spec = PvcInputSpec output_spec = PvcOutputSpec _cmd = 'pvc' @@ -262,6 +317,28 @@ class CerebroOutputSpec(TraitedSpec): class Cerebro(CommandLine): + """ + Cerebrum/cerebellum labeling tool + This program performs automated labeling of cerebellum and cerebrum in T1 MRI. + Input MRI should be skull-stripped or a brain-only mask should be provided. + + + http://brainsuite.org/processing/surfaceextraction/cerebrum/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> cerebro = brainsuite.Cerebro() + >>> cerebro.inputs.inputMRIFile = example_data('structural.nii') + >>> cerebro.inputs.inputAtlasMRIFile = 'atlasMRIVolume.img' + >>> cerebro.inputs.inputAtlasLabelFile = 'atlasLabels.img' + >>> cerebro.inputs.inputBrainMaskFile = example_data('mask.nii') + >>> results = cerebro.run() #doctest: +SKIP + + """ + input_spec = CerebroInputSpec output_spec = CerebroOutputSpec _cmd = 'cerebro' @@ -304,6 +381,25 @@ class CortexOutputSpec(TraitedSpec): class Cortex(CommandLine): + """ + cortex extractor + This program produces a cortical mask using tissue fraction estimates + and a co-registered cerebellum/hemisphere mask. + + http://brainsuite.org/processing/surfaceextraction/cortex/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> cortex = brainsuite.Cortex() + >>> cortex.inputs.inputHemisphereLabelFile = example_data('mask.nii') + >>> cortex.inputs.inputTissueFractionFile = example_data('tissues.nii.gz') + >>> results = cortex.run() #doctest: +SKIP + + """ + input_spec = CortexInputSpec output_spec = CortexOutputSpec _cmd = 'cortex' @@ -340,6 +436,23 @@ class ScrubmaskOutputSpec(TraitedSpec): class Scrubmask(CommandLine): + """ + ScrubMask tool + scrubmask filters binary masks to trim loosely connected voxels that may + result from segmentation errors and produce bumps on tessellated surfaces. + + http://brainsuite.org/processing/surfaceextraction/scrubmask/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> scrubmask = brainsuite.Scrubmask() + >>> scrubmask.inputs.inputMaskFile = example_data('mask.nii') + >>> results = scrubmask.run() #doctest: +SKIP + + """ input_spec = ScrubmaskInputSpec output_spec = ScrubmaskOutputSpec _cmd = 'scrubmask' @@ -379,6 +492,21 @@ class TcaOutputSpec(TraitedSpec): class Tca(CommandLine): + """ + topological correction algorithm (TCA) + This program removes topological handles from a binary object. + + http://brainsuite.org/processing/surfaceextraction/tca/ + + Examples + -------- + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> tca = brainsuite.Tca() + >>> tca.inputs.inputMaskFile = example_data('mask.nii') + >>> results = tca.run() #doctest: +SKIP + + """ input_spec = TcaInputSpec output_spec = TcaOutputSpec _cmd = 'tca' @@ -413,6 +541,28 @@ class DewispOutputSpec(TraitedSpec): class Dewisp(CommandLine): + """ + dewisp + removes wispy tendril structures from cortex model binary masks. + It does so based on graph theoretic analysis of connected components, + similar to TCA. Each branch of the structure graph is analyzed to determine + pinch points that indicate a likely error in segmentation that attaches noise + to the image. The pinch threshold determines how many voxels the cross-section + can be before it is considered part of the image. + + http://brainsuite.org/processing/surfaceextraction/dewisp/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> dewisp = brainsuite.Dewisp() + >>> dewisp.inputs.inputMaskFile = example_data('mask.nii') + >>> results = dewisp.run() #doctest: +SKIP + + """ + input_spec = DewispInputSpec output_spec = DewispOutputSpec _cmd = 'dewisp' @@ -466,6 +616,23 @@ class DfsOutputSpec(TraitedSpec): class Dfs(CommandLine): + """ + Surface Generator + Generates mesh surfaces using an isosurface algorithm. + + http://brainsuite.org/processing/surfaceextraction/inner-cortical-surface/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> dfs = brainsuite.Dfs() + >>> dfs.inputs.inputVolumeFile = example_data('structural.nii') + >>> results = dfs.run() #doctest: +SKIP + + """ + input_spec = DfsInputSpec output_spec = DfsOutputSpec _cmd = 'dfs' @@ -533,6 +700,25 @@ class PialmeshOutputSpec(TraitedSpec): class Pialmesh(CommandLine): + """ + pialmesh + computes a pial surface model using an inner WM/GM mesh and a tissue fraction map. + + http://brainsuite.org/processing/surfaceextraction/pial/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> pialmesh = brainsuite.Pialmesh() + >>> pialmesh.inputs.inputSurfaceFile = 'input_mesh.dfs' + >>> pialmesh.inputs.inputTissueFractionFile = 'frac_file.nii.gz' + >>> pialmesh.inputs.inputMaskFile = example_data('mask.nii') + >>> results = pialmesh.run() #doctest: +SKIP + + """ + input_spec = PialmeshInputSpec output_spec = PialmeshOutputSpec _cmd = 'pialmesh' @@ -583,6 +769,20 @@ class SkullfinderOutputSpec(TraitedSpec): class Skullfinder(CommandLine): + """ + Skull and scalp segmentation algorithm. + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> skullfinder = brainsuite.Skullfinder() + >>> skullfinder.inputs.inputMRIFile = example_data('structural.nii') + >>> skullfinder.inputs.inputMaskFile = example_data('mask.nii') + >>> results = skullfinder.run() #doctest: +SKIP + + """ input_spec = SkullfinderInputSpec output_spec = SkullfinderOutputSpec _cmd = 'skullfinder' @@ -628,6 +828,25 @@ class HemisplitOutputSpec(TraitedSpec): class Hemisplit(CommandLine): + """ + Hemisphere splitter + Splits a surface object into two separate surfaces given an input label volume. + Each vertex is labeled left or right based on the labels being odd (left) or even (right). + The largest contour on the split surface is then found and used as the separation between left and right. + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> hemisplit = brainsuite.Hemisplit() + >>> hemisplit.inputs.inputSurfaceFile = 'input_surf.dfs' + >>> hemisplit.inputs.inputHemisphereLabelFile = 'label.nii' + >>> hemisplit.inputs.pialSurfaceFile = 'pial.dfs' + >>> results = hemisplit.run() #doctest: +SKIP + + """ + input_spec = HemisplitInputSpec output_spec = HemisplitOutputSpec _cmd = 'hemisplit' From 48f19f0988faaae5522487c4be2fd0084f8c3ff3 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 20 Mar 2016 21:55:12 -0700 Subject: [PATCH 17/25] move to own folder --- nipype/interfaces/brainsuite/brainsuite.py | 888 +++++++++++++++++++++ 1 file changed, 888 insertions(+) create mode 100644 nipype/interfaces/brainsuite/brainsuite.py diff --git a/nipype/interfaces/brainsuite/brainsuite.py b/nipype/interfaces/brainsuite/brainsuite.py new file mode 100644 index 0000000000..d49b8147a1 --- /dev/null +++ b/nipype/interfaces/brainsuite/brainsuite.py @@ -0,0 +1,888 @@ +import os +import re as regex + +from nipype.interfaces.base import( + TraitedSpec, + CommandLineInputSpec, + CommandLine, + File, + traits, + isdefined, +) + + +class BseInputSpec(CommandLineInputSpec): + + inputMRIFile = File(mandatory=True, argstr='-i %s', + desc='input MRI volume') + outputMRIVolume = File(desc='output brain-masked MRI volume. If' + 'unspecified, output file name will be auto' + 'generated.', + argstr='-o %s', hash_files=False, genfile=True) + diffusionConstant = traits.Float(25, usedefault=True, + desc='diffusion constant', argstr='-d %f') + diffusionIterations = traits.Int(3, usedefault=True, + desc='diffusion iterations', + argstr='-n %d') + edgeDetectionConstant = traits.Float(0.64, usedefault=True, + desc='edge detection constant', + argstr='-s %f') + radius = traits.Float(1, usedefault=True, + desc='radius of erosion/dilation filter', + argstr='-r %f') + dilateFinalMask = traits.Bool(True, usedefault=True, + desc='dilate final mask', argstr='-p') + trim = traits.Bool(True, usedefault=True, desc='trim brainstem', + argstr='--trim') + outputMaskFile = File(desc='save smooth brain mask', + argstr='--mask %s', hash_files=False) + outputDiffusionFilter = File(desc='diffusion filter output', + argstr='--adf %s', hash_files=False) + outputEdgeMap = File(desc='edge map output', argstr='--edge %s', + hash_files=False) + outputDetailedBrainMask = File(desc='save detailed brain mask', + argstr='--hires %s', hash_files=False) + outputCortexFile = File(desc='cortex file', argstr='--cortex %s', + hash_files=False) + verbosityLevel = traits.Float(1, usedefault=True, + desc=' verbosity level (0=silent)', + argstr='-v %f') + noRotate = traits.Bool(desc='retain original orientation' + '(default behavior will auto-rotate input NII files' + 'to LPI orientation)', argstr='--norotate') + timer = traits.Bool(desc='show timing', argstr='--timer') + + +class BseOutputSpec(TraitedSpec): + outputMRIVolume = File(desc='path/name of brain-masked MRI volume') + outputMaskFile = File(desc='path/name of smooth brain mask') + outputDiffusionFilter = File(desc='path/name of diffusion filter output') + outputEdgeMap = File(desc='path/name of edge map output') + outputDetailedBrainMask = File(desc='path/name of detailed brain mask') + outputCortexFile = File(desc='path/name of cortex file') + + +class Bse(CommandLine): + """ + brain surface extractor (BSE) + This program performs automated skull and scalp removal on T1-weighted MRI volumes. + + http://brainsuite.org/processing/surfaceextraction/bse/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> bse = brainsuite.Bse() + >>> bse.inputs.inputMRIFile = example_data('structural.nii') + >>> results = bse.run() #doctest: +SKIP + + """ + + input_spec = BseInputSpec + output_spec = BseOutputSpec + _cmd = 'bse' + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + if name == 'outputMRIVolume': + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') + + return None + + def _list_outputs(self): + return l_outputs(self) + + +class BfcInputSpec(CommandLineInputSpec): + inputMRIFile = File(mandatory=True, + desc='input skull-stripped MRI volume', argstr='-i %s') + inputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) + outputMRIVolume = File(desc='output bias-corrected MRI volume.' + 'If unspecified, output file name' + 'will be auto generated.', argstr='-o %s', + hash_files=False, genfile=True) + outputBiasField = File(desc='save bias field estimate', + argstr='--bias %s', hash_files=False) + outputMaskedBiasField = File(desc='save bias field estimate (masked)', + argstr='--maskedbias %s', hash_files=False) + histogramRadius = traits.Int(desc='histogram radius (voxels)', + argstr='-r %d') + biasEstimateSpacing = traits.Int(desc='bias sample spacing (voxels)', + argstr='-s %d') + controlPointSpacing = traits.Int(desc='control point spacing (voxels)', + argstr='-c %d') + splineLambda = traits.Float(desc='spline stiffness weighting parameter', + argstr='-w %f') + histogramType = traits.Enum('ellipse', 'block', + desc='Options for type of histogram\nellipse:' + 'use ellipsoid for ROI histogram\nblock' + ':use block for ROI histogram', + argstr='%s') + iterativeMode = traits.Bool(desc='iterative mode (overrides -r, -s, -c,' + '-w settings)', + argstr='--iterate') + correctionScheduleFile = File(desc='list of parameters ', + argstr='--schedule %s') + biasFieldEstimatesOutputPrefix = traits.Str(desc='save iterative bias' + 'field estimates as' + '.n.field.nii.gz', + argstr='--biasprefix %s') + correctedImagesOutputPrefix = traits.Str(desc='save iterative corrected' + 'images as' + '.n.bfc.nii.gz', + argstr='--prefix %s') + correctWholeVolume = traits.Bool(desc='apply correction field to entire' + 'volume', argstr='--extrapolate') + minBias = traits.Float(0.5, usedefault=True, desc='minimum allowed bias' + 'value', + argstr='-L %f') + maxBias = traits.Float(1.5, usedefault=True, desc='maximum allowed bias' '' + 'value', + argstr='-U %f') + biasRange = traits.Enum("low", "medium", "high", + desc='Preset options for bias_model\n' + 'low: small bias model [0.95,1.05]\n' + 'medium: medium bias model [0.90,1.10]\n' + 'high: high bias model [0.80,1.20]', + argstr='%s') + intermediate_file_type = traits.Enum("analyze", "nifti", + "gzippedAnalyze", "gzippedNifti", + desc='Options for the format in' + 'which intermediate files are' "" + 'generated', + argstr='%s') + convergenceThreshold = traits.Float(desc='convergence threshold', + argstr='--eps %f') + biasEstimateConvergenceThreshold = traits.Float( + desc='bias estimate convergence threshold (values > 0.1 disable)', argstr='--beps %f') + verbosityLevel = traits.Int( + desc='verbosity level (0=silent)', argstr='-v %d') + timer = traits.Bool(desc='display timing information', argstr='--timer') + + +class BfcOutputSpec(TraitedSpec): + outputMRIVolume = File(desc='path/name of output file') + outputBiasField = File(desc='path/name of bias field output file') + outputMaskedBiasField = File(desc='path/name of masked bias field output') + correctionScheduleFile = File(desc='path/name of schedule file') + + +class Bfc(CommandLine): + """ + bias field corrector (BFC) + This program corrects gain variation in T1-weighted MRI. + + http://brainsuite.org/processing/surfaceextraction/bfc/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> bfc = brainsuite.Bfc() + >>> bfc.inputs.inputMRIFile = example_data('structural.nii') + >>> bfc.inputs.inputMaskFile = example_data('mask.nii') + >>> results = bfc.run() #doctest: +SKIP + + """ + + + input_spec = BfcInputSpec + output_spec = BfcOutputSpec + _cmd = 'bfc' + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + if name == 'outputMRIVolume': + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') + + return None + + def _format_arg(self, name, spec, value): + if name == 'histogramType': + return spec.argstr % {"ellipse": "--ellipse", "block": "--block"}[value] + if name == 'biasRange': + return spec.argstr % {"low": "--low", "medium": "--medium", "high": "--high"}[value] + if name == 'intermediate_file_type': + return spec.argstr % {"analyze": "--analyze", "nifti": "--nifti", "gzippedAnalyze": "--analyzegz", "gzippedNifti": "--niftigz"}[value] + + return super(Bfc, self)._format_arg(name, spec, value) + + def _list_outputs(self): + return l_outputs(self) + + +class PvcInputSpec(CommandLineInputSpec): + inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') + inputMaskFile = File(desc='brain mask file', argstr='-m %s') + outputLabelFile = File(desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + outputTissueFractionFile = File(desc='output tissue fraction file', argstr='-f %s', genfile=True) + spatialPrior = traits.Float(desc='spatial prior strength', argstr='-l %f') + verbosity = traits.Int(desc='verbosity level (0 = silent)', argstr='-v %d') + threeClassFlag = traits.Bool( + desc='use a three-class (CSF=0,GM=1,WM=2) labeling', argstr='-3') + timer = traits.Bool(desc='time processing', argstr='--timer') + + +class PvcOutputSpec(TraitedSpec): + outputLabelFile = File(desc='path/name of label file') + outputTissueFractionFile = File(desc='path/name of tissue fraction file') + + +class Pvc(CommandLine): + """ + partial volume classifier (PVC) tool. + This program performs voxel-wise tissue classification T1-weighted MRI. + Image should be skull-stripped and bias-corrected before tissue classification. + + http://brainsuite.org/processing/surfaceextraction/pvc/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> pvc = brainsuite.Pvc() + >>> pvc.inputs.inputMRIFile = example_data('structural.nii') + >>> pvc.inputs.inputMaskFile = example_data('mask.nii') + >>> results = pvc.run() #doctest: +SKIP + + """ + + input_spec = PvcInputSpec + output_spec = PvcOutputSpec + _cmd = 'pvc' + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + if name == 'outputLabelFile' or name == 'outputTissueFractionFile': + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') + + return None + + def _list_outputs(self): + return l_outputs(self) + + +class CerebroInputSpec(CommandLineInputSpec): + inputMRIFile = File( + mandatory=True, desc='input 3D MRI volume', argstr='-i %s') + inputAtlasMRIFile = File( + mandatory=True, desc='atlas MRI volume', argstr='--atlas %s') + inputAtlasLabelFile = File( + mandatory=True, desc='atlas labeling', argstr='--atlaslabels %s') + inputBrainMaskFile = File(desc='brain mask file', argstr='-m %s') + outputCerebrumMaskFile = File(desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', + argstr='-o %s', genfile=True) + outputLabelMaskFile = File(desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', + argstr='-l %s', genfile=True) + costFunction = traits.Int(2, usedefault=True, desc='0,1,2', argstr='-c %d') + useCentroids = traits.Bool( + desc='use centroids of data to initialize position', argstr='--centroids') + outputAffineTransformFile = File( + desc='save affine transform to file.', argstr='--air %s') + outputWarpTransformFile = File( + desc='save warp transform to file.', argstr='--warp %s') + verbosity = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') + linearConvergence = traits.Float( + desc='linear convergence', argstr='--linconv %f') + warpLabel = traits.Int( + desc='warp order (2,3,4,5,6,7,8)', argstr='--warplevel %d') + warpConvergence = traits.Float( + desc='warp convergence', argstr='--warpconv %f') + keepTempFiles = traits.Bool( + desc="don't remove temporary files", argstr='--keep') + tempDirectory = traits.Str( + desc='specify directory to use for temporary files', argstr='--tempdir %s') + tempDirectoryBase = traits.Str( + desc='create a temporary directory within this directory', argstr='--tempdirbase %s') + + +class CerebroOutputSpec(TraitedSpec): + outputCerebrumMaskFile = File(desc='path/name of cerebrum mask file') + outputLabelMaskFile = File(desc='path/name of label mask file') + outputAffineTransformFile = File(desc='path/name of affine transform file') + outputWarpTransformFile = File(desc='path/name of warp transform file') + + +class Cerebro(CommandLine): + """ + Cerebrum/cerebellum labeling tool + This program performs automated labeling of cerebellum and cerebrum in T1 MRI. + Input MRI should be skull-stripped or a brain-only mask should be provided. + + + http://brainsuite.org/processing/surfaceextraction/cerebrum/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> cerebro = brainsuite.Cerebro() + >>> cerebro.inputs.inputMRIFile = example_data('structural.nii') + >>> cerebro.inputs.inputAtlasMRIFile = 'atlasMRIVolume.img' + >>> cerebro.inputs.inputAtlasLabelFile = 'atlasLabels.img' + >>> cerebro.inputs.inputBrainMaskFile = example_data('mask.nii') + >>> results = cerebro.run() #doctest: +SKIP + + """ + + input_spec = CerebroInputSpec + output_spec = CerebroOutputSpec + _cmd = 'cerebro' + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + if name == 'outputCerebrumMaskFile' or name == 'outputLabelMaskFile': + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') + + return None + + def _list_outputs(self): + return l_outputs(self) + + +class CortexInputSpec(CommandLineInputSpec): + inputHemisphereLabelFile = File( + mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') + outputCerebrumMask = File( + desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + inputTissueFractionFile = File( + mandatory=True, desc='tissue fraction file (32-bit float)', argstr='-f %s') + tissueFractionThreshold = traits.Float( + 50.0, usedefault=True, desc='tissue fraction threshold (percentage)', argstr='-p %f') + computeWGBoundary = traits.Bool( + True, usedefault=True, desc='compute WM/GM boundary', argstr='-w') + computeGCBoundary = traits.Bool( + desc='compute GM/CSF boundary', argstr='-g') + includeAllSubcorticalAreas = traits.Bool( + True, usedefault=True, esc='include all subcortical areas in WM mask', argstr='-a') + verbosity = traits.Int(desc='verbosity level', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + + +class CortexOutputSpec(TraitedSpec): + outputCerebrumMask = File(desc='path/name of cerebrum mask') + + +class Cortex(CommandLine): + """ + cortex extractor + This program produces a cortical mask using tissue fraction estimates + and a co-registered cerebellum/hemisphere mask. + + http://brainsuite.org/processing/surfaceextraction/cortex/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> cortex = brainsuite.Cortex() + >>> cortex.inputs.inputHemisphereLabelFile = example_data('mask.nii') + >>> cortex.inputs.inputTissueFractionFile = example_data('tissues.nii.gz') + >>> results = cortex.run() #doctest: +SKIP + + """ + + input_spec = CortexInputSpec + output_spec = CortexOutputSpec + _cmd = 'cortex' + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + if name == 'outputCerebrumMask': + return getFileName(self, self.inputs.inputHemisphereLabelFile, name, '.nii.gz') + return None + + def _list_outputs(self): + return l_outputs(self) + + +class ScrubmaskInputSpec(CommandLineInputSpec): + inputMaskFile = File( + mandatory=True, desc='input structure mask file', argstr='-i %s') + outputMaskFile = File( + desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + backgroundFillThreshold = traits.Int( + 2, usedefault=True, desc='background fill threshold', argstr='-b %d') + foregroundTrimThreshold = traits.Int( + 0, usedefault=True, desc='foreground trim threshold', argstr='-f %d') + numberIterations = traits.Int(desc='number of iterations', argstr='-n %d') + verbosity = traits.Int(desc='verbosity (0=silent)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + + +class ScrubmaskOutputSpec(TraitedSpec): + outputMaskFile = File(desc='path/name of mask file') + + +class Scrubmask(CommandLine): + """ + ScrubMask tool + scrubmask filters binary masks to trim loosely connected voxels that may + result from segmentation errors and produce bumps on tessellated surfaces. + + http://brainsuite.org/processing/surfaceextraction/scrubmask/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> scrubmask = brainsuite.Scrubmask() + >>> scrubmask.inputs.inputMaskFile = example_data('mask.nii') + >>> results = scrubmask.run() #doctest: +SKIP + + """ + input_spec = ScrubmaskInputSpec + output_spec = ScrubmaskOutputSpec + _cmd = 'scrubmask' + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + if name == 'outputMaskFile': + return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') + + + return None + + def _list_outputs(self): + return l_outputs(self) + + +class TcaInputSpec(CommandLineInputSpec): + inputMaskFile = File( + mandatory=True, desc='input mask volume', argstr='-i %s') + outputMaskFile = File( + desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + minCorrectionSize = traits.Int( + 2500, usedefault=True, desc='maximum correction size', argstr='-m %d') + maxCorrectionSize = traits.Int( + desc='minimum correction size', argstr='-n %d') + foregroundDelta = traits.Int( + 20, usedefault=True, desc='foreground delta', argstr='--delta %d') + verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + + +class TcaOutputSpec(TraitedSpec): + outputMaskFile = File(desc='path/name of mask file') + + +class Tca(CommandLine): + """ + topological correction algorithm (TCA) + This program removes topological handles from a binary object. + + http://brainsuite.org/processing/surfaceextraction/tca/ + + Examples + -------- + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> tca = brainsuite.Tca() + >>> tca.inputs.inputMaskFile = example_data('mask.nii') + >>> results = tca.run() #doctest: +SKIP + + """ + input_spec = TcaInputSpec + output_spec = TcaOutputSpec + _cmd = 'tca' + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + if name == 'outputMaskFile': + return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') + + return None + + def _list_outputs(self): + return l_outputs(self) + + +class DewispInputSpec(CommandLineInputSpec): + inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') + outputMaskFile = File( + desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + verbosity = traits.Int(desc='verbosity', argstr='-v %d') + sizeThreshold = traits.Int(desc='size threshold', argstr='-t %d') + maximumIterations = traits.Int( + desc='maximum number of iterations', argstr='-n %d') + timer = traits.Bool(desc='time processing', argstr='--timer') + + +class DewispOutputSpec(TraitedSpec): + outputMaskFile = File(desc='path/name of mask file') + + +class Dewisp(CommandLine): + """ + dewisp + removes wispy tendril structures from cortex model binary masks. + It does so based on graph theoretic analysis of connected components, + similar to TCA. Each branch of the structure graph is analyzed to determine + pinch points that indicate a likely error in segmentation that attaches noise + to the image. The pinch threshold determines how many voxels the cross-section + can be before it is considered part of the image. + + http://brainsuite.org/processing/surfaceextraction/dewisp/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> dewisp = brainsuite.Dewisp() + >>> dewisp.inputs.inputMaskFile = example_data('mask.nii') + >>> results = dewisp.run() #doctest: +SKIP + + """ + + input_spec = DewispInputSpec + output_spec = DewispOutputSpec + _cmd = 'dewisp' + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + if name == 'outputMaskFile': + return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') + + return None + + def _list_outputs(self): + return l_outputs(self) + + +class DfsInputSpec(CommandLineInputSpec): + inputVolumeFile = File( + mandatory=True, desc='input 3D volume', argstr='-i %s') + outputSurfaceFile = File( + desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + inputShadingVolume = File( + desc='shade surface model with data from image volume', argstr='-c %s') + smoothingIterations = traits.Int( + 10, usedefault=True, desc='number of smoothing iterations', argstr='-n %d') + smoothingConstant = traits.Float( + 0.5, usedefault=True, desc='smoothing constant', argstr='-a %f') + curvatureWeighting = traits.Float( + 5.0, usedefault=True, desc='curvature weighting', argstr='-w %f') + scalingPercentile = traits.Float(desc='scaling percentile', argstr='-f %f') + nonZeroTessellation = traits.Bool( + desc='tessellate non-zero voxels', argstr='-nz', xor=('nonZeroTessellation', 'specialTessellation')) + tessellationThreshold = traits.Float( + desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%f') + specialTessellation = traits.Enum('greater_than', 'less_than', 'equal_to', desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%s', xor=( + 'nonZeroTessellation', 'specialTessellation'), requires=['tessellationThreshold'], position=-1) + zeroPadFlag = traits.Bool( + desc='zero-pad volume (avoids clipping at edges)', argstr='-z') + noNormalsFlag = traits.Bool( + desc='do not compute vertex normals', argstr='--nonormals') + postSmoothFlag = traits.Bool( + desc='smooth vertices after coloring', argstr='--postsmooth') + verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + + +class DfsOutputSpec(TraitedSpec): + outputSurfaceFile = File(desc='path/name of surface file') + + +class Dfs(CommandLine): + """ + Surface Generator + Generates mesh surfaces using an isosurface algorithm. + + http://brainsuite.org/processing/surfaceextraction/inner-cortical-surface/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> dfs = brainsuite.Dfs() + >>> dfs.inputs.inputVolumeFile = example_data('structural.nii') + >>> results = dfs.run() #doctest: +SKIP + + """ + + input_spec = DfsInputSpec + output_spec = DfsOutputSpec + _cmd = 'dfs' + + def _format_arg(self, name, spec, value): + if name == 'tessellationThreshold': + return '' # blank argstr + if name == 'specialTessellation': + threshold = self.inputs.tessellationThreshold + return spec.argstr % {"greater_than": ''.join(("-gt %f" % threshold)), "less_than": ''.join(("-lt %f" % threshold)), "equal_to": ''.join(("-eq %f" % threshold))}[value] + return super(Dfs, self)._format_arg(name, spec, value) + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + if name == 'outputSurfaceFile': + return getFileName(self, self.inputs.inputVolumeFile, name, '.dfs') + + return None + + def _list_outputs(self): + return l_outputs(self) + + +class PialmeshInputSpec(CommandLineInputSpec): + inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') + outputSurfaceFile = File( + desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + verbosity = traits.Int(desc='verbosity', argstr='-v %d') + inputTissueFractionFile = File( + mandatory=True, desc='floating point (32) tissue fraction image', argstr='-f %s') + numIterations = traits.Int( + 100, usedefault=True, desc='number of iterations', argstr='-n %d') + searchRadius = traits.Float( + 1, usedefault=True, desc='search radius', argstr='-r %f') + stepSize = traits.Float(0.4, usedefault=True, + desc='step size', argstr='-s %f') + inputMaskFile = File( + mandatory=True, desc='restrict growth to mask file region', argstr='-m %s') + maxThickness = traits.Float( + 20, usedefault=True, desc='maximum allowed tissue thickness', argstr='--max %f') + tissueThreshold = traits.Float( + 1.05, usedefault=True, desc='tissue threshold', argstr='-t %f') +# output interval is not an output -- it specifies how frequently the +# output surfaces are generated + outputInterval = traits.Int( + 10, usedefault=True, desc='output interval', argstr='--interval %d') + exportPrefix = traits.Str( + desc='prefix for exporting surfaces if interval is set', argstr='--prefix %s') + laplacianSmoothing = traits.Float( + 0.025, usedefault=True, desc='apply Laplacian smoothing', argstr='--smooth %f') + timer = traits.Bool(desc='show timing', argstr='--timer') + recomputeNormals = traits.Bool( + desc='recompute normals at each iteration', argstr='--norm') + normalSmoother = traits.Float( + 0.2, usedefault=True, desc='strength of normal smoother.', argstr='--nc %f') + tangentSmoother = traits.Float( + desc='strength of tangential smoother.', argstr='--tc %f') + + +class PialmeshOutputSpec(TraitedSpec): + outputSurfaceFile = File(desc='path/name of surface file') + + +class Pialmesh(CommandLine): + """ + pialmesh + computes a pial surface model using an inner WM/GM mesh and a tissue fraction map. + + http://brainsuite.org/processing/surfaceextraction/pial/ + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> pialmesh = brainsuite.Pialmesh() + >>> pialmesh.inputs.inputSurfaceFile = 'input_mesh.dfs' + >>> pialmesh.inputs.inputTissueFractionFile = 'frac_file.nii.gz' + >>> pialmesh.inputs.inputMaskFile = example_data('mask.nii') + >>> results = pialmesh.run() #doctest: +SKIP + + """ + + input_spec = PialmeshInputSpec + output_spec = PialmeshOutputSpec + _cmd = 'pialmesh' + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + if name == 'outputSurfaceFile': + return getFileName(self, self.inputs.inputSurfaceFile, name, '.dfs') + + return None + + def _list_outputs(self): + return l_outputs(self) + + +class SkullfinderInputSpec(CommandLineInputSpec): + inputMRIFile = File(mandatory=True, desc='input file', argstr='-i %s') + inputMaskFile = File( + mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') + outputLabelFile = File( + desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) + verbosity = traits.Int(desc='verbosity', argstr='-v %d') + lowerThreshold = traits.Int( + desc='Lower threshold for segmentation', argstr='-l %d') + upperThreshold = traits.Int( + desc='Upper threshold for segmentation', argstr='-u %d') + surfaceFilePrefix = traits.Str( + desc='if specified, generate surface files for brain, skull, and scalp', argstr='-s %s') + bgLabelValue = traits.Int( + desc='background label value (0-255)', argstr='--bglabel %d') + scalpLabelValue = traits.Int( + desc='scalp label value (0-255)', argstr='--scalplabel %d') + skullLabelValue = traits.Int( + desc='skull label value (0-255)', argstr='--skulllabel %d') + spaceLabelValue = traits.Int( + desc='space label value (0-255)', argstr='--spacelabel %d') + brainLabelValue = traits.Int( + desc='brain label value (0-255)', argstr='--brainlabel %d') + performFinalOpening = traits.Bool( + desc='perform a final opening operation on the scalp mask', argstr='--finalOpening') + + +class SkullfinderOutputSpec(TraitedSpec): + outputLabelFile = File(desc='path/name of label file') + + +class Skullfinder(CommandLine): + """ + Skull and scalp segmentation algorithm. + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> skullfinder = brainsuite.Skullfinder() + >>> skullfinder.inputs.inputMRIFile = example_data('structural.nii') + >>> skullfinder.inputs.inputMaskFile = example_data('mask.nii') + >>> results = skullfinder.run() #doctest: +SKIP + + """ + input_spec = SkullfinderInputSpec + output_spec = SkullfinderOutputSpec + _cmd = 'skullfinder' + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + if name == 'outputLabelFile': + return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') + + return None + + def _list_outputs(self): + return l_outputs(self) + + +class HemisplitInputSpec(CommandLineInputSpec): + inputSurfaceFile = File( + mandatory=True, desc='input surface', argstr='-i %s') + inputHemisphereLabelFile = File( + mandatory=True, desc='input hemisphere label volume', argstr='-l %s') + outputLeftHemisphere = File( + desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) + outputRightHemisphere = File( + desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) + pialSurfaceFile = File( + desc='pial surface file -- must have same geometry as input surface', argstr='-p %s') + outputLeftPialHemisphere = File( + desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) + outputRightPialHemisphere = File( + desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) + verbosity = traits.Int(desc='verbosity (0 = silent)', argstr='-v %d') + timer = traits.Bool(desc='timing function', argstr='--timer') + + +class HemisplitOutputSpec(TraitedSpec): + outputLeftHemisphere = File(desc='path/name of left hemisphere') + outputRightHemisphere = File(desc='path/name of right hemisphere') + outputLeftPialHemisphere = File(desc='path/name of left pial hemisphere') + outputRightPialHemisphere = File(desc='path/name of right pial hemisphere') + + +class Hemisplit(CommandLine): + """ + Hemisphere splitter + Splits a surface object into two separate surfaces given an input label volume. + Each vertex is labeled left or right based on the labels being odd (left) or even (right). + The largest contour on the split surface is then found and used as the separation between left and right. + + Examples + -------- + + >>> from nipype.interfaces import brainsuite + >>> from nipype.testing import example_data + >>> hemisplit = brainsuite.Hemisplit() + >>> hemisplit.inputs.inputSurfaceFile = 'input_surf.dfs' + >>> hemisplit.inputs.inputHemisphereLabelFile = 'label.nii' + >>> hemisplit.inputs.pialSurfaceFile = 'pial.dfs' + >>> results = hemisplit.run() #doctest: +SKIP + + """ + + input_spec = HemisplitInputSpec + output_spec = HemisplitOutputSpec + _cmd = 'hemisplit' + + def _gen_filename(self, name): + inputs = self.inputs.get() + if isdefined(inputs[name]): + return os.path.abspath(inputs[name]) + + + if (name == 'outputLeftHemisphere' + or name == 'outputRightHemisphere' + or name == 'outputLeftPialHemisphere' + or name == 'outputRightPialHemisphere'): + return getFileName(self, self.inputs.inputSurfaceFile, name, '.dfs') + + return None + + def _list_outputs(self): + return l_outputs(self) + +# used to generate file names for outputs +# removes pathway and extension of inputName, returns concatenation of] +# inputName, command, name, and extension +def getFileName(self, inputName, name, extension): + fullInput = os.path.basename(inputName) + dotRegex = regex.compile("[^.]+") + inputNoExtension = dotRegex.findall(fullInput)[0] + return os.path.abspath( + ''.join((inputNoExtension, '_', self._cmd, '_', name, extension))) + +def l_outputs(self): + outputs = self.output_spec().get() + for key in outputs: + name = self._gen_filename(key) + if not name is None: + outputs[key] = name + + return outputs From f0a3a2fe0197bb4ec60967ab89a74a3eec2b8e16 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 30 Mar 2016 11:27:18 -0700 Subject: [PATCH 18/25] remove --- nipype/interfaces/brainsuite.py | 888 -------------------------------- 1 file changed, 888 deletions(-) delete mode 100644 nipype/interfaces/brainsuite.py diff --git a/nipype/interfaces/brainsuite.py b/nipype/interfaces/brainsuite.py deleted file mode 100644 index d49b8147a1..0000000000 --- a/nipype/interfaces/brainsuite.py +++ /dev/null @@ -1,888 +0,0 @@ -import os -import re as regex - -from nipype.interfaces.base import( - TraitedSpec, - CommandLineInputSpec, - CommandLine, - File, - traits, - isdefined, -) - - -class BseInputSpec(CommandLineInputSpec): - - inputMRIFile = File(mandatory=True, argstr='-i %s', - desc='input MRI volume') - outputMRIVolume = File(desc='output brain-masked MRI volume. If' - 'unspecified, output file name will be auto' - 'generated.', - argstr='-o %s', hash_files=False, genfile=True) - diffusionConstant = traits.Float(25, usedefault=True, - desc='diffusion constant', argstr='-d %f') - diffusionIterations = traits.Int(3, usedefault=True, - desc='diffusion iterations', - argstr='-n %d') - edgeDetectionConstant = traits.Float(0.64, usedefault=True, - desc='edge detection constant', - argstr='-s %f') - radius = traits.Float(1, usedefault=True, - desc='radius of erosion/dilation filter', - argstr='-r %f') - dilateFinalMask = traits.Bool(True, usedefault=True, - desc='dilate final mask', argstr='-p') - trim = traits.Bool(True, usedefault=True, desc='trim brainstem', - argstr='--trim') - outputMaskFile = File(desc='save smooth brain mask', - argstr='--mask %s', hash_files=False) - outputDiffusionFilter = File(desc='diffusion filter output', - argstr='--adf %s', hash_files=False) - outputEdgeMap = File(desc='edge map output', argstr='--edge %s', - hash_files=False) - outputDetailedBrainMask = File(desc='save detailed brain mask', - argstr='--hires %s', hash_files=False) - outputCortexFile = File(desc='cortex file', argstr='--cortex %s', - hash_files=False) - verbosityLevel = traits.Float(1, usedefault=True, - desc=' verbosity level (0=silent)', - argstr='-v %f') - noRotate = traits.Bool(desc='retain original orientation' - '(default behavior will auto-rotate input NII files' - 'to LPI orientation)', argstr='--norotate') - timer = traits.Bool(desc='show timing', argstr='--timer') - - -class BseOutputSpec(TraitedSpec): - outputMRIVolume = File(desc='path/name of brain-masked MRI volume') - outputMaskFile = File(desc='path/name of smooth brain mask') - outputDiffusionFilter = File(desc='path/name of diffusion filter output') - outputEdgeMap = File(desc='path/name of edge map output') - outputDetailedBrainMask = File(desc='path/name of detailed brain mask') - outputCortexFile = File(desc='path/name of cortex file') - - -class Bse(CommandLine): - """ - brain surface extractor (BSE) - This program performs automated skull and scalp removal on T1-weighted MRI volumes. - - http://brainsuite.org/processing/surfaceextraction/bse/ - - Examples - -------- - - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> bse = brainsuite.Bse() - >>> bse.inputs.inputMRIFile = example_data('structural.nii') - >>> results = bse.run() #doctest: +SKIP - - """ - - input_spec = BseInputSpec - output_spec = BseOutputSpec - _cmd = 'bse' - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - if name == 'outputMRIVolume': - return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') - - return None - - def _list_outputs(self): - return l_outputs(self) - - -class BfcInputSpec(CommandLineInputSpec): - inputMRIFile = File(mandatory=True, - desc='input skull-stripped MRI volume', argstr='-i %s') - inputMaskFile = File(desc='mask file', argstr='-m %s', hash_files=False) - outputMRIVolume = File(desc='output bias-corrected MRI volume.' - 'If unspecified, output file name' - 'will be auto generated.', argstr='-o %s', - hash_files=False, genfile=True) - outputBiasField = File(desc='save bias field estimate', - argstr='--bias %s', hash_files=False) - outputMaskedBiasField = File(desc='save bias field estimate (masked)', - argstr='--maskedbias %s', hash_files=False) - histogramRadius = traits.Int(desc='histogram radius (voxels)', - argstr='-r %d') - biasEstimateSpacing = traits.Int(desc='bias sample spacing (voxels)', - argstr='-s %d') - controlPointSpacing = traits.Int(desc='control point spacing (voxels)', - argstr='-c %d') - splineLambda = traits.Float(desc='spline stiffness weighting parameter', - argstr='-w %f') - histogramType = traits.Enum('ellipse', 'block', - desc='Options for type of histogram\nellipse:' - 'use ellipsoid for ROI histogram\nblock' - ':use block for ROI histogram', - argstr='%s') - iterativeMode = traits.Bool(desc='iterative mode (overrides -r, -s, -c,' - '-w settings)', - argstr='--iterate') - correctionScheduleFile = File(desc='list of parameters ', - argstr='--schedule %s') - biasFieldEstimatesOutputPrefix = traits.Str(desc='save iterative bias' - 'field estimates as' - '.n.field.nii.gz', - argstr='--biasprefix %s') - correctedImagesOutputPrefix = traits.Str(desc='save iterative corrected' - 'images as' - '.n.bfc.nii.gz', - argstr='--prefix %s') - correctWholeVolume = traits.Bool(desc='apply correction field to entire' - 'volume', argstr='--extrapolate') - minBias = traits.Float(0.5, usedefault=True, desc='minimum allowed bias' - 'value', - argstr='-L %f') - maxBias = traits.Float(1.5, usedefault=True, desc='maximum allowed bias' '' - 'value', - argstr='-U %f') - biasRange = traits.Enum("low", "medium", "high", - desc='Preset options for bias_model\n' - 'low: small bias model [0.95,1.05]\n' - 'medium: medium bias model [0.90,1.10]\n' - 'high: high bias model [0.80,1.20]', - argstr='%s') - intermediate_file_type = traits.Enum("analyze", "nifti", - "gzippedAnalyze", "gzippedNifti", - desc='Options for the format in' - 'which intermediate files are' "" - 'generated', - argstr='%s') - convergenceThreshold = traits.Float(desc='convergence threshold', - argstr='--eps %f') - biasEstimateConvergenceThreshold = traits.Float( - desc='bias estimate convergence threshold (values > 0.1 disable)', argstr='--beps %f') - verbosityLevel = traits.Int( - desc='verbosity level (0=silent)', argstr='-v %d') - timer = traits.Bool(desc='display timing information', argstr='--timer') - - -class BfcOutputSpec(TraitedSpec): - outputMRIVolume = File(desc='path/name of output file') - outputBiasField = File(desc='path/name of bias field output file') - outputMaskedBiasField = File(desc='path/name of masked bias field output') - correctionScheduleFile = File(desc='path/name of schedule file') - - -class Bfc(CommandLine): - """ - bias field corrector (BFC) - This program corrects gain variation in T1-weighted MRI. - - http://brainsuite.org/processing/surfaceextraction/bfc/ - - Examples - -------- - - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> bfc = brainsuite.Bfc() - >>> bfc.inputs.inputMRIFile = example_data('structural.nii') - >>> bfc.inputs.inputMaskFile = example_data('mask.nii') - >>> results = bfc.run() #doctest: +SKIP - - """ - - - input_spec = BfcInputSpec - output_spec = BfcOutputSpec - _cmd = 'bfc' - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - if name == 'outputMRIVolume': - return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') - - return None - - def _format_arg(self, name, spec, value): - if name == 'histogramType': - return spec.argstr % {"ellipse": "--ellipse", "block": "--block"}[value] - if name == 'biasRange': - return spec.argstr % {"low": "--low", "medium": "--medium", "high": "--high"}[value] - if name == 'intermediate_file_type': - return spec.argstr % {"analyze": "--analyze", "nifti": "--nifti", "gzippedAnalyze": "--analyzegz", "gzippedNifti": "--niftigz"}[value] - - return super(Bfc, self)._format_arg(name, spec, value) - - def _list_outputs(self): - return l_outputs(self) - - -class PvcInputSpec(CommandLineInputSpec): - inputMRIFile = File(mandatory=True, desc='MRI file', argstr='-i %s') - inputMaskFile = File(desc='brain mask file', argstr='-m %s') - outputLabelFile = File(desc='output label file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - outputTissueFractionFile = File(desc='output tissue fraction file', argstr='-f %s', genfile=True) - spatialPrior = traits.Float(desc='spatial prior strength', argstr='-l %f') - verbosity = traits.Int(desc='verbosity level (0 = silent)', argstr='-v %d') - threeClassFlag = traits.Bool( - desc='use a three-class (CSF=0,GM=1,WM=2) labeling', argstr='-3') - timer = traits.Bool(desc='time processing', argstr='--timer') - - -class PvcOutputSpec(TraitedSpec): - outputLabelFile = File(desc='path/name of label file') - outputTissueFractionFile = File(desc='path/name of tissue fraction file') - - -class Pvc(CommandLine): - """ - partial volume classifier (PVC) tool. - This program performs voxel-wise tissue classification T1-weighted MRI. - Image should be skull-stripped and bias-corrected before tissue classification. - - http://brainsuite.org/processing/surfaceextraction/pvc/ - - Examples - -------- - - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> pvc = brainsuite.Pvc() - >>> pvc.inputs.inputMRIFile = example_data('structural.nii') - >>> pvc.inputs.inputMaskFile = example_data('mask.nii') - >>> results = pvc.run() #doctest: +SKIP - - """ - - input_spec = PvcInputSpec - output_spec = PvcOutputSpec - _cmd = 'pvc' - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - if name == 'outputLabelFile' or name == 'outputTissueFractionFile': - return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') - - return None - - def _list_outputs(self): - return l_outputs(self) - - -class CerebroInputSpec(CommandLineInputSpec): - inputMRIFile = File( - mandatory=True, desc='input 3D MRI volume', argstr='-i %s') - inputAtlasMRIFile = File( - mandatory=True, desc='atlas MRI volume', argstr='--atlas %s') - inputAtlasLabelFile = File( - mandatory=True, desc='atlas labeling', argstr='--atlaslabels %s') - inputBrainMaskFile = File(desc='brain mask file', argstr='-m %s') - outputCerebrumMaskFile = File(desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', - argstr='-o %s', genfile=True) - outputLabelMaskFile = File(desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', - argstr='-l %s', genfile=True) - costFunction = traits.Int(2, usedefault=True, desc='0,1,2', argstr='-c %d') - useCentroids = traits.Bool( - desc='use centroids of data to initialize position', argstr='--centroids') - outputAffineTransformFile = File( - desc='save affine transform to file.', argstr='--air %s') - outputWarpTransformFile = File( - desc='save warp transform to file.', argstr='--warp %s') - verbosity = traits.Int(desc='verbosity level (0=silent)', argstr='-v %d') - linearConvergence = traits.Float( - desc='linear convergence', argstr='--linconv %f') - warpLabel = traits.Int( - desc='warp order (2,3,4,5,6,7,8)', argstr='--warplevel %d') - warpConvergence = traits.Float( - desc='warp convergence', argstr='--warpconv %f') - keepTempFiles = traits.Bool( - desc="don't remove temporary files", argstr='--keep') - tempDirectory = traits.Str( - desc='specify directory to use for temporary files', argstr='--tempdir %s') - tempDirectoryBase = traits.Str( - desc='create a temporary directory within this directory', argstr='--tempdirbase %s') - - -class CerebroOutputSpec(TraitedSpec): - outputCerebrumMaskFile = File(desc='path/name of cerebrum mask file') - outputLabelMaskFile = File(desc='path/name of label mask file') - outputAffineTransformFile = File(desc='path/name of affine transform file') - outputWarpTransformFile = File(desc='path/name of warp transform file') - - -class Cerebro(CommandLine): - """ - Cerebrum/cerebellum labeling tool - This program performs automated labeling of cerebellum and cerebrum in T1 MRI. - Input MRI should be skull-stripped or a brain-only mask should be provided. - - - http://brainsuite.org/processing/surfaceextraction/cerebrum/ - - Examples - -------- - - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> cerebro = brainsuite.Cerebro() - >>> cerebro.inputs.inputMRIFile = example_data('structural.nii') - >>> cerebro.inputs.inputAtlasMRIFile = 'atlasMRIVolume.img' - >>> cerebro.inputs.inputAtlasLabelFile = 'atlasLabels.img' - >>> cerebro.inputs.inputBrainMaskFile = example_data('mask.nii') - >>> results = cerebro.run() #doctest: +SKIP - - """ - - input_spec = CerebroInputSpec - output_spec = CerebroOutputSpec - _cmd = 'cerebro' - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - if name == 'outputCerebrumMaskFile' or name == 'outputLabelMaskFile': - return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') - - return None - - def _list_outputs(self): - return l_outputs(self) - - -class CortexInputSpec(CommandLineInputSpec): - inputHemisphereLabelFile = File( - mandatory=True, desc='hemisphere / lobe label volume', argstr='-h %s') - outputCerebrumMask = File( - desc='output structure mask. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - inputTissueFractionFile = File( - mandatory=True, desc='tissue fraction file (32-bit float)', argstr='-f %s') - tissueFractionThreshold = traits.Float( - 50.0, usedefault=True, desc='tissue fraction threshold (percentage)', argstr='-p %f') - computeWGBoundary = traits.Bool( - True, usedefault=True, desc='compute WM/GM boundary', argstr='-w') - computeGCBoundary = traits.Bool( - desc='compute GM/CSF boundary', argstr='-g') - includeAllSubcorticalAreas = traits.Bool( - True, usedefault=True, esc='include all subcortical areas in WM mask', argstr='-a') - verbosity = traits.Int(desc='verbosity level', argstr='-v %d') - timer = traits.Bool(desc='timing function', argstr='--timer') - - -class CortexOutputSpec(TraitedSpec): - outputCerebrumMask = File(desc='path/name of cerebrum mask') - - -class Cortex(CommandLine): - """ - cortex extractor - This program produces a cortical mask using tissue fraction estimates - and a co-registered cerebellum/hemisphere mask. - - http://brainsuite.org/processing/surfaceextraction/cortex/ - - Examples - -------- - - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> cortex = brainsuite.Cortex() - >>> cortex.inputs.inputHemisphereLabelFile = example_data('mask.nii') - >>> cortex.inputs.inputTissueFractionFile = example_data('tissues.nii.gz') - >>> results = cortex.run() #doctest: +SKIP - - """ - - input_spec = CortexInputSpec - output_spec = CortexOutputSpec - _cmd = 'cortex' - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - if name == 'outputCerebrumMask': - return getFileName(self, self.inputs.inputHemisphereLabelFile, name, '.nii.gz') - return None - - def _list_outputs(self): - return l_outputs(self) - - -class ScrubmaskInputSpec(CommandLineInputSpec): - inputMaskFile = File( - mandatory=True, desc='input structure mask file', argstr='-i %s') - outputMaskFile = File( - desc='output structure mask file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - backgroundFillThreshold = traits.Int( - 2, usedefault=True, desc='background fill threshold', argstr='-b %d') - foregroundTrimThreshold = traits.Int( - 0, usedefault=True, desc='foreground trim threshold', argstr='-f %d') - numberIterations = traits.Int(desc='number of iterations', argstr='-n %d') - verbosity = traits.Int(desc='verbosity (0=silent)', argstr='-v %d') - timer = traits.Bool(desc='timing function', argstr='--timer') - - -class ScrubmaskOutputSpec(TraitedSpec): - outputMaskFile = File(desc='path/name of mask file') - - -class Scrubmask(CommandLine): - """ - ScrubMask tool - scrubmask filters binary masks to trim loosely connected voxels that may - result from segmentation errors and produce bumps on tessellated surfaces. - - http://brainsuite.org/processing/surfaceextraction/scrubmask/ - - Examples - -------- - - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> scrubmask = brainsuite.Scrubmask() - >>> scrubmask.inputs.inputMaskFile = example_data('mask.nii') - >>> results = scrubmask.run() #doctest: +SKIP - - """ - input_spec = ScrubmaskInputSpec - output_spec = ScrubmaskOutputSpec - _cmd = 'scrubmask' - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - if name == 'outputMaskFile': - return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') - - - return None - - def _list_outputs(self): - return l_outputs(self) - - -class TcaInputSpec(CommandLineInputSpec): - inputMaskFile = File( - mandatory=True, desc='input mask volume', argstr='-i %s') - outputMaskFile = File( - desc='output mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - minCorrectionSize = traits.Int( - 2500, usedefault=True, desc='maximum correction size', argstr='-m %d') - maxCorrectionSize = traits.Int( - desc='minimum correction size', argstr='-n %d') - foregroundDelta = traits.Int( - 20, usedefault=True, desc='foreground delta', argstr='--delta %d') - verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') - timer = traits.Bool(desc='timing function', argstr='--timer') - - -class TcaOutputSpec(TraitedSpec): - outputMaskFile = File(desc='path/name of mask file') - - -class Tca(CommandLine): - """ - topological correction algorithm (TCA) - This program removes topological handles from a binary object. - - http://brainsuite.org/processing/surfaceextraction/tca/ - - Examples - -------- - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> tca = brainsuite.Tca() - >>> tca.inputs.inputMaskFile = example_data('mask.nii') - >>> results = tca.run() #doctest: +SKIP - - """ - input_spec = TcaInputSpec - output_spec = TcaOutputSpec - _cmd = 'tca' - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - if name == 'outputMaskFile': - return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') - - return None - - def _list_outputs(self): - return l_outputs(self) - - -class DewispInputSpec(CommandLineInputSpec): - inputMaskFile = File(mandatory=True, desc='input file', argstr='-i %s') - outputMaskFile = File( - desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - verbosity = traits.Int(desc='verbosity', argstr='-v %d') - sizeThreshold = traits.Int(desc='size threshold', argstr='-t %d') - maximumIterations = traits.Int( - desc='maximum number of iterations', argstr='-n %d') - timer = traits.Bool(desc='time processing', argstr='--timer') - - -class DewispOutputSpec(TraitedSpec): - outputMaskFile = File(desc='path/name of mask file') - - -class Dewisp(CommandLine): - """ - dewisp - removes wispy tendril structures from cortex model binary masks. - It does so based on graph theoretic analysis of connected components, - similar to TCA. Each branch of the structure graph is analyzed to determine - pinch points that indicate a likely error in segmentation that attaches noise - to the image. The pinch threshold determines how many voxels the cross-section - can be before it is considered part of the image. - - http://brainsuite.org/processing/surfaceextraction/dewisp/ - - Examples - -------- - - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> dewisp = brainsuite.Dewisp() - >>> dewisp.inputs.inputMaskFile = example_data('mask.nii') - >>> results = dewisp.run() #doctest: +SKIP - - """ - - input_spec = DewispInputSpec - output_spec = DewispOutputSpec - _cmd = 'dewisp' - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - if name == 'outputMaskFile': - return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') - - return None - - def _list_outputs(self): - return l_outputs(self) - - -class DfsInputSpec(CommandLineInputSpec): - inputVolumeFile = File( - mandatory=True, desc='input 3D volume', argstr='-i %s') - outputSurfaceFile = File( - desc='output surface mesh file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - inputShadingVolume = File( - desc='shade surface model with data from image volume', argstr='-c %s') - smoothingIterations = traits.Int( - 10, usedefault=True, desc='number of smoothing iterations', argstr='-n %d') - smoothingConstant = traits.Float( - 0.5, usedefault=True, desc='smoothing constant', argstr='-a %f') - curvatureWeighting = traits.Float( - 5.0, usedefault=True, desc='curvature weighting', argstr='-w %f') - scalingPercentile = traits.Float(desc='scaling percentile', argstr='-f %f') - nonZeroTessellation = traits.Bool( - desc='tessellate non-zero voxels', argstr='-nz', xor=('nonZeroTessellation', 'specialTessellation')) - tessellationThreshold = traits.Float( - desc='To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%f') - specialTessellation = traits.Enum('greater_than', 'less_than', 'equal_to', desc='To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to ', argstr='%s', xor=( - 'nonZeroTessellation', 'specialTessellation'), requires=['tessellationThreshold'], position=-1) - zeroPadFlag = traits.Bool( - desc='zero-pad volume (avoids clipping at edges)', argstr='-z') - noNormalsFlag = traits.Bool( - desc='do not compute vertex normals', argstr='--nonormals') - postSmoothFlag = traits.Bool( - desc='smooth vertices after coloring', argstr='--postsmooth') - verbosity = traits.Int(desc='verbosity (0 = quiet)', argstr='-v %d') - timer = traits.Bool(desc='timing function', argstr='--timer') - - -class DfsOutputSpec(TraitedSpec): - outputSurfaceFile = File(desc='path/name of surface file') - - -class Dfs(CommandLine): - """ - Surface Generator - Generates mesh surfaces using an isosurface algorithm. - - http://brainsuite.org/processing/surfaceextraction/inner-cortical-surface/ - - Examples - -------- - - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> dfs = brainsuite.Dfs() - >>> dfs.inputs.inputVolumeFile = example_data('structural.nii') - >>> results = dfs.run() #doctest: +SKIP - - """ - - input_spec = DfsInputSpec - output_spec = DfsOutputSpec - _cmd = 'dfs' - - def _format_arg(self, name, spec, value): - if name == 'tessellationThreshold': - return '' # blank argstr - if name == 'specialTessellation': - threshold = self.inputs.tessellationThreshold - return spec.argstr % {"greater_than": ''.join(("-gt %f" % threshold)), "less_than": ''.join(("-lt %f" % threshold)), "equal_to": ''.join(("-eq %f" % threshold))}[value] - return super(Dfs, self)._format_arg(name, spec, value) - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - if name == 'outputSurfaceFile': - return getFileName(self, self.inputs.inputVolumeFile, name, '.dfs') - - return None - - def _list_outputs(self): - return l_outputs(self) - - -class PialmeshInputSpec(CommandLineInputSpec): - inputSurfaceFile = File(mandatory=True, desc='input file', argstr='-i %s') - outputSurfaceFile = File( - desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - verbosity = traits.Int(desc='verbosity', argstr='-v %d') - inputTissueFractionFile = File( - mandatory=True, desc='floating point (32) tissue fraction image', argstr='-f %s') - numIterations = traits.Int( - 100, usedefault=True, desc='number of iterations', argstr='-n %d') - searchRadius = traits.Float( - 1, usedefault=True, desc='search radius', argstr='-r %f') - stepSize = traits.Float(0.4, usedefault=True, - desc='step size', argstr='-s %f') - inputMaskFile = File( - mandatory=True, desc='restrict growth to mask file region', argstr='-m %s') - maxThickness = traits.Float( - 20, usedefault=True, desc='maximum allowed tissue thickness', argstr='--max %f') - tissueThreshold = traits.Float( - 1.05, usedefault=True, desc='tissue threshold', argstr='-t %f') -# output interval is not an output -- it specifies how frequently the -# output surfaces are generated - outputInterval = traits.Int( - 10, usedefault=True, desc='output interval', argstr='--interval %d') - exportPrefix = traits.Str( - desc='prefix for exporting surfaces if interval is set', argstr='--prefix %s') - laplacianSmoothing = traits.Float( - 0.025, usedefault=True, desc='apply Laplacian smoothing', argstr='--smooth %f') - timer = traits.Bool(desc='show timing', argstr='--timer') - recomputeNormals = traits.Bool( - desc='recompute normals at each iteration', argstr='--norm') - normalSmoother = traits.Float( - 0.2, usedefault=True, desc='strength of normal smoother.', argstr='--nc %f') - tangentSmoother = traits.Float( - desc='strength of tangential smoother.', argstr='--tc %f') - - -class PialmeshOutputSpec(TraitedSpec): - outputSurfaceFile = File(desc='path/name of surface file') - - -class Pialmesh(CommandLine): - """ - pialmesh - computes a pial surface model using an inner WM/GM mesh and a tissue fraction map. - - http://brainsuite.org/processing/surfaceextraction/pial/ - - Examples - -------- - - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> pialmesh = brainsuite.Pialmesh() - >>> pialmesh.inputs.inputSurfaceFile = 'input_mesh.dfs' - >>> pialmesh.inputs.inputTissueFractionFile = 'frac_file.nii.gz' - >>> pialmesh.inputs.inputMaskFile = example_data('mask.nii') - >>> results = pialmesh.run() #doctest: +SKIP - - """ - - input_spec = PialmeshInputSpec - output_spec = PialmeshOutputSpec - _cmd = 'pialmesh' - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - if name == 'outputSurfaceFile': - return getFileName(self, self.inputs.inputSurfaceFile, name, '.dfs') - - return None - - def _list_outputs(self): - return l_outputs(self) - - -class SkullfinderInputSpec(CommandLineInputSpec): - inputMRIFile = File(mandatory=True, desc='input file', argstr='-i %s') - inputMaskFile = File( - mandatory=True, desc='A brain mask file, 8-bit image (0=non-brain, 255=brain)', argstr='-m %s') - outputLabelFile = File( - desc='output file. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - verbosity = traits.Int(desc='verbosity', argstr='-v %d') - lowerThreshold = traits.Int( - desc='Lower threshold for segmentation', argstr='-l %d') - upperThreshold = traits.Int( - desc='Upper threshold for segmentation', argstr='-u %d') - surfaceFilePrefix = traits.Str( - desc='if specified, generate surface files for brain, skull, and scalp', argstr='-s %s') - bgLabelValue = traits.Int( - desc='background label value (0-255)', argstr='--bglabel %d') - scalpLabelValue = traits.Int( - desc='scalp label value (0-255)', argstr='--scalplabel %d') - skullLabelValue = traits.Int( - desc='skull label value (0-255)', argstr='--skulllabel %d') - spaceLabelValue = traits.Int( - desc='space label value (0-255)', argstr='--spacelabel %d') - brainLabelValue = traits.Int( - desc='brain label value (0-255)', argstr='--brainlabel %d') - performFinalOpening = traits.Bool( - desc='perform a final opening operation on the scalp mask', argstr='--finalOpening') - - -class SkullfinderOutputSpec(TraitedSpec): - outputLabelFile = File(desc='path/name of label file') - - -class Skullfinder(CommandLine): - """ - Skull and scalp segmentation algorithm. - - Examples - -------- - - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> skullfinder = brainsuite.Skullfinder() - >>> skullfinder.inputs.inputMRIFile = example_data('structural.nii') - >>> skullfinder.inputs.inputMaskFile = example_data('mask.nii') - >>> results = skullfinder.run() #doctest: +SKIP - - """ - input_spec = SkullfinderInputSpec - output_spec = SkullfinderOutputSpec - _cmd = 'skullfinder' - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - if name == 'outputLabelFile': - return getFileName(self, self.inputs.inputMRIFile, name, '.nii.gz') - - return None - - def _list_outputs(self): - return l_outputs(self) - - -class HemisplitInputSpec(CommandLineInputSpec): - inputSurfaceFile = File( - mandatory=True, desc='input surface', argstr='-i %s') - inputHemisphereLabelFile = File( - mandatory=True, desc='input hemisphere label volume', argstr='-l %s') - outputLeftHemisphere = File( - desc='output surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='--left %s', genfile=True) - outputRightHemisphere = File( - desc='output surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='--right %s', genfile=True) - pialSurfaceFile = File( - desc='pial surface file -- must have same geometry as input surface', argstr='-p %s') - outputLeftPialHemisphere = File( - desc='output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.', argstr='-pl %s', genfile=True) - outputRightPialHemisphere = File( - desc='output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.', argstr='-pr %s', genfile=True) - verbosity = traits.Int(desc='verbosity (0 = silent)', argstr='-v %d') - timer = traits.Bool(desc='timing function', argstr='--timer') - - -class HemisplitOutputSpec(TraitedSpec): - outputLeftHemisphere = File(desc='path/name of left hemisphere') - outputRightHemisphere = File(desc='path/name of right hemisphere') - outputLeftPialHemisphere = File(desc='path/name of left pial hemisphere') - outputRightPialHemisphere = File(desc='path/name of right pial hemisphere') - - -class Hemisplit(CommandLine): - """ - Hemisphere splitter - Splits a surface object into two separate surfaces given an input label volume. - Each vertex is labeled left or right based on the labels being odd (left) or even (right). - The largest contour on the split surface is then found and used as the separation between left and right. - - Examples - -------- - - >>> from nipype.interfaces import brainsuite - >>> from nipype.testing import example_data - >>> hemisplit = brainsuite.Hemisplit() - >>> hemisplit.inputs.inputSurfaceFile = 'input_surf.dfs' - >>> hemisplit.inputs.inputHemisphereLabelFile = 'label.nii' - >>> hemisplit.inputs.pialSurfaceFile = 'pial.dfs' - >>> results = hemisplit.run() #doctest: +SKIP - - """ - - input_spec = HemisplitInputSpec - output_spec = HemisplitOutputSpec - _cmd = 'hemisplit' - - def _gen_filename(self, name): - inputs = self.inputs.get() - if isdefined(inputs[name]): - return os.path.abspath(inputs[name]) - - - if (name == 'outputLeftHemisphere' - or name == 'outputRightHemisphere' - or name == 'outputLeftPialHemisphere' - or name == 'outputRightPialHemisphere'): - return getFileName(self, self.inputs.inputSurfaceFile, name, '.dfs') - - return None - - def _list_outputs(self): - return l_outputs(self) - -# used to generate file names for outputs -# removes pathway and extension of inputName, returns concatenation of] -# inputName, command, name, and extension -def getFileName(self, inputName, name, extension): - fullInput = os.path.basename(inputName) - dotRegex = regex.compile("[^.]+") - inputNoExtension = dotRegex.findall(fullInput)[0] - return os.path.abspath( - ''.join((inputNoExtension, '_', self._cmd, '_', name, extension))) - -def l_outputs(self): - outputs = self.output_spec().get() - for key in outputs: - name = self._gen_filename(key) - if not name is None: - outputs[key] = name - - return outputs From 147117179c64a04df882811c3260575af5c4c26f Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 31 Mar 2016 11:43:40 -0700 Subject: [PATCH 19/25] add __init__.py --- nipype/interfaces/brainsuite/__init__.py | 2 ++ nipype/interfaces/brainsuite/tests/__init__.py | 0 2 files changed, 2 insertions(+) create mode 100644 nipype/interfaces/brainsuite/__init__.py create mode 100644 nipype/interfaces/brainsuite/tests/__init__.py diff --git a/nipype/interfaces/brainsuite/__init__.py b/nipype/interfaces/brainsuite/__init__.py new file mode 100644 index 0000000000..bf6a283f63 --- /dev/null +++ b/nipype/interfaces/brainsuite/__init__.py @@ -0,0 +1,2 @@ +from .brainsuite import (Bse, Bfc, Pvc, Cerebro, Cortex, Scrubmask, Tca, + Dewisp, Dfs, Pialmesh, Skullfinder, Hemisplit) diff --git a/nipype/interfaces/brainsuite/tests/__init__.py b/nipype/interfaces/brainsuite/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 From bc83e7153de3bdbbd065f333b730c806e3d1424b Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 1 Apr 2016 11:25:07 -0700 Subject: [PATCH 20/25] fixing for make specs --- nipype/interfaces/brainsuite/brainsuite.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nipype/interfaces/brainsuite/brainsuite.py b/nipype/interfaces/brainsuite/brainsuite.py index d49b8147a1..a849446203 100644 --- a/nipype/interfaces/brainsuite/brainsuite.py +++ b/nipype/interfaces/brainsuite/brainsuite.py @@ -371,7 +371,7 @@ class CortexInputSpec(CommandLineInputSpec): computeGCBoundary = traits.Bool( desc='compute GM/CSF boundary', argstr='-g') includeAllSubcorticalAreas = traits.Bool( - True, usedefault=True, esc='include all subcortical areas in WM mask', argstr='-a') + True, usedefault=True, desc='include all subcortical areas in WM mask', argstr='-a') verbosity = traits.Int(desc='verbosity level', argstr='-v %d') timer = traits.Bool(desc='timing function', argstr='--timer') @@ -885,4 +885,4 @@ def l_outputs(self): if not name is None: outputs[key] = name - return outputs + return outputs \ No newline at end of file From 9c12e4433124dccb8401ee359e9cb38798c92c55 Mon Sep 17 00:00:00 2001 From: Jason W Date: Mon, 4 Apr 2016 13:58:01 -0700 Subject: [PATCH 21/25] ran make specs and make check-before-commit --- nipype/interfaces/brainsuite/brainsuite.py | 68 +++++++------- .../brainsuite/tests/test_auto_Bfc.py | 89 +++++++++++++++++++ .../brainsuite/tests/test_auto_Bse.py | 84 +++++++++++++++++ .../brainsuite/tests/test_auto_Cerebro.py | 75 ++++++++++++++++ .../brainsuite/tests/test_auto_Cortex.py | 56 ++++++++++++ .../brainsuite/tests/test_auto_Dewisp.py | 46 ++++++++++ .../brainsuite/tests/test_auto_Dfs.py | 71 +++++++++++++++ .../brainsuite/tests/test_auto_Hemisplit.py | 59 ++++++++++++ .../brainsuite/tests/test_auto_Pialmesh.py | 78 ++++++++++++++++ .../brainsuite/tests/test_auto_Pvc.py | 52 +++++++++++ .../brainsuite/tests/test_auto_Scrubmask.py | 50 +++++++++++ .../brainsuite/tests/test_auto_Skullfinder.py | 61 +++++++++++++ .../brainsuite/tests/test_auto_Tca.py | 50 +++++++++++ 13 files changed, 805 insertions(+), 34 deletions(-) create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Bfc.py create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Bse.py create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Cerebro.py create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Cortex.py create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Dewisp.py create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Dfs.py create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Hemisplit.py create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Pialmesh.py create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Pvc.py create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Scrubmask.py create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Skullfinder.py create mode 100644 nipype/interfaces/brainsuite/tests/test_auto_Tca.py diff --git a/nipype/interfaces/brainsuite/brainsuite.py b/nipype/interfaces/brainsuite/brainsuite.py index a849446203..3d8234b380 100644 --- a/nipype/interfaces/brainsuite/brainsuite.py +++ b/nipype/interfaces/brainsuite/brainsuite.py @@ -66,18 +66,18 @@ class Bse(CommandLine): """ brain surface extractor (BSE) This program performs automated skull and scalp removal on T1-weighted MRI volumes. - + http://brainsuite.org/processing/surfaceextraction/bse/ - + Examples -------- - + >>> from nipype.interfaces import brainsuite >>> from nipype.testing import example_data >>> bse = brainsuite.Bse() >>> bse.inputs.inputMRIFile = example_data('structural.nii') >>> results = bse.run() #doctest: +SKIP - + """ input_spec = BseInputSpec @@ -178,17 +178,17 @@ class Bfc(CommandLine): This program corrects gain variation in T1-weighted MRI. http://brainsuite.org/processing/surfaceextraction/bfc/ - + Examples -------- - + >>> from nipype.interfaces import brainsuite >>> from nipype.testing import example_data >>> bfc = brainsuite.Bfc() >>> bfc.inputs.inputMRIFile = example_data('structural.nii') >>> bfc.inputs.inputMaskFile = example_data('mask.nii') >>> results = bfc.run() #doctest: +SKIP - + """ @@ -242,19 +242,19 @@ class Pvc(CommandLine): partial volume classifier (PVC) tool. This program performs voxel-wise tissue classification T1-weighted MRI. Image should be skull-stripped and bias-corrected before tissue classification. - + http://brainsuite.org/processing/surfaceextraction/pvc/ - + Examples -------- - + >>> from nipype.interfaces import brainsuite >>> from nipype.testing import example_data >>> pvc = brainsuite.Pvc() >>> pvc.inputs.inputMRIFile = example_data('structural.nii') >>> pvc.inputs.inputMaskFile = example_data('mask.nii') >>> results = pvc.run() #doctest: +SKIP - + """ input_spec = PvcInputSpec @@ -283,9 +283,9 @@ class CerebroInputSpec(CommandLineInputSpec): inputAtlasLabelFile = File( mandatory=True, desc='atlas labeling', argstr='--atlaslabels %s') inputBrainMaskFile = File(desc='brain mask file', argstr='-m %s') - outputCerebrumMaskFile = File(desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', + outputCerebrumMaskFile = File(desc='output cerebrum mask volume. If unspecified, output file name will be auto generated.', argstr='-o %s', genfile=True) - outputLabelMaskFile = File(desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', + outputLabelMaskFile = File(desc='output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.', argstr='-l %s', genfile=True) costFunction = traits.Int(2, usedefault=True, desc='0,1,2', argstr='-c %d') useCentroids = traits.Bool( @@ -336,9 +336,9 @@ class Cerebro(CommandLine): >>> cerebro.inputs.inputAtlasLabelFile = 'atlasLabels.img' >>> cerebro.inputs.inputBrainMaskFile = example_data('mask.nii') >>> results = cerebro.run() #doctest: +SKIP - + """ - + input_spec = CerebroInputSpec output_spec = CerebroOutputSpec _cmd = 'cerebro' @@ -397,7 +397,7 @@ class Cortex(CommandLine): >>> cortex.inputs.inputHemisphereLabelFile = example_data('mask.nii') >>> cortex.inputs.inputTissueFractionFile = example_data('tissues.nii.gz') >>> results = cortex.run() #doctest: +SKIP - + """ input_spec = CortexInputSpec @@ -451,7 +451,7 @@ class Scrubmask(CommandLine): >>> scrubmask = brainsuite.Scrubmask() >>> scrubmask.inputs.inputMaskFile = example_data('mask.nii') >>> results = scrubmask.run() #doctest: +SKIP - + """ input_spec = ScrubmaskInputSpec output_spec = ScrubmaskOutputSpec @@ -464,8 +464,8 @@ def _gen_filename(self, name): if name == 'outputMaskFile': return getFileName(self, self.inputs.inputMaskFile, name, '.nii.gz') - - + + return None def _list_outputs(self): @@ -497,7 +497,7 @@ class Tca(CommandLine): This program removes topological handles from a binary object. http://brainsuite.org/processing/surfaceextraction/tca/ - + Examples -------- >>> from nipype.interfaces import brainsuite @@ -505,7 +505,7 @@ class Tca(CommandLine): >>> tca = brainsuite.Tca() >>> tca.inputs.inputMaskFile = example_data('mask.nii') >>> results = tca.run() #doctest: +SKIP - + """ input_spec = TcaInputSpec output_spec = TcaOutputSpec @@ -551,7 +551,7 @@ class Dewisp(CommandLine): can be before it is considered part of the image. http://brainsuite.org/processing/surfaceextraction/dewisp/ - + Examples -------- @@ -560,9 +560,9 @@ class Dewisp(CommandLine): >>> dewisp = brainsuite.Dewisp() >>> dewisp.inputs.inputMaskFile = example_data('mask.nii') >>> results = dewisp.run() #doctest: +SKIP - + """ - + input_spec = DewispInputSpec output_spec = DewispOutputSpec _cmd = 'dewisp' @@ -703,9 +703,9 @@ class Pialmesh(CommandLine): """ pialmesh computes a pial surface model using an inner WM/GM mesh and a tissue fraction map. - + http://brainsuite.org/processing/surfaceextraction/pial/ - + Examples -------- @@ -716,9 +716,9 @@ class Pialmesh(CommandLine): >>> pialmesh.inputs.inputTissueFractionFile = 'frac_file.nii.gz' >>> pialmesh.inputs.inputMaskFile = example_data('mask.nii') >>> results = pialmesh.run() #doctest: +SKIP - + """ - + input_spec = PialmeshInputSpec output_spec = PialmeshOutputSpec _cmd = 'pialmesh' @@ -771,17 +771,17 @@ class SkullfinderOutputSpec(TraitedSpec): class Skullfinder(CommandLine): """ Skull and scalp segmentation algorithm. - + Examples -------- - + >>> from nipype.interfaces import brainsuite >>> from nipype.testing import example_data >>> skullfinder = brainsuite.Skullfinder() >>> skullfinder.inputs.inputMRIFile = example_data('structural.nii') >>> skullfinder.inputs.inputMaskFile = example_data('mask.nii') >>> results = skullfinder.run() #doctest: +SKIP - + """ input_spec = SkullfinderInputSpec output_spec = SkullfinderOutputSpec @@ -836,15 +836,15 @@ class Hemisplit(CommandLine): Examples -------- - + >>> from nipype.interfaces import brainsuite >>> from nipype.testing import example_data >>> hemisplit = brainsuite.Hemisplit() >>> hemisplit.inputs.inputSurfaceFile = 'input_surf.dfs' >>> hemisplit.inputs.inputHemisphereLabelFile = 'label.nii' >>> hemisplit.inputs.pialSurfaceFile = 'pial.dfs' - >>> results = hemisplit.run() #doctest: +SKIP - + >>> results = hemisplit.run() #doctest: +SKIP + """ input_spec = HemisplitInputSpec diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Bfc.py b/nipype/interfaces/brainsuite/tests/test_auto_Bfc.py new file mode 100644 index 0000000000..ed52f6275e --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Bfc.py @@ -0,0 +1,89 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Bfc + + +def test_Bfc_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + biasEstimateConvergenceThreshold=dict(argstr='--beps %f', + ), + biasEstimateSpacing=dict(argstr='-s %d', + ), + biasFieldEstimatesOutputPrefix=dict(argstr='--biasprefix %s', + ), + biasRange=dict(argstr='%s', + ), + controlPointSpacing=dict(argstr='-c %d', + ), + convergenceThreshold=dict(argstr='--eps %f', + ), + correctWholeVolume=dict(argstr='--extrapolate', + ), + correctedImagesOutputPrefix=dict(argstr='--prefix %s', + ), + correctionScheduleFile=dict(argstr='--schedule %s', + ), + environ=dict(nohash=True, + usedefault=True, + ), + histogramRadius=dict(argstr='-r %d', + ), + histogramType=dict(argstr='%s', + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + inputMRIFile=dict(argstr='-i %s', + mandatory=True, + ), + inputMaskFile=dict(argstr='-m %s', + hash_files=False, + ), + intermediate_file_type=dict(argstr='%s', + ), + iterativeMode=dict(argstr='--iterate', + ), + maxBias=dict(argstr='-U %f', + usedefault=True, + ), + minBias=dict(argstr='-L %f', + usedefault=True, + ), + outputBiasField=dict(argstr='--bias %s', + hash_files=False, + ), + outputMRIVolume=dict(argstr='-o %s', + genfile=True, + hash_files=False, + ), + outputMaskedBiasField=dict(argstr='--maskedbias %s', + hash_files=False, + ), + splineLambda=dict(argstr='-w %f', + ), + terminal_output=dict(nohash=True, + ), + timer=dict(argstr='--timer', + ), + verbosityLevel=dict(argstr='-v %d', + ), + ) + inputs = Bfc.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Bfc_outputs(): + output_map = dict(correctionScheduleFile=dict(), + outputBiasField=dict(), + outputMRIVolume=dict(), + outputMaskedBiasField=dict(), + ) + outputs = Bfc.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Bse.py b/nipype/interfaces/brainsuite/tests/test_auto_Bse.py new file mode 100644 index 0000000000..3a525a4451 --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Bse.py @@ -0,0 +1,84 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Bse + + +def test_Bse_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + diffusionConstant=dict(argstr='-d %f', + usedefault=True, + ), + diffusionIterations=dict(argstr='-n %d', + usedefault=True, + ), + dilateFinalMask=dict(argstr='-p', + usedefault=True, + ), + edgeDetectionConstant=dict(argstr='-s %f', + usedefault=True, + ), + environ=dict(nohash=True, + usedefault=True, + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + inputMRIFile=dict(argstr='-i %s', + mandatory=True, + ), + noRotate=dict(argstr='--norotate', + ), + outputCortexFile=dict(argstr='--cortex %s', + hash_files=False, + ), + outputDetailedBrainMask=dict(argstr='--hires %s', + hash_files=False, + ), + outputDiffusionFilter=dict(argstr='--adf %s', + hash_files=False, + ), + outputEdgeMap=dict(argstr='--edge %s', + hash_files=False, + ), + outputMRIVolume=dict(argstr='-o %s', + genfile=True, + hash_files=False, + ), + outputMaskFile=dict(argstr='--mask %s', + hash_files=False, + ), + radius=dict(argstr='-r %f', + usedefault=True, + ), + terminal_output=dict(nohash=True, + ), + timer=dict(argstr='--timer', + ), + trim=dict(argstr='--trim', + usedefault=True, + ), + verbosityLevel=dict(argstr='-v %f', + usedefault=True, + ), + ) + inputs = Bse.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Bse_outputs(): + output_map = dict(outputCortexFile=dict(), + outputDetailedBrainMask=dict(), + outputDiffusionFilter=dict(), + outputEdgeMap=dict(), + outputMRIVolume=dict(), + outputMaskFile=dict(), + ) + outputs = Bse.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Cerebro.py b/nipype/interfaces/brainsuite/tests/test_auto_Cerebro.py new file mode 100644 index 0000000000..869819133d --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Cerebro.py @@ -0,0 +1,75 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Cerebro + + +def test_Cerebro_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + costFunction=dict(argstr='-c %d', + usedefault=True, + ), + environ=dict(nohash=True, + usedefault=True, + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + inputAtlasLabelFile=dict(argstr='--atlaslabels %s', + mandatory=True, + ), + inputAtlasMRIFile=dict(argstr='--atlas %s', + mandatory=True, + ), + inputBrainMaskFile=dict(argstr='-m %s', + ), + inputMRIFile=dict(argstr='-i %s', + mandatory=True, + ), + keepTempFiles=dict(argstr='--keep', + ), + linearConvergence=dict(argstr='--linconv %f', + ), + outputAffineTransformFile=dict(argstr='--air %s', + ), + outputCerebrumMaskFile=dict(argstr='-o %s', + genfile=True, + ), + outputLabelMaskFile=dict(argstr='-l %s', + genfile=True, + ), + outputWarpTransformFile=dict(argstr='--warp %s', + ), + tempDirectory=dict(argstr='--tempdir %s', + ), + tempDirectoryBase=dict(argstr='--tempdirbase %s', + ), + terminal_output=dict(nohash=True, + ), + useCentroids=dict(argstr='--centroids', + ), + verbosity=dict(argstr='-v %d', + ), + warpConvergence=dict(argstr='--warpconv %f', + ), + warpLabel=dict(argstr='--warplevel %d', + ), + ) + inputs = Cerebro.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Cerebro_outputs(): + output_map = dict(outputAffineTransformFile=dict(), + outputCerebrumMaskFile=dict(), + outputLabelMaskFile=dict(), + outputWarpTransformFile=dict(), + ) + outputs = Cerebro.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Cortex.py b/nipype/interfaces/brainsuite/tests/test_auto_Cortex.py new file mode 100644 index 0000000000..982edf7ab0 --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Cortex.py @@ -0,0 +1,56 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Cortex + + +def test_Cortex_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + computeGCBoundary=dict(argstr='-g', + ), + computeWGBoundary=dict(argstr='-w', + usedefault=True, + ), + environ=dict(nohash=True, + usedefault=True, + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + includeAllSubcorticalAreas=dict(argstr='-a', + usedefault=True, + ), + inputHemisphereLabelFile=dict(argstr='-h %s', + mandatory=True, + ), + inputTissueFractionFile=dict(argstr='-f %s', + mandatory=True, + ), + outputCerebrumMask=dict(argstr='-o %s', + genfile=True, + ), + terminal_output=dict(nohash=True, + ), + timer=dict(argstr='--timer', + ), + tissueFractionThreshold=dict(argstr='-p %f', + usedefault=True, + ), + verbosity=dict(argstr='-v %d', + ), + ) + inputs = Cortex.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Cortex_outputs(): + output_map = dict(outputCerebrumMask=dict(), + ) + outputs = Cortex.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Dewisp.py b/nipype/interfaces/brainsuite/tests/test_auto_Dewisp.py new file mode 100644 index 0000000000..8e935cf53d --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Dewisp.py @@ -0,0 +1,46 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Dewisp + + +def test_Dewisp_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + environ=dict(nohash=True, + usedefault=True, + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + inputMaskFile=dict(argstr='-i %s', + mandatory=True, + ), + maximumIterations=dict(argstr='-n %d', + ), + outputMaskFile=dict(argstr='-o %s', + genfile=True, + ), + sizeThreshold=dict(argstr='-t %d', + ), + terminal_output=dict(nohash=True, + ), + timer=dict(argstr='--timer', + ), + verbosity=dict(argstr='-v %d', + ), + ) + inputs = Dewisp.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Dewisp_outputs(): + output_map = dict(outputMaskFile=dict(), + ) + outputs = Dewisp.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Dfs.py b/nipype/interfaces/brainsuite/tests/test_auto_Dfs.py new file mode 100644 index 0000000000..a49244d115 --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Dfs.py @@ -0,0 +1,71 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Dfs + + +def test_Dfs_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + curvatureWeighting=dict(argstr='-w %f', + usedefault=True, + ), + environ=dict(nohash=True, + usedefault=True, + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + inputShadingVolume=dict(argstr='-c %s', + ), + inputVolumeFile=dict(argstr='-i %s', + mandatory=True, + ), + noNormalsFlag=dict(argstr='--nonormals', + ), + nonZeroTessellation=dict(argstr='-nz', + xor=('nonZeroTessellation', 'specialTessellation'), + ), + outputSurfaceFile=dict(argstr='-o %s', + genfile=True, + ), + postSmoothFlag=dict(argstr='--postsmooth', + ), + scalingPercentile=dict(argstr='-f %f', + ), + smoothingConstant=dict(argstr='-a %f', + usedefault=True, + ), + smoothingIterations=dict(argstr='-n %d', + usedefault=True, + ), + specialTessellation=dict(argstr='%s', + position=-1, + requires=['tessellationThreshold'], + xor=('nonZeroTessellation', 'specialTessellation'), + ), + terminal_output=dict(nohash=True, + ), + tessellationThreshold=dict(argstr='%f', + ), + timer=dict(argstr='--timer', + ), + verbosity=dict(argstr='-v %d', + ), + zeroPadFlag=dict(argstr='-z', + ), + ) + inputs = Dfs.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Dfs_outputs(): + output_map = dict(outputSurfaceFile=dict(), + ) + outputs = Dfs.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Hemisplit.py b/nipype/interfaces/brainsuite/tests/test_auto_Hemisplit.py new file mode 100644 index 0000000000..ff73bac5f1 --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Hemisplit.py @@ -0,0 +1,59 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Hemisplit + + +def test_Hemisplit_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + environ=dict(nohash=True, + usedefault=True, + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + inputHemisphereLabelFile=dict(argstr='-l %s', + mandatory=True, + ), + inputSurfaceFile=dict(argstr='-i %s', + mandatory=True, + ), + outputLeftHemisphere=dict(argstr='--left %s', + genfile=True, + ), + outputLeftPialHemisphere=dict(argstr='-pl %s', + genfile=True, + ), + outputRightHemisphere=dict(argstr='--right %s', + genfile=True, + ), + outputRightPialHemisphere=dict(argstr='-pr %s', + genfile=True, + ), + pialSurfaceFile=dict(argstr='-p %s', + ), + terminal_output=dict(nohash=True, + ), + timer=dict(argstr='--timer', + ), + verbosity=dict(argstr='-v %d', + ), + ) + inputs = Hemisplit.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Hemisplit_outputs(): + output_map = dict(outputLeftHemisphere=dict(), + outputLeftPialHemisphere=dict(), + outputRightHemisphere=dict(), + outputRightPialHemisphere=dict(), + ) + outputs = Hemisplit.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Pialmesh.py b/nipype/interfaces/brainsuite/tests/test_auto_Pialmesh.py new file mode 100644 index 0000000000..b345930151 --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Pialmesh.py @@ -0,0 +1,78 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Pialmesh + + +def test_Pialmesh_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + environ=dict(nohash=True, + usedefault=True, + ), + exportPrefix=dict(argstr='--prefix %s', + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + inputMaskFile=dict(argstr='-m %s', + mandatory=True, + ), + inputSurfaceFile=dict(argstr='-i %s', + mandatory=True, + ), + inputTissueFractionFile=dict(argstr='-f %s', + mandatory=True, + ), + laplacianSmoothing=dict(argstr='--smooth %f', + usedefault=True, + ), + maxThickness=dict(argstr='--max %f', + usedefault=True, + ), + normalSmoother=dict(argstr='--nc %f', + usedefault=True, + ), + numIterations=dict(argstr='-n %d', + usedefault=True, + ), + outputInterval=dict(argstr='--interval %d', + usedefault=True, + ), + outputSurfaceFile=dict(argstr='-o %s', + genfile=True, + ), + recomputeNormals=dict(argstr='--norm', + ), + searchRadius=dict(argstr='-r %f', + usedefault=True, + ), + stepSize=dict(argstr='-s %f', + usedefault=True, + ), + tangentSmoother=dict(argstr='--tc %f', + ), + terminal_output=dict(nohash=True, + ), + timer=dict(argstr='--timer', + ), + tissueThreshold=dict(argstr='-t %f', + usedefault=True, + ), + verbosity=dict(argstr='-v %d', + ), + ) + inputs = Pialmesh.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Pialmesh_outputs(): + output_map = dict(outputSurfaceFile=dict(), + ) + outputs = Pialmesh.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Pvc.py b/nipype/interfaces/brainsuite/tests/test_auto_Pvc.py new file mode 100644 index 0000000000..b78920ae67 --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Pvc.py @@ -0,0 +1,52 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Pvc + + +def test_Pvc_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + environ=dict(nohash=True, + usedefault=True, + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + inputMRIFile=dict(argstr='-i %s', + mandatory=True, + ), + inputMaskFile=dict(argstr='-m %s', + ), + outputLabelFile=dict(argstr='-o %s', + genfile=True, + ), + outputTissueFractionFile=dict(argstr='-f %s', + genfile=True, + ), + spatialPrior=dict(argstr='-l %f', + ), + terminal_output=dict(nohash=True, + ), + threeClassFlag=dict(argstr='-3', + ), + timer=dict(argstr='--timer', + ), + verbosity=dict(argstr='-v %d', + ), + ) + inputs = Pvc.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Pvc_outputs(): + output_map = dict(outputLabelFile=dict(), + outputTissueFractionFile=dict(), + ) + outputs = Pvc.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Scrubmask.py b/nipype/interfaces/brainsuite/tests/test_auto_Scrubmask.py new file mode 100644 index 0000000000..aafee6e1c5 --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Scrubmask.py @@ -0,0 +1,50 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Scrubmask + + +def test_Scrubmask_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + backgroundFillThreshold=dict(argstr='-b %d', + usedefault=True, + ), + environ=dict(nohash=True, + usedefault=True, + ), + foregroundTrimThreshold=dict(argstr='-f %d', + usedefault=True, + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + inputMaskFile=dict(argstr='-i %s', + mandatory=True, + ), + numberIterations=dict(argstr='-n %d', + ), + outputMaskFile=dict(argstr='-o %s', + genfile=True, + ), + terminal_output=dict(nohash=True, + ), + timer=dict(argstr='--timer', + ), + verbosity=dict(argstr='-v %d', + ), + ) + inputs = Scrubmask.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Scrubmask_outputs(): + output_map = dict(outputMaskFile=dict(), + ) + outputs = Scrubmask.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Skullfinder.py b/nipype/interfaces/brainsuite/tests/test_auto_Skullfinder.py new file mode 100644 index 0000000000..6c685a5c05 --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Skullfinder.py @@ -0,0 +1,61 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Skullfinder + + +def test_Skullfinder_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + bgLabelValue=dict(argstr='--bglabel %d', + ), + brainLabelValue=dict(argstr='--brainlabel %d', + ), + environ=dict(nohash=True, + usedefault=True, + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + inputMRIFile=dict(argstr='-i %s', + mandatory=True, + ), + inputMaskFile=dict(argstr='-m %s', + mandatory=True, + ), + lowerThreshold=dict(argstr='-l %d', + ), + outputLabelFile=dict(argstr='-o %s', + genfile=True, + ), + performFinalOpening=dict(argstr='--finalOpening', + ), + scalpLabelValue=dict(argstr='--scalplabel %d', + ), + skullLabelValue=dict(argstr='--skulllabel %d', + ), + spaceLabelValue=dict(argstr='--spacelabel %d', + ), + surfaceFilePrefix=dict(argstr='-s %s', + ), + terminal_output=dict(nohash=True, + ), + upperThreshold=dict(argstr='-u %d', + ), + verbosity=dict(argstr='-v %d', + ), + ) + inputs = Skullfinder.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Skullfinder_outputs(): + output_map = dict(outputLabelFile=dict(), + ) + outputs = Skullfinder.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/interfaces/brainsuite/tests/test_auto_Tca.py b/nipype/interfaces/brainsuite/tests/test_auto_Tca.py new file mode 100644 index 0000000000..f314094f58 --- /dev/null +++ b/nipype/interfaces/brainsuite/tests/test_auto_Tca.py @@ -0,0 +1,50 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ....testing import assert_equal +from ..brainsuite import Tca + + +def test_Tca_inputs(): + input_map = dict(args=dict(argstr='%s', + ), + environ=dict(nohash=True, + usedefault=True, + ), + foregroundDelta=dict(argstr='--delta %d', + usedefault=True, + ), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + inputMaskFile=dict(argstr='-i %s', + mandatory=True, + ), + maxCorrectionSize=dict(argstr='-n %d', + ), + minCorrectionSize=dict(argstr='-m %d', + usedefault=True, + ), + outputMaskFile=dict(argstr='-o %s', + genfile=True, + ), + terminal_output=dict(nohash=True, + ), + timer=dict(argstr='--timer', + ), + verbosity=dict(argstr='-v %d', + ), + ) + inputs = Tca.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_Tca_outputs(): + output_map = dict(outputMaskFile=dict(), + ) + outputs = Tca.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value From 515c16e9dfb6e78934b24d50254415c88618440a Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 4 Apr 2016 14:09:01 -0700 Subject: [PATCH 22/25] additional files modified/added --- nipype/interfaces/tests/test_auto_DataSink.py | 6 --- .../interfaces/tests/test_auto_S3DataSink.py | 44 +++++++++++++++++++ .../outputs/text_file/datasink_test_s3.txt | 1 + 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 nipype/interfaces/tests/test_auto_S3DataSink.py create mode 100644 nipype/testing/data/outputs/text_file/datasink_test_s3.txt diff --git a/nipype/interfaces/tests/test_auto_DataSink.py b/nipype/interfaces/tests/test_auto_DataSink.py index 38cb7c1915..c49647f889 100644 --- a/nipype/interfaces/tests/test_auto_DataSink.py +++ b/nipype/interfaces/tests/test_auto_DataSink.py @@ -7,16 +7,10 @@ def test_DataSink_inputs(): input_map = dict(_outputs=dict(usedefault=True, ), base_directory=dict(), - bucket=dict(mandatory=False, - trait_value=True, - ), container=dict(), - creds_path=dict(), - encrypt_bucket_keys=dict(), ignore_exception=dict(nohash=True, usedefault=True, ), - local_copy=dict(), parameterization=dict(usedefault=True, ), regexp_substitutions=dict(), diff --git a/nipype/interfaces/tests/test_auto_S3DataSink.py b/nipype/interfaces/tests/test_auto_S3DataSink.py new file mode 100644 index 0000000000..9ef342defb --- /dev/null +++ b/nipype/interfaces/tests/test_auto_S3DataSink.py @@ -0,0 +1,44 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from ...testing import assert_equal +from ..io import S3DataSink + + +def test_S3DataSink_inputs(): + input_map = dict(_outputs=dict(usedefault=True, + ), + anon=dict(usedefault=True, + ), + base_directory=dict(), + bucket=dict(mandatory=True, + ), + bucket_path=dict(usedefault=True, + ), + container=dict(), + ignore_exception=dict(nohash=True, + usedefault=True, + ), + parameterization=dict(usedefault=True, + ), + regexp_substitutions=dict(), + remove_dest_dir=dict(usedefault=True, + ), + strip_dir=dict(), + substitutions=dict(), + testing=dict(usedefault=True, + ), + ) + inputs = S3DataSink.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(inputs.traits()[key], metakey), value + + +def test_S3DataSink_outputs(): + output_map = dict(out_file=dict(), + ) + outputs = S3DataSink.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + yield assert_equal, getattr(outputs.traits()[key], metakey), value diff --git a/nipype/testing/data/outputs/text_file/datasink_test_s3.txt b/nipype/testing/data/outputs/text_file/datasink_test_s3.txt new file mode 100644 index 0000000000..40e0d1cf44 --- /dev/null +++ b/nipype/testing/data/outputs/text_file/datasink_test_s3.txt @@ -0,0 +1 @@ +ABCD1234 \ No newline at end of file From 06dd50a0a5ba88cb5a87fde536fae29a2039a2cc Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 4 Apr 2016 14:48:54 -0700 Subject: [PATCH 23/25] deleted added files, reverted io.py and datasink test --- nipype/interfaces/io.py | 599 +++++++++++++----- nipype/interfaces/tests/test_auto_DataSink.py | 6 + 2 files changed, 456 insertions(+), 149 deletions(-) diff --git a/nipype/interfaces/io.py b/nipype/interfaces/io.py index ed5c0b5f9f..6f0ad3bc32 100644 --- a/nipype/interfaces/io.py +++ b/nipype/interfaces/io.py @@ -134,7 +134,54 @@ def _add_output_traits(self, base): return base +# Class to track percentage of S3 file upload +class ProgressPercentage(object): + ''' + Callable class instsance (via __call__ method) that displays + upload percentage of a file to S3 + ''' + + def __init__(self, filename): + ''' + ''' + + # Import packages + import threading + + # Initialize data attributes + self._filename = filename + self._size = float(os.path.getsize(filename)) + self._seen_so_far = 0 + self._lock = threading.Lock() + + def __call__(self, bytes_amount): + ''' + ''' + + # Import packages + import sys + + # With the lock on, print upload status + with self._lock: + self._seen_so_far += bytes_amount + if self._size != 0: + percentage = (self._seen_so_far / self._size) * 100 + else: + percentage = 0 + progress_str = '%d / %d (%.2f%%)\r'\ + % (self._seen_so_far, self._size, percentage) + + # Write to stdout + sys.stdout.write(progress_str) + sys.stdout.flush() + + +# DataSink inputs class DataSinkInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec): + ''' + ''' + + # Init inputspec data attributes base_directory = Directory( desc='Path to the base directory for storing data.') container = traits.Str( @@ -146,17 +193,32 @@ class DataSinkInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec): desc=('List of 2-tuples reflecting string ' 'to substitute and string to replace ' 'it with')) - regexp_substitutions = InputMultiPath(traits.Tuple(traits.Str, traits.Str), - desc=('List of 2-tuples reflecting a pair ' - 'of a Python regexp pattern and a ' - 'replacement string. Invoked after ' - 'string `substitutions`')) + regexp_substitutions = \ + InputMultiPath(traits.Tuple(traits.Str, traits.Str), + desc=('List of 2-tuples reflecting a pair of a '\ + 'Python regexp pattern and a replacement '\ + 'string. Invoked after string `substitutions`')) _outputs = traits.Dict(traits.Str, value={}, usedefault=True) remove_dest_dir = traits.Bool(False, usedefault=True, desc='remove dest directory when copying dirs') + # AWS S3 data attributes + creds_path = traits.Str(desc='Filepath to AWS credentials file for S3 bucket '\ + 'access; if not specified, the credentials will '\ + 'be taken from the AWS_ACCESS_KEY_ID and '\ + 'AWS_SECRET_ACCESS_KEY environment variables') + encrypt_bucket_keys = traits.Bool(desc='Flag indicating whether to use S3 '\ + 'server-side AES-256 encryption') + # Set this if user wishes to override the bucket with their own + bucket = traits.Generic(mandatory=False, + desc='Boto3 S3 bucket for manual override of bucket') + # Set this if user wishes to have local copy of files as well + local_copy = traits.Str(desc='Copy files locally as well as to S3 bucket') + + # Set call-able inputs attributes def __setattr__(self, key, value): + if key not in self.copyable_trait_names(): if not isdefined(value): super(DataSinkInputSpec, self).__setattr__(key, value) @@ -167,11 +229,14 @@ def __setattr__(self, key, value): super(DataSinkInputSpec, self).__setattr__(key, value) +# DataSink outputs class DataSinkOutputSpec(TraitedSpec): + # Init out file out_file = traits.Any(desc='datasink output') +# Custom DataSink class class DataSink(IOBase): """ Generic datasink module to store structured outputs @@ -233,9 +298,12 @@ class DataSink(IOBase): >>> ds.run() # doctest: +SKIP """ + + # Give obj .inputs and .outputs input_spec = DataSinkInputSpec output_spec = DataSinkOutputSpec + # Initialization method to set up datasink def __init__(self, infields=None, force_run=True, **kwargs): """ Parameters @@ -257,6 +325,7 @@ def __init__(self, infields=None, force_run=True, **kwargs): if force_run: self._always_run = True + # Get destination paths def _get_dst(self, src): # If path is directory with trailing os.path.sep, # then remove that for a more robust behavior @@ -280,6 +349,7 @@ def _get_dst(self, src): dst = dst[1:] return dst + # Substitute paths in substitutions dictionary parameter def _substitute(self, pathstr): pathstr_ = pathstr if isdefined(self.inputs.substitutions): @@ -300,50 +370,377 @@ def _substitute(self, pathstr): iflogger.info('sub: %s -> %s' % (pathstr_, pathstr)) return pathstr + # Check for s3 in base directory + def _check_s3_base_dir(self): + ''' + Method to see if the datasink's base directory specifies an + S3 bucket path; if it does, it parses the path for the bucket + name in the form 's3://bucket_name/...' and returns it + + Parameters + ---------- + + Returns + ------- + s3_flag : boolean + flag indicating whether the base_directory contained an + S3 bucket path + bucket_name : string + name of the S3 bucket to connect to; if the base directory + is not a valid S3 path, defaults to '' + ''' + + # Init variables + s3_str = 's3://' + bucket_name = '' + base_directory = self.inputs.base_directory + + if not isdefined(base_directory): + s3_flag = False + return s3_flag, bucket_name + + # Explicitly lower-case the "s3" + if base_directory.lower().startswith(s3_str): + base_dir_sp = base_directory.split('/') + base_dir_sp[0] = base_dir_sp[0].lower() + base_directory = '/'.join(base_dir_sp) + + # Check if 's3://' in base dir + if base_directory.startswith(s3_str): + # Expects bucket name to be 's3://bucket_name/base_dir/..' + bucket_name = base_directory.split(s3_str)[1].split('/')[0] + s3_flag = True + # Otherwise it's just a normal datasink + else: + s3_flag = False + + # Return s3_flag + return s3_flag, bucket_name + + # Function to return AWS secure environment variables + def _return_aws_keys(self): + ''' + Method to return AWS access key id and secret access key using + credentials found in a local file. + + Parameters + ---------- + self : nipype.interfaces.io.DataSink + self for instance method + + Returns + ------- + aws_access_key_id : string + string of the AWS access key ID + aws_secret_access_key : string + string of the AWS secret access key + ''' + + # Import packages + import os + + # Init variables + creds_path = self.inputs.creds_path + + # Check if creds exist + if creds_path and os.path.exists(creds_path): + with open(creds_path, 'r') as creds_in: + # Grab csv rows + row1 = creds_in.readline() + row2 = creds_in.readline() + + # Are they root or user keys + if 'User Name' in row1: + # And split out for keys + aws_access_key_id = row2.split(',')[1] + aws_secret_access_key = row2.split(',')[2] + elif 'AWSAccessKeyId' in row1: + # And split out for keys + aws_access_key_id = row1.split('=')[1] + aws_secret_access_key = row2.split('=')[1] + else: + err_msg = 'Credentials file not recognized, check file is correct' + raise Exception(err_msg) + + # Strip any carriage return/line feeds + aws_access_key_id = aws_access_key_id.replace('\r', '').replace('\n', '') + aws_secret_access_key = aws_secret_access_key.replace('\r', '').replace('\n', '') + else: + aws_access_key_id = os.getenv('AWS_ACCESS_KEY_ID') + aws_secret_access_key = os.getenv('AWS_SECRET_ACCESS_KEY') + + # Return keys + return aws_access_key_id, aws_secret_access_key + + # Fetch bucket object + def _fetch_bucket(self, bucket_name): + ''' + Method to return a bucket object which can be used to interact + with an AWS S3 bucket using credentials found in a local file. + + Parameters + ---------- + self : nipype.interfaces.io.DataSink + self for instance method + bucket_name : string + string corresponding to the name of the bucket on S3 + + Returns + ------- + bucket : boto3.resources.factory.s3.Bucket + boto3 s3 Bucket object which is used to interact with files + in an S3 bucket on AWS + ''' + + # Import packages + import logging + + try: + import boto3 + import botocore + except ImportError as exc: + err_msg = 'Boto3 package is not installed - install boto3 and '\ + 'try again.' + raise Exception(err_msg) + + # Init variables + creds_path = self.inputs.creds_path + iflogger = logging.getLogger('interface') + + # Get AWS credentials + try: + aws_access_key_id, aws_secret_access_key = \ + self._return_aws_keys() + except Exception as exc: + err_msg = 'There was a problem extracting the AWS credentials '\ + 'from the credentials file provided: %s. Error:\n%s'\ + % (creds_path, exc) + raise Exception(err_msg) + + # Try and get AWS credentials if a creds_path is specified + if aws_access_key_id and aws_secret_access_key: + # Init connection + iflogger.info('Connecting to S3 bucket: %s with credentials...'\ + % bucket_name) + # Use individual session for each instance of DataSink + # Better when datasinks are being used in multi-threading, see: + # http://boto3.readthedocs.org/en/latest/guide/resources.html#multithreading + session = boto3.session.Session(aws_access_key_id=aws_access_key_id, + aws_secret_access_key=aws_secret_access_key) + s3_resource = session.resource('s3', use_ssl=True) + + # Otherwise, connect anonymously + else: + iflogger.info('Connecting to AWS: %s anonymously...'\ + % bucket_name) + session = boto3.session.Session() + s3_resource = session.resource('s3', use_ssl=True) + s3_resource.meta.client.meta.events.register('choose-signer.s3.*', + botocore.handlers.disable_signing) + + # Explicitly declare a secure SSL connection for bucket object + bucket = s3_resource.Bucket(bucket_name) + + # And try fetch the bucket with the name argument + try: + s3_resource.meta.client.head_bucket(Bucket=bucket_name) + except botocore.exceptions.ClientError as exc: + error_code = int(exc.response['Error']['Code']) + if error_code == 403: + err_msg = 'Access to bucket: %s is denied; check credentials'\ + % bucket_name + raise Exception(err_msg) + elif error_code == 404: + err_msg = 'Bucket: %s does not exist; check spelling and try '\ + 'again' % bucket_name + raise Exception(err_msg) + else: + err_msg = 'Unable to connect to bucket: %s. Error message:\n%s'\ + % (bucket_name, exc) + except Exception as exc: + err_msg = 'Unable to connect to bucket: %s. Error message:\n%s'\ + % (bucket_name, exc) + raise Exception(err_msg) + + # Return the bucket + return bucket + + # Send up to S3 method + def _upload_to_s3(self, bucket, src, dst): + ''' + Method to upload outputs to S3 bucket instead of on local disk + ''' + + # Import packages + import hashlib + import logging + import os + + from botocore.exceptions import ClientError + + # Init variables + iflogger = logging.getLogger('interface') + s3_str = 's3://' + s3_prefix = s3_str + bucket.name + + # Explicitly lower-case the "s3" + if dst.lower().startswith(s3_str): + dst_sp = dst.split('/') + dst_sp[0] = dst_sp[0].lower() + dst = '/'.join(dst_sp) + + # If src is a directory, collect files (this assumes dst is a dir too) + if os.path.isdir(src): + src_files = [] + for root, dirs, files in os.walk(src): + src_files.extend([os.path.join(root, fil) for fil in files]) + # Make the dst files have the dst folder as base dir + dst_files = [os.path.join(dst, src_f.split(src)[1]) \ + for src_f in src_files] + else: + src_files = [src] + dst_files = [dst] + + # Iterate over src and copy to dst + for src_idx, src_f in enumerate(src_files): + # Get destination filename/keyname + dst_f = dst_files[src_idx] + dst_k = dst_f.replace(s3_prefix, '').lstrip('/') + + # See if same file is already up there + try: + dst_obj = bucket.Object(key=dst_k) + dst_md5 = dst_obj.e_tag.strip('"') + + # See if same file is already there + src_read = open(src_f, 'rb').read() + src_md5 = hashlib.md5(src_read).hexdigest() + # Move to next loop iteration + if dst_md5 == src_md5: + iflogger.info('File %s already exists on S3, skipping...' % dst_f) + continue + else: + iflogger.info('Overwriting previous S3 file...') + + except ClientError: + iflogger.info('New file to S3') + + # Copy file up to S3 (either encrypted or not) + iflogger.info('Uploading %s to S3 bucket, %s, as %s...'\ + % (src_f, bucket.name, dst_f)) + if self.inputs.encrypt_bucket_keys: + extra_args = {'ServerSideEncryption' : 'AES256'} + else: + extra_args = {} + bucket.upload_file(src_f, dst_k, ExtraArgs=extra_args, + Callback=ProgressPercentage(src_f)) + + # List outputs, main run routine def _list_outputs(self): """Execute this module. """ + + # Init variables + iflogger = logging.getLogger('interface') outputs = self.output_spec().get() out_files = [] - outdir = self.inputs.base_directory - if not isdefined(outdir): - outdir = '.' - outdir = os.path.abspath(outdir) + # Use hardlink + use_hardlink = str2bool(config.get('execution', 'try_hard_link_datasink')) + + # Set local output directory if specified + if isdefined(self.inputs.local_copy): + outdir = self.inputs.local_copy + else: + outdir = self.inputs.base_directory + # If base directory isn't given, assume current directory + if not isdefined(outdir): + outdir = '.' + + # Check if base directory reflects S3 bucket upload + s3_flag, bucket_name = self._check_s3_base_dir() + if s3_flag: + s3dir = self.inputs.base_directory + # If user overrides bucket object, use that + if self.inputs.bucket: + bucket = self.inputs.bucket + # Otherwise fetch bucket object using name + else: + try: + bucket = self._fetch_bucket(bucket_name) + # If encountering an exception during bucket access, set output + # base directory to a local folder + except Exception as exc: + s3dir = '' + if not isdefined(self.inputs.local_copy): + local_out_exception = os.path.join(os.path.expanduser('~'), + 's3_datasink_' + bucket_name) + outdir = local_out_exception + # Log local copying directory + iflogger.info('Access to S3 failed! Storing outputs locally at: '\ + '%s\nError: %s' %(outdir, exc)) + else: + s3dir = '' + + # If container input is given, append that to outdir if isdefined(self.inputs.container): outdir = os.path.join(outdir, self.inputs.container) - if not os.path.exists(outdir): - try: - os.makedirs(outdir) - except OSError as inst: - if 'File exists' in inst: - pass - else: - raise(inst) - use_hardlink = str2bool(config.get('execution', - 'try_hard_link_datasink')) - for key, files in list(self.inputs._outputs.items()): + s3dir = os.path.join(s3dir, self.inputs.container) + + # If sinking to local folder + if outdir != s3dir: + outdir = os.path.abspath(outdir) + # Create the directory if it doesn't exist + if not os.path.exists(outdir): + try: + os.makedirs(outdir) + except OSError as inst: + if 'File exists' in inst: + pass + else: + raise(inst) + + # Iterate through outputs attributes {key : path(s)} + for key, files in self.inputs._outputs.items(): if not isdefined(files): continue iflogger.debug("key: %s files: %s" % (key, str(files))) files = filename_to_list(files) tempoutdir = outdir + if s3_flag: + s3tempoutdir = s3dir for d in key.split('.'): if d[0] == '@': continue tempoutdir = os.path.join(tempoutdir, d) + if s3_flag: + s3tempoutdir = os.path.join(s3tempoutdir, d) # flattening list if isinstance(files, list): if isinstance(files[0], list): files = [item for sublist in files for item in sublist] + # Iterate through passed-in source files for src in filename_to_list(files): + # Format src and dst files src = os.path.abspath(src) - if os.path.isfile(src): - dst = self._get_dst(src) - dst = os.path.join(tempoutdir, dst) - dst = self._substitute(dst) - path, _ = os.path.split(dst) + if not os.path.isfile(src): + src = os.path.join(src, '') + dst = self._get_dst(src) + if s3_flag: + s3dst = os.path.join(s3tempoutdir, dst) + s3dst = self._substitute(s3dst) + dst = os.path.join(tempoutdir, dst) + dst = self._substitute(dst) + path, _ = os.path.split(dst) + + # If we're uploading to S3 + if s3_flag: + self._upload_to_s3(bucket, src, s3dst) + out_files.append(s3dst) + # Otherwise, copy locally src -> dst + if not s3_flag or isdefined(self.inputs.local_copy): + # Create output directory if it doesnt exist if not os.path.exists(path): try: os.makedirs(path) @@ -352,130 +749,31 @@ def _list_outputs(self): pass else: raise(inst) - iflogger.debug("copyfile: %s %s" % (src, dst)) - copyfile(src, dst, copy=True, hashmethod='content', - use_hardlink=use_hardlink) - out_files.append(dst) - elif os.path.isdir(src): - dst = self._get_dst(os.path.join(src, '')) - dst = os.path.join(tempoutdir, dst) - dst = self._substitute(dst) - path, _ = os.path.split(dst) - if not os.path.exists(path): - try: - os.makedirs(path) - except OSError as inst: - if 'File exists' in inst: - pass - else: - raise(inst) - if os.path.exists(dst) and self.inputs.remove_dest_dir: - iflogger.debug("removing: %s" % dst) - shutil.rmtree(dst) - iflogger.debug("copydir: %s %s" % (src, dst)) - copytree(src, dst) - out_files.append(dst) + # If src is a file, copy it to dst + if os.path.isfile(src): + iflogger.debug('copyfile: %s %s' % (src, dst)) + copyfile(src, dst, copy=True, hashmethod='content', + use_hardlink=use_hardlink) + out_files.append(dst) + # If src is a directory, copy entire contents to dst dir + elif os.path.isdir(src): + if os.path.exists(dst) and self.inputs.remove_dest_dir: + iflogger.debug('removing: %s' % dst) + shutil.rmtree(dst) + iflogger.debug('copydir: %s %s' % (src, dst)) + copytree(src, dst) + out_files.append(dst) + + # Return outputs dictionary outputs['out_file'] = out_files return outputs -class S3DataSinkInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec): - testing = traits.Bool(False, usedefault=True, - desc='Flag for using local fakes3 server.' - ' (for testing purposes only)') - anon = traits.Bool(False, usedefault=True, - desc='Use anonymous connection to s3') - bucket = traits.Str(mandatory=True, - desc='Amazon S3 bucket where your data is stored') - bucket_path = traits.Str('', usedefault=True, - desc='Location within your bucket to store ' - 'data.') - base_directory = Directory( - desc='Path to the base directory for storing data.') - container = traits.Str( - desc='Folder within base directory in which to store output') - parameterization = traits.Bool(True, usedefault=True, - desc='store output in parametrized structure') - strip_dir = Directory(desc='path to strip out of filename') - substitutions = InputMultiPath(traits.Tuple(traits.Str, traits.Str), - desc=('List of 2-tuples reflecting string ' - 'to substitute and string to replace ' - 'it with')) - regexp_substitutions = InputMultiPath(traits.Tuple(traits.Str, traits.Str), - desc=('List of 2-tuples reflecting a pair ' - 'of a Python regexp pattern and a ' - 'replacement string. Invoked after ' - 'string `substitutions`')) - - _outputs = traits.Dict(traits.Str, value={}, usedefault=True) - remove_dest_dir = traits.Bool(False, usedefault=True, - desc='remove dest directory when copying dirs') - - def __setattr__(self, key, value): - if key not in self.copyable_trait_names(): - if not isdefined(value): - super(S3DataSinkInputSpec, self).__setattr__(key, value) - self._outputs[key] = value - else: - if key in self._outputs: - self._outputs[key] = value - super(S3DataSinkInputSpec, self).__setattr__(key, value) - - -class S3DataSink(DataSink): - """ Works exactly like DataSink, except the specified files will - also be uploaded to Amazon S3 storage in the specified bucket - and location. 'bucket_path' is the s3 analog for - 'base_directory'. - - """ - input_spec = S3DataSinkInputSpec - - def _list_outputs(self): - """Execute this module. - """ - outputs = super(S3DataSink, self)._list_outputs() - - self.localtos3(outputs['out_file']) - - return outputs - - def localtos3(self, paths): - if self.inputs.testing: - conn = S3Connection(anon=True, is_secure=False, port=4567, - host='localhost', - calling_format=OrdinaryCallingFormat()) - - else: - conn = S3Connection(anon=self.inputs.anon) - bkt = conn.get_bucket(self.inputs.bucket) - s3paths = [] - - for path in paths: - # convert local path to s3 path - bd_index = path.find(self.inputs.base_directory) - if bd_index != -1: # base_directory is in path, maintain directory structure - s3path = path[bd_index + len(self.inputs.base_directory):] # cut out base directory - if s3path[0] == os.path.sep: - s3path = s3path[1:] - else: # base_directory isn't in path, simply place all files in bucket_path folder - s3path = os.path.split(path)[1] # take filename from path - s3path = os.path.join(self.inputs.bucket_path, s3path) - if s3path[-1] == os.path.sep: - s3path = s3path[:-1] - s3paths.append(s3path) - - k = boto.s3.key.Key(bkt) - k.key = s3path - k.set_contents_from_filename(path) - - return s3paths - - class S3DataGrabberInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec): anon = traits.Bool(False, usedefault=True, - desc='Use anonymous connection to s3') + desc='Use anonymous connection to s3. If this is set to True, boto may print' + + ' a urlopen error, but this does not prevent data from being downloaded.') region = traits.Str('us-east-1', usedefault=True, desc='Region of s3 bucket') bucket = traits.Str(mandatory=True, @@ -656,14 +954,17 @@ def _list_outputs(self): # Outputs are currently stored as locations on S3. # We must convert to the local location specified # and download the files. - for key in outputs: - if type(outputs[key]) == list: - paths = outputs[key] - for i in range(len(paths)): - path = paths[i] + for key,val in outputs.iteritems(): + #This will basically be either list-like or string-like: + #if it has the __iter__ attribute, it's list-like (list, + #tuple, numpy array) and we iterate through each of its + #values. If it doesn't, it's string-like (string, + #unicode), and we convert that value directly. + if hasattr(val,'__iter__'): + for i,path in enumerate(val): outputs[key][i] = self.s3tolocal(path, bkt) - elif type(outputs[key]) == str: - outputs[key] = self.s3tolocal(outputs[key], bkt) + else: + outputs[key] = self.s3tolocal(val, bkt) return outputs diff --git a/nipype/interfaces/tests/test_auto_DataSink.py b/nipype/interfaces/tests/test_auto_DataSink.py index c49647f889..38cb7c1915 100644 --- a/nipype/interfaces/tests/test_auto_DataSink.py +++ b/nipype/interfaces/tests/test_auto_DataSink.py @@ -7,10 +7,16 @@ def test_DataSink_inputs(): input_map = dict(_outputs=dict(usedefault=True, ), base_directory=dict(), + bucket=dict(mandatory=False, + trait_value=True, + ), container=dict(), + creds_path=dict(), + encrypt_bucket_keys=dict(), ignore_exception=dict(nohash=True, usedefault=True, ), + local_copy=dict(), parameterization=dict(usedefault=True, ), regexp_substitutions=dict(), From 68db637e61f87fd22a5fb1137312014f46ada272 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 4 Apr 2016 16:25:17 -0700 Subject: [PATCH 24/25] Update CHANGES, remove additional DataSink related file --- CHANGES | 2 +- .../interfaces/tests/test_auto_S3DataSink.py | 44 ------------------- 2 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 nipype/interfaces/tests/test_auto_S3DataSink.py diff --git a/CHANGES b/CHANGES index abe825748a..20193401ab 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,6 @@ Next release ============ - +* ENH: Created interface for BrainSuite Cortical Surface Extraction command line tools (https://github.com/nipy/nipype/pull/1305) * FIX: job execution on systems/approaches where locale is undefined (https://github.com/nipy/nipype/pull/1401) * FIX: Clean up byte/unicode issues using subprocess (https://github.com/nipy/nipype/pull/1394) * FIX: Prevent crash when tvtk is loaded - ETS_TOOLKIT=null (https://github.com/nipy/nipype/pull/973) diff --git a/nipype/interfaces/tests/test_auto_S3DataSink.py b/nipype/interfaces/tests/test_auto_S3DataSink.py deleted file mode 100644 index 9ef342defb..0000000000 --- a/nipype/interfaces/tests/test_auto_S3DataSink.py +++ /dev/null @@ -1,44 +0,0 @@ -# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT -from ...testing import assert_equal -from ..io import S3DataSink - - -def test_S3DataSink_inputs(): - input_map = dict(_outputs=dict(usedefault=True, - ), - anon=dict(usedefault=True, - ), - base_directory=dict(), - bucket=dict(mandatory=True, - ), - bucket_path=dict(usedefault=True, - ), - container=dict(), - ignore_exception=dict(nohash=True, - usedefault=True, - ), - parameterization=dict(usedefault=True, - ), - regexp_substitutions=dict(), - remove_dest_dir=dict(usedefault=True, - ), - strip_dir=dict(), - substitutions=dict(), - testing=dict(usedefault=True, - ), - ) - inputs = S3DataSink.input_spec() - - for key, metadata in list(input_map.items()): - for metakey, value in list(metadata.items()): - yield assert_equal, getattr(inputs.traits()[key], metakey), value - - -def test_S3DataSink_outputs(): - output_map = dict(out_file=dict(), - ) - outputs = S3DataSink.output_spec() - - for key, metadata in list(output_map.items()): - for metakey, value in list(metadata.items()): - yield assert_equal, getattr(outputs.traits()[key], metakey), value From 98fdb3d0f3a422206711e83fba588055fd15c181 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 4 Apr 2016 16:26:54 -0700 Subject: [PATCH 25/25] delete additional file --- nipype/testing/data/outputs/text_file/datasink_test_s3.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 nipype/testing/data/outputs/text_file/datasink_test_s3.txt diff --git a/nipype/testing/data/outputs/text_file/datasink_test_s3.txt b/nipype/testing/data/outputs/text_file/datasink_test_s3.txt deleted file mode 100644 index 40e0d1cf44..0000000000 --- a/nipype/testing/data/outputs/text_file/datasink_test_s3.txt +++ /dev/null @@ -1 +0,0 @@ -ABCD1234 \ No newline at end of file