Skip to content

Commit 89e55ac

Browse files
committed
Merge remote-tracking branch 'origin/pr/848'
Conflicts: CHANGES
2 parents 868c329 + dfc8453 commit 89e55ac

File tree

12 files changed

+228
-5
lines changed

12 files changed

+228
-5
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Next Release
1414
* ENH: Support for elastix via a set of new interfaces: Registration, ApplyWarp,
1515
AnalyzeWarp, PointsWarp, and EditTransform
1616
* ENH: New ANTs interface: ApplyTransformsToPoints, LaplacianThickness
17+
* ENH: New Diffusion Toolkit interface: TrackMerge
18+
* ENH: New MRtrix interface: FilterTracks
1719
* ENH: New metrics group in algorithms. Now Distance, Overlap, and FuzzyOverlap
1820
are found in nipype.algorithms.metrics instead of misc
1921
* ENH: New interface in algorithms.metrics: ErrorMap (a voxel-wise diff map).
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .base import Info
2-
from .postproc import SplineFilter
2+
from .postproc import SplineFilter, TrackMerge
33
from .dti import DTIRecon, DTITracker
44
from .odf import HARDIMat, ODFRecon, ODFTracker

nipype/interfaces/diffusion_toolkit/postproc.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
__docformat__ = 'restructuredtext'
1414

1515
from nipype.interfaces.base import (TraitedSpec, File, traits, CommandLine,
16-
CommandLineInputSpec)
16+
InputMultiPath, CommandLineInputSpec)
1717

1818
class SplineFilterInputSpec(CommandLineInputSpec):
1919
track_file = File(exists=True, desc="file containing tracks to be filtered", position=0, argstr="%s", mandatory=True)
@@ -24,6 +24,23 @@ class SplineFilterOutputSpec(TraitedSpec):
2424
smoothed_track_file = File(exists=True)
2525

2626
class SplineFilter(CommandLine):
27+
"""
28+
Smoothes TrackVis track files with a B-Spline filter.
29+
30+
Helps remove redundant track points and segments
31+
(thus reducing the size of the track file) and also
32+
make tracks nicely smoothed. It will NOT change the
33+
quality of the tracks or lose any original information.
34+
35+
Example
36+
-------
37+
38+
>>> import nipype.interfaces.diffusion_toolkit as dtk
39+
>>> filt = dtk.SplineFilter()
40+
>>> filt.inputs.track_file = 'tracks.trk'
41+
>>> filt.inputs.step_length = 0.5
42+
>>> filt.run() # doctest: +SKIP
43+
"""
2744
input_spec=SplineFilterInputSpec
2845
output_spec=SplineFilterOutputSpec
2946

