Skip to content

Commit 04aa3c5

Browse files
jguillonsatra
authored andcommitted
[FIX/REF] Switch to new MRtrix3 labelconvert CL tool (#2441)
* Fix new MrTrix3 CL tool * Fix some tests * fix: empty out the file file contents not required for testing * Add back Mrtrix3 labelconfig interface * Apply suggestions
1 parent a40ed0b commit 04aa3c5

File tree

4 files changed

+149
-1
lines changed

4 files changed

+149
-1
lines changed

nipype/interfaces/mrtrix3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
from .preprocess import ResponseSD, ACTPrepareFSL, ReplaceFSwithFIRST
99
from .tracking import Tractography
1010
from .reconst import FitTensor, EstimateFOD
11-
from .connectivity import LabelConfig, BuildConnectome
11+
from .connectivity import LabelConfig, LabelConvert, BuildConnectome

nipype/interfaces/mrtrix3/connectivity.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,91 @@ def _list_outputs(self):
219219
outputs = self.output_spec().get()
220220
outputs['out_file'] = op.abspath(self.inputs.out_file)
221221
return outputs
222+
223+
224+
class LabelConvertInputSpec(CommandLineInputSpec):
225+
in_file = File(
226+
exists=True,
227+
argstr='%s',
228+
mandatory=True,
229+
position=-4,
230+
desc='input anatomical image')
231+
in_lut = File(
232+
exists=True,
233+
argstr='%s',
234+
mandatory=True,
235+
position=-3,
236+
desc='get information from '
237+
'a basic lookup table consisting of index / name pairs')
238+
in_config = File(
239+
exists=True,
240+
argstr='%s',
241+
position=-2,
242+
desc='connectome configuration file')
243+
out_file = File(
244+
'parcellation.mif',
245+
argstr='%s',
246+
mandatory=True,
247+
position=-1,
248+
usedefault=True,
249+
desc='output file after processing')
250+
spine = File(
251+
argstr='-spine %s',
252+
desc='provide a manually-defined '
253+
'segmentation of the base of the spine where the streamlines'
254+
' terminate, so that this can become a node in the connection'
255+
' matrix.')
256+
num_threads = traits.Int(
257+
argstr='-nthreads %d',
258+
desc='number of threads. if zero, the number'
259+
' of available cpus will be used',
260+
nohash=True)
261+
262+
263+
class LabelConvertOutputSpec(TraitedSpec):
264+
out_file = File(exists=True, desc='the output response file')
265+
266+
267+
class LabelConvert(MRTrix3Base):
268+
"""
269+
Re-configure parcellation to be incrementally defined.
270+
271+
Example
272+
-------
273+
274+
>>> import nipype.interfaces.mrtrix3 as mrt
275+
>>> labels = mrt.LabelConvert()
276+
>>> labels.inputs.in_file = 'aparc+aseg.nii'
277+
>>> labels.inputs.in_config = 'mrtrix3_labelconfig.txt'
278+
>>> labels.inputs.in_lut = 'FreeSurferColorLUT.txt'
279+
>>> labels.cmdline
280+
'labelconvert aparc+aseg.nii FreeSurferColorLUT.txt mrtrix3_labelconfig.txt parcellation.mif'
281+
>>> labels.run() # doctest: +SKIP
282+
"""
283+
284+
_cmd = 'labelconvert'
285+
input_spec = LabelConvertInputSpec
286+
output_spec = LabelConvertOutputSpec
287+
288+
def _parse_inputs(self, skip=None):
289+
if skip is None:
290+
skip = []
291+
292+
if not isdefined(self.inputs.in_config):
293+
from nipype.utils.filemanip import which
294+
path = which(self._cmd)
295+
if path is None:
296+
path = os.getenv(MRTRIX3_HOME, '/opt/mrtrix3')
297+
else:
298+
path = op.dirname(op.dirname(path))
299+
300+
self.inputs.in_config = op.join(
301+
path, 'src/dwi/tractography/connectomics/'
302+
'example_configs/fs_default.txt')
303+
304+
return super(LabelConvert, self)._parse_inputs(skip=skip)
305+
306+
def _list_outputs(self):
307+
outputs = self.output_spec().get()
308+
outputs['out_file'] = op.abspath(self.inputs.out_file)
309+
return outputs
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..connectivity import LabelConvert
4+
5+
6+
def test_LabelConvert_inputs():
7+
input_map = dict(
8+
args=dict(argstr='%s', ),
9+
environ=dict(
10+
nohash=True,
11+
usedefault=True,
12+
),
13+
ignore_exception=dict(
14+
deprecated='1.0.0',
15+
nohash=True,
16+
usedefault=True,
17+
),
18+
in_config=dict(
19+
argstr='%s',
20+
position=-2,
21+
),
22+
in_file=dict(
23+
argstr='%s',
24+
mandatory=True,
25+
position=-4,
26+
),
27+
in_lut=dict(
28+
argstr='%s',
29+
mandatory=True,
30+
position=-3,
31+
),
32+
num_threads=dict(
33+
argstr='-nthreads %d',
34+
nohash=True,
35+
),
36+
out_file=dict(
37+
argstr='%s',
38+
mandatory=True,
39+
position=-1,
40+
usedefault=True,
41+
),
42+
spine=dict(argstr='-spine %s', ),
43+
terminal_output=dict(
44+
deprecated='1.0.0',
45+
nohash=True,
46+
),
47+
)
48+
inputs = LabelConvert.input_spec()
49+
50+
for key, metadata in list(input_map.items()):
51+
for metakey, value in list(metadata.items()):
52+
assert getattr(inputs.traits()[key], metakey) == value
53+
def test_LabelConvert_outputs():
54+
output_map = dict(out_file=dict(), )
55+
outputs = LabelConvert.output_spec()
56+
57+
for key, metadata in list(output_map.items()):
58+
for metakey, value in list(metadata.items()):
59+
assert getattr(outputs.traits()[key], metakey) == value
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)