diff --git a/nipype/interfaces/ants/__init__.py b/nipype/interfaces/ants/__init__.py index 5ce3da60a3..e1970912cf 100644 --- a/nipype/interfaces/ants/__init__.py +++ b/nipype/interfaces/ants/__init__.py @@ -23,4 +23,4 @@ # Utility Programs from .utils import (AverageAffineTransform, AverageImages, MultiplyImages, CreateJacobianDeterminantImage, AffineInitializer, - ComposeMultiTransform) + ComposeMultiTransform, LabelGeometry) diff --git a/nipype/interfaces/ants/tests/test_auto_LabelGeometry.py b/nipype/interfaces/ants/tests/test_auto_LabelGeometry.py new file mode 100644 index 0000000000..1a8ef63f44 --- /dev/null +++ b/nipype/interfaces/ants/tests/test_auto_LabelGeometry.py @@ -0,0 +1,60 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..utils import LabelGeometry + + +def test_LabelGeometry_inputs(): + input_map = dict( + args=dict(argstr='%s', ), + dimension=dict( + argstr='%d', + position=0, + usedefault=True, + ), + environ=dict( + nohash=True, + usedefault=True, + ), + ignore_exception=dict( + deprecated='1.0.0', + nohash=True, + usedefault=True, + ), + intensity_image=dict( + argstr='%s', + mandatory=True, + position=2, + usedefault=True, + ), + label_image=dict( + argstr='%s', + mandatory=True, + position=1, + ), + num_threads=dict( + nohash=True, + usedefault=True, + ), + output_file=dict( + argstr='%s', + name_source=['label_image'], + name_template='%s.csv', + position=3, + ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = LabelGeometry.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_LabelGeometry_outputs(): + output_map = dict(output_file=dict(), ) + outputs = LabelGeometry.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/ants/utils.py b/nipype/interfaces/ants/utils.py index 932d852133..5d284b89c0 100644 --- a/nipype/interfaces/ants/utils.py +++ b/nipype/interfaces/ants/utils.py @@ -357,3 +357,60 @@ class ComposeMultiTransform(ANTSCommand): _cmd = 'ComposeMultiTransform' input_spec = ComposeMultiTransformInputSpec output_spec = ComposeMultiTransformOutputSpec + + +class LabelGeometryInputSpec(ANTSCommandInputSpec): + dimension = traits.Enum( + 3, + 2, + argstr='%d', + usedefault=True, + position=0, + desc='image dimension (2 or 3)') + label_image = File( + argstr='%s', + position=1, + mandatory=True, + desc='label image to use for extracting geometry measures') + intensity_image = File( + value='[]', + exists=True, + argstr='%s', + mandatory=True, + usedefault=True, + position=2, + desc='Intensity image to extract values from. ' + 'This is an optional input') + output_file = traits.Str( + name_source=['label_image'], + name_template='%s.csv', + argstr='%s', + position=3, + desc='name of output file') + + +class LabelGeometryOutputSpec(TraitedSpec): + output_file = File(exists=True, desc='CSV file of geometry measures') + + +class LabelGeometry(ANTSCommand): + """ + Extracts geometry measures using a label file and an optional image file + + Examples + -------- + >>> from nipype.interfaces.ants import LabelGeometry + >>> label_extract = LabelGeometry() + >>> label_extract.inputs.dimension = 3 + >>> label_extract.inputs.label_image = 'atlas.nii.gz' + >>> label_extract.cmdline + 'LabelGeometryMeasures 3 atlas.nii.gz [] atlas.csv' + + >>> label_extract.inputs.intensity_image = 'ants_Warp.nii.gz' + >>> label_extract.cmdline + 'LabelGeometryMeasures 3 atlas.nii.gz ants_Warp.nii.gz atlas.csv' + + """ + _cmd = 'LabelGeometryMeasures' + input_spec = LabelGeometryInputSpec + output_spec = LabelGeometryOutputSpec