Adaptive viral tracing informed tractography (AdaViT) - #1345
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces an “Adaptive viral tracing informed tractography (AdaViT)” workflow to scilpy by adding a dedicated CLI and a corresponding tracker implementation that supports 4D tracking masks and optional exclusion-mask-based backtracking. It also extends tractogram info reporting with an additional streamline-length statistic.
Changes:
- Added
scil_tracking_adavitCLI entrypoint and implementation for AdaViT tracking with 4D masks, optional dilation, and (probabilistic-only) backtracking via an exclusion mask. - Added
TrackerAdaViT(and related stopping-criteria signature update) to support trajectory-dependent tracking masks. - Extended
scil_tractogram_print_info.pystatistics with median streamline length.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/scilpy/tracking/tracker.py | Updates base stopping-criteria signature and adds TrackerAdaViT (plus a new MouseTracker class). |
| src/scilpy/cli/scil_tractogram_print_info.py | Adds median streamline length to printed tractogram statistics. |
| src/scilpy/cli/scil_tracking_adavit.py | New AdaViT CLI script wiring inputs/args to TrackerAdaViT and saving output tractograms. |
| pyproject.toml | Registers the new scil_tracking_adavit console script entrypoint. |
Suppressed comments (1)
src/scilpy/tracking/tracker.py:1043
- The space/origin guard uses
and, so it will only raise when both space is not VOX and origin is not CENTER. This allows unsupported configurations through.
self.origin = self.propagator.origin
self.space = self.propagator.space
if self.space != Space.VOX and self.origin != Origin.CENTER:
raise NotImplementedError("This version of the Tracker only works in VOX space with CENTER origin.")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| def _verify_stopping_criteria(self, line): | ||
| # project line coordinates onto a grid to find which masks we are in | ||
| # TODO: Support trilinear interpolation for line-masks intersection | ||
| line_mask = np.zeros(self.tracking_masks.shape[:-1], dtype=bool) | ||
|
|
||
| # line is in origin center, so we add 0.5 to get to | ||
| # corner and then floor to get voxel coordinates | ||
| coords = np.floor(np.array(line) + 0.5).astype(int) | ||
|
|
||
| line_mask[coords[:, 0], coords[:, 1], coords[:, 2]] = True | ||
| line_masks_intersection = self.tracking_masks[line_mask] | ||
|
|
||
| matching_tracking_masks = np.all(line_masks_intersection, axis=0) | ||
| return np.any(matching_tracking_masks) |
| # assert space | ||
| if self.space != Space.VOX and self.origin != Origin.CENTER: | ||
| raise NotImplementedError("This version of the Tracker only works in VOX space with CENTER origin.") | ||
|
|
| AdaViT uses a 4D volume containing many tracking masks and tracks only | ||
| in the union of all masks intersecting the streamline trajectory. In the | ||
| original publication, AdaViT is used with tracking masks estimated from | ||
| viral tracing experiments, but in practice, any list of masks can be used. |
| tracts_format = detect_format(args.out_tractogram) | ||
| if tracts_format is not TrkFile: | ||
| logging.warning("You have selected option --save_seeds but you are " | ||
| "not saving your tractogram as a .trk file. \n" | ||
| "Data_per_point information CANNOT be saved.\n" | ||
| "Ignoring.") | ||
| args.save_seeds = False | ||
|
|
| # condition for backtracking | ||
| backtrack = args.mask_exclude is not None and args.algo == 'prob' | ||
| backtrack_n_pts = int(args.backtrack_distance / step_size) | ||
|
|
| # Compared with scil_tracking_local, using sft rather than | ||
| # LazyTractogram to deal with space. | ||
| # Contrary to scilpy or dipy, where space after tracking is vox, here | ||
| # space after tracking is voxmm. | ||
| # Smallest possible streamline coordinate is (0,0,0), equivalent of |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1345 +/- ##
==========================================
- Coverage 72.59% 71.84% -0.76%
==========================================
Files 301 302 +1
Lines 26283 26649 +366
Branches 3700 3763 +63
==========================================
+ Hits 19080 19145 +65
- Misses 5651 5950 +299
- Partials 1552 1554 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Quick description
Addition of a new CLI script for adaptive viral tracing informed tractography (AdaViT), allowing for dynamically updating the tracking mask based on streamline position. This is the code from my CDMRI 26 conference paper.
New functionality:
scil_tracking_adavit.pyimplementing the AdaViT algorithm for viral tracing informed tractography, including support for 4D tracking masks, exclusion masks, and backtracking options.Other:
scil_tractogram_print_info.pyby including the median streamline length in the statistics.Type of change
Check the relevant options.
Checklist