Skip to content

Commit eb4d8b4

Browse files
authored
Merge pull request #2585 from salma1601/fsl_slice
FSL slice
2 parents 0498267 + f69fc29 commit eb4d8b4

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

nipype/interfaces/fsl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
FLAMEO, ContrastMgr, MultipleRegressDesign, L2Model, SMM,
1515
MELODIC, SmoothEstimate, Cluster, Randomise, GLM)
1616
from .utils import (
17-
AvScale, Smooth, Merge, ExtractROI, Split, ImageMaths, ImageMeants,
17+
AvScale, Smooth, Slice, Merge, ExtractROI, Split, ImageMaths, ImageMeants,
1818
ImageStats, FilterRegressor, Overlay, Slicer, PlotTimeSeries,
1919
PlotMotionParams, ConvertXFM, SwapDimensions, PowerSpectrum, Reorient2Std,
2020
Complex, InvWarp, WarpUtils, ConvertWarp, WarpPoints, WarpPointsToStd,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..utils import Slice
4+
5+
6+
def test_Slice_inputs():
7+
input_map = dict(
8+
args=dict(argstr='%s', ),
9+
environ=dict(
10+
nohash=True,
11+
usedefault=True,
12+
),
13+
ignore_exception=dict(
14+
deprecated='1.0.0',
15+
nohash=True,
16+
usedefault=True,
17+
),
18+
in_file=dict(
19+
argstr='%s',
20+
copyfile=False,
21+
mandatory=True,
22+
position=0,
23+
),
24+
out_base_name=dict(
25+
argstr='%s',
26+
position=1,
27+
),
28+
output_type=dict(),
29+
terminal_output=dict(
30+
deprecated='1.0.0',
31+
nohash=True,
32+
),
33+
)
34+
inputs = Slice.input_spec()
35+
36+
for key, metadata in list(input_map.items()):
37+
for metakey, value in list(metadata.items()):
38+
assert getattr(inputs.traits()[key], metakey) == value
39+
def test_Slice_outputs():
40+
output_map = dict(out_files=dict(), )
41+
outputs = Slice.output_spec()
42+
43+
for key, metadata in list(output_map.items()):
44+
for metakey, value in list(metadata.items()):
45+
assert getattr(outputs.traits()[key], metakey) == value

nipype/interfaces/fsl/utils.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,68 @@ def _format_arg(self, name, trait_spec, value):
262262
return super(Smooth, self)._format_arg(name, trait_spec, value)
263263

264264

265+
class SliceInputSpec(FSLCommandInputSpec):
266+
in_file = File(exists=True, argstr="%s", position=0, mandatory=True,
267+
desc="input filename", copyfile=False)
268+
out_base_name = traits.Str(argstr="%s", position=1, desc="outputs prefix")
269+
270+
271+
class SliceOutputSpec(TraitedSpec):
272+
out_files = OutputMultiPath(File(exists=True))
273+
274+
275+
class Slice(FSLCommand):
276+
"""Use fslslice to split a 3D file into lots of 2D files (along z-axis).
277+
278+
279+
Examples
280+
--------
281+
282+
>>> from nipype.interfaces.fsl import Slice
283+
>>> slice = Slice()
284+
>>> slice.inputs.in_file = 'functional.nii'
285+
>>> slice.inputs.out_base_name = 'sl'
286+
>>> slice.cmdline
287+
'fslslice functional.nii sl'
288+
289+
290+
"""
291+
292+
_cmd = 'fslslice'
293+
input_spec = SliceInputSpec
294+
output_spec = SliceOutputSpec
295+
296+
def _list_outputs(self):
297+
"""Create a Bunch which contains all possible files generated
298+
by running the interface. Some files are always generated, others
299+
depending on which ``inputs`` options are set.
300+
301+
Returns
302+
-------
303+
304+
outputs : Bunch object
305+
Bunch object containing all possible files generated by
306+
interface object.
307+
308+
If None, file was not generated
309+
Else, contains path, filename of generated outputfile
310+
311+
"""
312+
outputs = self._outputs().get()
313+
ext = Info.output_type_to_ext(self.inputs.output_type)
314+
suffix = '_slice_*' + ext
315+
if isdefined(self.inputs.out_base_name):
316+
fname_template = os.path.abspath(
317+
self.inputs.out_base_name + suffix)
318+
else:
319+
fname_template = fname_presuffix(self.inputs.in_file,
320+
suffix=suffix, use_ext=False)
321+
322+
outputs['out_files'] = sorted(glob(fname_template))
323+
324+
return outputs
325+
326+
265327
class MergeInputSpec(FSLCommandInputSpec):
266328
in_files = traits.List(
267329
File(exists=True), argstr="%s", position=2, mandatory=True)

0 commit comments

Comments
 (0)