Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -228,3 +228,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.')
nthreads = traits.Int(
Copy link
Member

@effigies effigies Mar 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be num_threads, to help nipype automatically do resource management.

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 # doctest: +ELLIPSIS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ellipsis in the cmdline, so I think we can drop the doctest directive here.

'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 distutils.spawn import find_executable
path = find_executable(self._cmd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're looking at dropping the distutils dependency (#2348). Can you use nipype.utils.filemanip.which instead?

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,
),
nthreads=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 @@