-
Notifications
You must be signed in to change notification settings - Fork 536
[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
Changes from 7 commits
e8509b3
60175a3
0728350
a8ee66c
bd009d0
2ea4c3e
ab6c552
40c4c04
6f4c68b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
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 | ||
|
||
'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) | ||
|
||
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 |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.