Skip to content

Commit f1ebe41

Browse files
committed
adding interface fsl.Slice
1 parent 53e0662 commit f1ebe41

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

nipype/interfaces/fsl/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
from .model import (Level1Design, FEAT, FEATModel, FILMGLS, FEATRegister,
1414
FLAMEO, ContrastMgr, MultipleRegressDesign, L2Model, SMM,
1515
MELODIC, SmoothEstimate, Cluster, Randomise, GLM)
16-
from .utils import (
17-
AvScale, Smooth, Merge, ExtractROI, Split, ImageMaths, ImageMeants,
18-
ImageStats, FilterRegressor, Overlay, Slicer, PlotTimeSeries,
19-
PlotMotionParams, ConvertXFM, SwapDimensions, PowerSpectrum, Reorient2Std,
20-
Complex, InvWarp, WarpUtils, ConvertWarp, WarpPoints, WarpPointsToStd,
21-
WarpPointsFromStd, RobustFOV, CopyGeom, MotionOutliers)
16+
from .utils import (AvScale, Smooth, Merge, ExtractROI, Split, ImageMaths, ImageMeants,
17+
ImageStats, FilterRegressor, Overlay, Slicer, Slice,
18+
PlotTimeSeries, PlotMotionParams, ConvertXFM,
19+
SwapDimensions, PowerSpectrum, Reorient2Std,
20+
Complex, InvWarp, WarpUtils, ConvertWarp, WarpPoints,
21+
WarpPointsToStd, WarpPointsFromStd, RobustFOV,
22+
CopyGeom, MotionOutliers)
2223

2324
from .epi import (PrepareFieldmap, TOPUP, ApplyTOPUP, Eddy, EPIDeWarp, SigLoss,
2425
EddyCorrect, EpiReg)

nipype/interfaces/fsl/utils.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,70 @@ 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")
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+
if isdefined(self.inputs.out_base_name):
315+
outbase = self.inputs.out_base_name + '_slice_*'
316+
out_dir = os.getcwd()
317+
else:
318+
out_dir = os.path.dirname(self.inputs.in_file)
319+
in_base, _ = os.path.splitext(self.inputs.in_file)
320+
if '.gz' in self.inputs.in_file:
321+
in_base, _ = os.path.splitext(in_base)
322+
323+
outbase = in_base + '_slice*'
324+
outputs['out_files'] = sorted(glob(os.path.join(out_dir,
325+
outbase + ext)))
326+
return outputs
327+
328+
265329
class MergeInputSpec(FSLCommandInputSpec):
266330
in_files = traits.List(
267331
File(exists=True), argstr="%s", position=2, mandatory=True)

0 commit comments

Comments
 (0)