diff --git a/nipype/interfaces/fsl/__init__.py b/nipype/interfaces/fsl/__init__.py index b3302d65b3..e8f192f4f2 100644 --- a/nipype/interfaces/fsl/__init__.py +++ b/nipype/interfaces/fsl/__init__.py @@ -14,7 +14,7 @@ FLAMEO, ContrastMgr, MultipleRegressDesign, L2Model, SMM, MELODIC, SmoothEstimate, Cluster, Randomise, GLM) from .utils import ( - AvScale, Smooth, Merge, ExtractROI, Split, ImageMaths, ImageMeants, + AvScale, Smooth, Slice, Merge, ExtractROI, Split, ImageMaths, ImageMeants, ImageStats, FilterRegressor, Overlay, Slicer, PlotTimeSeries, PlotMotionParams, ConvertXFM, SwapDimensions, PowerSpectrum, Reorient2Std, Complex, InvWarp, WarpUtils, ConvertWarp, WarpPoints, WarpPointsToStd, diff --git a/nipype/interfaces/fsl/tests/test_auto_Slice.py b/nipype/interfaces/fsl/tests/test_auto_Slice.py new file mode 100644 index 0000000000..da2285a817 --- /dev/null +++ b/nipype/interfaces/fsl/tests/test_auto_Slice.py @@ -0,0 +1,45 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import Slice + + +def test_Slice_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + in_file=dict( + argstr='%s', + copyfile=False, + mandatory=True, + position=0, + ), + out_base_name=dict( + argstr='%s', + position=1, + ), + output_type=dict(), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = Slice.input_spec() + + for key, metadata in list(input_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(inputs.traits()[key], metakey) == value +def test_Slice_outputs(): + output_map = dict(out_files=dict(), ) + outputs = Slice.output_spec() + + for key, metadata in list(output_map.items()): + for metakey, value in list(metadata.items()): + assert getattr(outputs.traits()[key], metakey) == value diff --git a/nipype/interfaces/fsl/utils.py b/nipype/interfaces/fsl/utils.py index 53579a0927..e237124bb3 100644 --- a/nipype/interfaces/fsl/utils.py +++ b/nipype/interfaces/fsl/utils.py @@ -262,6 +262,68 @@ def _format_arg(self, name, trait_spec, value): return super(Smooth, self)._format_arg(name, trait_spec, value) +class SliceInputSpec(FSLCommandInputSpec): + in_file = File(exists=True, argstr="%s", position=0, mandatory=True, + desc="input filename", copyfile=False) + out_base_name = traits.Str(argstr="%s", position=1, desc="outputs prefix") + + +class SliceOutputSpec(TraitedSpec): + out_files = OutputMultiPath(File(exists=True)) + + +class Slice(FSLCommand): + """Use fslslice to split a 3D file into lots of 2D files (along z-axis). + + + Examples + -------- + + >>> from nipype.interfaces.fsl import Slice + >>> slice = Slice() + >>> slice.inputs.in_file = 'functional.nii' + >>> slice.inputs.out_base_name = 'sl' + >>> slice.cmdline + 'fslslice functional.nii sl' + + + """ + + _cmd = 'fslslice' + input_spec = SliceInputSpec + output_spec = SliceOutputSpec + + def _list_outputs(self): + """Create a Bunch which contains all possible files generated + by running the interface. Some files are always generated, others + depending on which ``inputs`` options are set. + + Returns + ------- + + outputs : Bunch object + Bunch object containing all possible files generated by + interface object. + + If None, file was not generated + Else, contains path, filename of generated outputfile + + """ + outputs = self._outputs().get() + ext = Info.output_type_to_ext(self.inputs.output_type) + suffix = '_slice_*' + ext + if isdefined(self.inputs.out_base_name): + fname_template = os.path.abspath( + self.inputs.out_base_name + suffix) + else: + fname_template = fname_presuffix(self.inputs.in_file, + suffix=suffix, use_ext=False) + + outputs['out_files'] = sorted(glob(fname_template)) + + return outputs + + class MergeInputSpec(FSLCommandInputSpec): in_files = traits.List( File(exists=True), argstr="%s", position=2, mandatory=True)