@@ -32,4 +49,42 @@ class SplineFilter(CommandLine):
3249
def _list_outputs(self):
3350
outputs = self.output_spec().get()
3451
outputs['smoothed_track_file'] = os.path.abspath(self.inputs.output_file)
35-
return outputs
52+
return outputs
53+
54+
55+
class TrackMergeInputSpec(CommandLineInputSpec):
56+
track_files = InputMultiPath(File(exists=True), desc="file containing tracks to be filtered", position=0, argstr="%s...", mandatory=True)
57+
output_file = File("merged_tracks.trk", desc="target file for merged tracks", position=-1, argstr="%s", usedefault=True)
58+
59+
class TrackMergeOutputSpec(TraitedSpec):
60+
track_file = File(exists=True)
61+
62+
class TrackMerge(CommandLine):
63+
"""
64+
Merges several TrackVis track files into a single track
65+
file.
66+
67+
An id type property tag is added to each track in the
68+
newly merged file, with each unique id representing where
69+
the track was originally from. When the merged file is
70+
loaded in TrackVis, a property filter will show up in
71+
Track Property panel. Users can adjust that to distinguish
72+
and sub-group tracks by its id (origin).
73+
74+
Example
75+
-------
76+
77+
>>> import nipype.interfaces.diffusion_toolkit as dtk
78+
>>> mrg = dtk.TrackMerge()
79+
>>> mrg.inputs.track_files = ['track1.trk','track2.trk']
80+
>>> mrg.run() # doctest: +SKIP
81+
"""
82+
input_spec=TrackMergeInputSpec
83+
output_spec=TrackMergeOutputSpec
84+
85+
_cmd = "track_merge"
86+
87+
def _list_outputs(self):
88+
outputs = self.output_spec().get()
89+
outputs['track_file'] = os.path.abspath(self.inputs.output_file)
90+
return outputs
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.diffusion_toolkit.postproc import TrackMerge
4+
5+
def test_TrackMerge_inputs():
6+
input_map = dict(args=dict(argstr='%s',
7+
),
8+
environ=dict(nohash=True,
9+
usedefault=True,
10+
),
11+
ignore_exception=dict(nohash=True,
12+
usedefault=True,
13+
),
14+
output_file=dict(argstr='%s',
15+
position=-1,
16+
usedefault=True,
17+
),
18+
terminal_output=dict(mandatory=True,
19+
nohash=True,
20+
),
21+
track_files=dict(argstr='%s...',
22+
mandatory=True,
23+
position=0,
24+
),
25+
)
26+
inputs = TrackMerge.input_spec()
27+
28+
for key, metadata in input_map.items():
29+
for metakey, value in metadata.items():
30+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
31+
32+
def test_TrackMerge_outputs():
33+
output_map = dict(track_file=dict(),
34+
)
35+
outputs = TrackMerge.output_spec()
36+
37+
for key, metadata in output_map.items():
38+
for metakey, value in metadata.items():
39+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
40+

