Skip to content

Commit f03d224

Browse files
committed
add tck2connectome interface
1 parent 3e326f1 commit f03d224

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

nipype/interfaces/mrtrix3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
from preprocess import ResponseSD, ACTPrepareFSL, ReplaceFSwithFIRST
77
from tracking import Tractography
88
from reconst import FitTensor, EstimateFOD
9-
from connectivity import LabelConfig
9+
from connectivity import LabelConfig, BuildConnectome

nipype/interfaces/mrtrix3/connectivity.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,114 @@
2222
from nipype.interfaces.traits_extension import isdefined
2323

2424

25+
class BuildConnectomeInputSpec(CommandLineInputSpec):
26+
in_file = File(exists=True, argstr='%s', mandatory=True, position=-3,
27+
desc='input tractography')
28+
in_parc = File(exists=True, argstr='%s', position=-2,
29+
desc='parcellation file')
30+
out_file = File(
31+
'connectome.csv', argstr='%s', mandatory=True, position=-1,
32+
usedefault=True, desc='output file after processing')
33+
34+
nthreads = traits.Int(
35+
argstr='-nthreads %d', desc='number of threads. if zero, the number'
36+
' of available cpus will be used')
37+
38+
vox_lookup = traits.Bool(
39+
argstr='-assignment_voxel_lookup',
40+
desc='use a simple voxel lookup value at each streamline endpoint')
41+
search_radius = traits.Float(
42+
argstr='-assignment_radial_search %f',
43+
desc='perform a radial search from each streamline endpoint to locate '
44+
'the nearest node. Argument is the maximum radius in mm; if no node is'
45+
' found within this radius, the streamline endpoint is not assigned to'
46+
' any node.')
47+
search_reverse = traits.Float(
48+
argstr='-assignment_reverse_search %f',
49+
desc='traverse from each streamline endpoint inwards along the '
50+
'streamline, in search of the last node traversed by the streamline. '
51+
'Argument is the maximum traversal length in mm (set to 0 to allow '
52+
'search to continue to the streamline midpoint).')
53+
search_forward = traits.Float(
54+
argstr='-assignment_forward_search %f',
55+
desc='project the streamline forwards from the endpoint in search of a'
56+
'parcellation node voxel. Argument is the maximum traversal length in '
57+
'mm.')
58+
59+
metric = traits.Enum(
60+
'count', 'meanlength', 'invlength', 'invnodevolume', 'mean_scalar',
61+
'invlength_invnodevolume', argstr='-metric %s', desc='specify the edge'
62+
' weight metric')
63+
64+
in_scalar = File(
65+
exists=True, argstr='-image %s', desc='provide the associated image '
66+
'for the mean_scalar metric')
67+
68+
in_weights = File(
69+
exists=True, argstr='-tck_weights_in %s', desc='specify a text scalar '
70+
'file containing the streamline weights')
71+
72+
keep_unassigned = traits.Bool(
73+
argstr='-keep_unassigned', desc='By default, the program discards the'
74+
' information regarding those streamlines that are not successfully '
75+
'assigned to a node pair. Set this option to keep these values (will '
76+
'be the first row/column in the output matrix)')
77+
zero_diagonal = traits.Bool(
78+
argstr='-zero_diagonal', desc='set all diagonal entries in the matrix '
79+
'to zero (these represent streamlines that connect to the same node at'
80+
' both ends)')
81+
82+
83+
class BuildConnectomeOutputSpec(TraitedSpec):
84+
out_file = File(exists=True, desc='the output response file')
85+
86+
87+
class BuildConnectome(MRTrix3Base):
88+
89+
"""
90+
Generate a connectome matrix from a streamlines file and a node
91+
parcellation image
92+
93+
Example
94+
-------
95+
96+
>>> import nipype.interfaces.mrtrix3 as mrt
97+
>>> mat = mrt.BuildConnectome()
98+
>>> mat.inputs.in_file = 'aparc+aseg.nii.gz'
99+
>>> mat.inputs.in_config = 'mrtrix3_labelconfig.txt'
100+
>>> mat.cmdline # doctest: +ELLIPSIS
101+
'labelconfig aparc+aseg.nii.gz mrtrix3_labelconfig.txt parcellation.mif'
102+
>>> mat.run() # doctest: +SKIP
103+
"""
104+
105+
_cmd = 'labelconfig'
106+
input_spec = BuildConnectomeInputSpec
107+
output_spec = BuildConnectomeOutputSpec
108+
109+
def _parse_inputs(self, skip=None):
110+
if skip is None:
111+
skip = []
112+
113+
if not isdefined(self.inputs.in_config):
114+
from distutils.spawn import find_executable
115+
path = find_executable(self._cmd)
116+
if path is None:
117+
path = os.getenv(MRTRIX3_HOME, '/opt/mrtrix3')
118+
else:
119+
path = op.dirname(op.dirname(path))
120+
121+
self.inputs.in_config = op.join(
122+
path, 'src/dwi/tractography/connectomics/'
123+
'example_configs/fs_default.txt')
124+
125+
return super(BuildConnectome, self)._parse_inputs(skip=skip)
126+
127+
def _list_outputs(self):
128+
outputs = self.output_spec().get()
129+
outputs['out_file'] = op.abspath(self.inputs.out_file)
130+
return outputs
131+
132+
25133
class LabelConfigInputSpec(CommandLineInputSpec):
26134
in_file = File(exists=True, argstr='%s', mandatory=True, position=-3,
27135
desc='input anatomical image')

0 commit comments

Comments
 (0)