Skip to content

FSL slice #2585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nipype/interfaces/fsl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 45 additions & 0 deletions nipype/interfaces/fsl/tests/test_auto_Slice.py
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions nipype/interfaces/fsl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down