diff --git a/nipype/interfaces/mrtrix3/__init__.py b/nipype/interfaces/mrtrix3/__init__.py index 53bc8f5f53..cd0f2580ab 100644 --- a/nipype/interfaces/mrtrix3/__init__.py +++ b/nipype/interfaces/mrtrix3/__init__.py @@ -8,4 +8,4 @@ from .preprocess import ResponseSD, ACTPrepareFSL, ReplaceFSwithFIRST from .tracking import Tractography from .reconst import FitTensor, EstimateFOD -from .connectivity import LabelConfig, BuildConnectome +from .connectivity import LabelConfig, LabelConvert, BuildConnectome diff --git a/nipype/interfaces/mrtrix3/connectivity.py b/nipype/interfaces/mrtrix3/connectivity.py index 67e602df84..0e246c796b 100644 --- a/nipype/interfaces/mrtrix3/connectivity.py +++ b/nipype/interfaces/mrtrix3/connectivity.py @@ -219,3 +219,91 @@ def _list_outputs(self): outputs = self.output_spec().get() outputs['out_file'] = op.abspath(self.inputs.out_file) return outputs + + +class LabelConvertInputSpec(CommandLineInputSpec): + in_file = File( + exists=True, + argstr='%s', + mandatory=True, + position=-4, + desc='input anatomical image') + in_lut = File( + exists=True, + argstr='%s', + mandatory=True, + position=-3, + desc='get information from ' + 'a basic lookup table consisting of index / name pairs') + in_config = File( + exists=True, + argstr='%s', + position=-2, + desc='connectome configuration file') + out_file = File( + 'parcellation.mif', + argstr='%s', + mandatory=True, + position=-1, + usedefault=True, + desc='output file after processing') + spine = File( + argstr='-spine %s', + desc='provide a manually-defined ' + 'segmentation of the base of the spine where the streamlines' + ' terminate, so that this can become a node in the connection' + ' matrix.') + num_threads = traits.Int( + argstr='-nthreads %d', + desc='number of threads. if zero, the number' + ' of available cpus will be used', + nohash=True) + + +class LabelConvertOutputSpec(TraitedSpec): + out_file = File(exists=True, desc='the output response file') + + +class LabelConvert(MRTrix3Base): + """ + Re-configure parcellation to be incrementally defined. + + Example + ------- + + >>> import nipype.interfaces.mrtrix3 as mrt + >>> labels = mrt.LabelConvert() + >>> labels.inputs.in_file = 'aparc+aseg.nii' + >>> labels.inputs.in_config = 'mrtrix3_labelconfig.txt' + >>> labels.inputs.in_lut = 'FreeSurferColorLUT.txt' + >>> labels.cmdline + 'labelconvert aparc+aseg.nii FreeSurferColorLUT.txt mrtrix3_labelconfig.txt parcellation.mif' + >>> labels.run() # doctest: +SKIP + """ + + _cmd = 'labelconvert' + input_spec = LabelConvertInputSpec + output_spec = LabelConvertOutputSpec + + def _parse_inputs(self, skip=None): + if skip is None: + skip = [] + + if not isdefined(self.inputs.in_config): + from nipype.utils.filemanip import which + path = which(self._cmd) + if path is None: + path = os.getenv(MRTRIX3_HOME, '/opt/mrtrix3') + else: + path = op.dirname(op.dirname(path)) + + self.inputs.in_config = op.join( + path, 'src/dwi/tractography/connectomics/' + 'example_configs/fs_default.txt') + + return super(LabelConvert, self)._parse_inputs(skip=skip) + + def _list_outputs(self): + outputs = self.output_spec().get() + outputs['out_file'] = op.abspath(self.inputs.out_file) + return outputs diff --git a/nipype/interfaces/mrtrix3/tests/test_auto_LabelConvert.py b/nipype/interfaces/mrtrix3/tests/test_auto_LabelConvert.py new file mode 100644 index 0000000000..693dd0ea93 --- /dev/null +++ b/nipype/interfaces/mrtrix3/tests/test_auto_LabelConvert.py @@ -0,0 +1,59 @@ +# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT +from __future__ import unicode_literals +from ..connectivity import LabelConvert + + +def test_LabelConvert_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_config=dict( + argstr='%s', + position=-2, + ), + in_file=dict( + argstr='%s', + mandatory=True, + position=-4, + ), + in_lut=dict( + argstr='%s', + mandatory=True, + position=-3, + ), + num_threads=dict( + argstr='-nthreads %d', + nohash=True, + ), + out_file=dict( + argstr='%s', + mandatory=True, + position=-1, + usedefault=True, + ), + spine=dict(argstr='-spine %s', ), + terminal_output=dict( + deprecated='1.0.0', + nohash=True, + ), + ) + inputs = LabelConvert.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_LabelConvert_outputs(): + output_map = dict(out_file=dict(), ) + outputs = LabelConvert.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/testing/data/FreeSurferColorLUT.txt b/nipype/testing/data/FreeSurferColorLUT.txt new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/nipype/testing/data/FreeSurferColorLUT.txt @@ -0,0 +1 @@ +