nipype/interfaces/mrtrix/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
3-
from .tracking import (Tracks2Prob, StreamlineTrack,
3+
from .tracking import (Tracks2Prob, FilterTracks, StreamlineTrack,
44
DiffusionTensorStreamlineTrack,
55
SphericallyDeconvolutedStreamlineTrack,
66
ProbabilisticSphericallyDeconvolutedStreamlineTrack)

nipype/interfaces/mrtrix/convert.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ def track_gen(track_points):
100100
n_streams = 0
101101
iflogger.info('Reading tracks...')
102102
while True:
103-
n_pts = track_points[n_streams]
103+
try:
104+
n_pts = track_points[n_streams]
105+
except IndexError:
106+
break
104107
pts_str = fileobj.read(n_pts * bytesize)
105108
nan_str = fileobj.read(bytesize)
106109
if len(pts_str) < (n_pts * bytesize):
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.mrtrix.tracking import FilterTracks
4+
5+
def test_FilterTracks_inputs():
6+
input_map = dict(args=dict(argstr='%s',
7+
),
8+
debug=dict(argstr='-debug',
9+
position=1,
10+
),
11+
environ=dict(nohash=True,
12+
usedefault=True,
13+
),
14+
exclude_file=dict(argstr='-exclude %s',
15+
xor=['exclude_file', 'exclude_spec'],
16+
),
17+
exclude_spec=dict(argstr='-exclude %s',
18+
position=2,
19+
sep=',',
20+
units='mm',
21+
xor=['exclude_file', 'exclude_spec'],
22+
),
23+
ignore_exception=dict(nohash=True,
24+
usedefault=True,
25+
),
26+
in_file=dict(argstr='%s',
27+
mandatory=True,
28+
position=-2,
29+
),
30+
include_file=dict(argstr='-include %s',
31+
xor=['include_file', 'include_spec'],
32+
),
33+
include_spec=dict(argstr='-include %s',
34+
position=2,
35+
sep=',',
36+
units='mm',
37+
xor=['include_file', 'include_spec'],
38+
),
39+
invert=dict(argstr='-invert',
40+
),
41+
minimum_tract_length=dict(argstr='-minlength %s',
42+
units='mm',
43+
),
44+
no_mask_interpolation=dict(argstr='-nomaskinterp',
45+
),
46+
out_file=dict(argstr='%s',
47+
hash_files=False,
48+
name_source=['in_file'],
49+
name_template='%s_filt',
50+
position=-1,
51+
),
52+
quiet=dict(argstr='-quiet',
53+
position=1,
54+
),
55+
terminal_output=dict(mandatory=True,
56+
nohash=True,
57+
),
58+
)
59+
inputs = FilterTracks.input_spec()
60+
61+
for key, metadata in input_map.items():
62+
for metakey, value in metadata.items():
63+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
64+
65+
def test_FilterTracks_outputs():
66+
output_map = dict(out_file=dict(),
67+
)
68+
outputs = FilterTracks.output_spec()
69+
70+
for key, metadata in output_map.items():
71+
for metakey, value in metadata.items():
72+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
73+

nipype/interfaces/mrtrix/tracking.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,56 @@
1414
import os, os.path as op
1515
from nipype.interfaces.traits_extension import isdefined
1616

17+
class FilterTracksInputSpec(CommandLineInputSpec):
18+
in_file = File(exists=True, argstr='%s', mandatory=True, position=-2,
19+
desc='input tracks to be filtered')
20+
include_xor = ['include_file', 'include_spec']
21+
include_file = File(exists=True, argstr='-include %s', desc='inclusion file', xor = include_xor)
22+
include_spec = traits.List(traits.Float, desc='inclusion specification in mm and radius (x y z r)', position=2,
23+
argstr='-include %s', minlen=4, maxlen=4, sep=',', units='mm', xor = include_xor)
24+
25+
exclude_xor = ['exclude_file', 'exclude_spec']
26+
exclude_file = File(exists=True, argstr='-exclude %s', desc='exclusion file', xor = exclude_xor)
27+
exclude_spec = traits.List(traits.Float, desc='exclusion specification in mm and radius (x y z r)', position=2,
28+
argstr='-exclude %s', minlen=4, maxlen=4, sep=',', units='mm', xor = exclude_xor)
29+
30+
minimum_tract_length = traits.Float(argstr='-minlength %s', units='mm',
31+
desc="Sets the minimum length of any track in millimeters (default is 10 mm).")
32+
33+
34+
out_file = File(argstr='%s', position=-1, desc='Output filtered track filename',
35+
name_source=['in_file'], hash_files=False, name_template='%s_filt')
36+
37+
no_mask_interpolation = traits.Bool(argstr='-nomaskinterp', desc="Turns off trilinear interpolation of mask images.")
38+
invert = traits.Bool(argstr='-invert', desc="invert the matching process, so that tracks that would" \
39+
"otherwise have been included are now excluded and vice-versa.")
40+
41+
42+
quiet = traits.Bool(argstr='-quiet', position=1, desc="Do not display information messages or progress status.")
43+
debug = traits.Bool(argstr='-debug', position=1, desc="Display debugging messages.")
44+
45+
class FilterTracksOutputSpec(TraitedSpec):
46+
out_file = File(exists=True, desc='the output filtered tracks')
47+
48+
class FilterTracks(CommandLine):
49+
"""
50+
Use regions-of-interest to select a subset of tracks
51+
from a given MRtrix track file.
52+
53+
Example
54+
-------
55+
56+
>>> import nipype.interfaces.mrtrix as mrt
57+
>>> filt = mrt.FilterTracks()
58+
>>> filt.inputs.in_file = 'tracks.tck'
59+
>>> filt.run() # doctest: +SKIP
60+
"""
61+
62+
_cmd = 'filter_tracks'
63+
input_spec=FilterTracksInputSpec
64+
output_spec=FilterTracksOutputSpec
65+
66+
1767
class Tracks2ProbInputSpec(CommandLineInputSpec):
1868
in_file = File(exists=True, argstr='%s', mandatory=True, position=-2,
1969
desc='tract file')

nipype/testing/data/track1.trk

Whitespace-only changes.

nipype/testing/data/track2.trk

Whitespace-only changes.

0 commit comments

Comments
 (0)