Skip to content

[FIX/REF] Switch to new MRtrix3 labelconvert CL tool #2441

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 9 commits into from
Mar 9, 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/mrtrix3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
88 changes: 88 additions & 0 deletions nipype/interfaces/mrtrix3/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
59 changes: 59 additions & 0 deletions nipype/interfaces/mrtrix3/tests/test_auto_LabelConvert.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions nipype/testing/data/FreeSurferColorLUT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@