Link tracks

Analysis › Tracking · version 3

Links localizations in successive frames into tracks: track_id and

What it does

In single-particle tracking (SPT) a molecule is localized again in frame after frame as it moves, and its track – the localizations of one particle in time order – shows how it moves: freely, slowly, confined, or switching between the two. This plugin decides which localizations belong to one particle and names each track, writing two attributes onto the table: track_id (1, 2, ... in the order the tracks start, -1 for a localization in no track) and track_length (how many localizations the track has).

Here the tracks are fitted from single molecules, so they are sparse: in one frame the molecules are far apart compared with how far each moves (its jump). A jump as long as the distance between molecules would blur the spot or make two spots overlap, and neither could be fitted. So which localization continues a track is rarely in doubt. What matters is the frames in which the fluorophore was dark, too dim to be found, or badly fitted: a track must survive them. memory says how many such frames in a row are bridged.

Two linkers, the algorithm:

On sparse tracks the two give the same links to within a few in a thousand, and the simple one is several times faster (the benchmark below).

A track is a region: track_id is an id attribute like cluster_id, so any measurement offered per region runs once per track (a block of a chain set to for each track_id, or the per-region steps), a filter on track_length keeps the long tracks, and Segment regions, from an id attribute, makes an ROI of each track to review.

It links the localizations the layer's filter and ROI keep; the rest of the files and channels the layer shows get track_id

  1. Other files and channels keep their tracks, and the new ones are

numbered after them, so two files on two layers are linked one after the other. It always links the single localizations, never merged blinks: merging joins the localizations in consecutive frames that lie close together, which for a slow particle is its whole track.

How it works

1. Candidates. For every localization, the localizations of the next memory + 1 frames within the maximum jump of it are its candidates: the places its particle may have gone, the next frame or after a few dark ones. They are found with the cell search of Neighbourhood, on every processor core.

2. Links. Taking the frames in order, each localization is joined to one open track end among its candidates, or starts a track of its own. A track end stays open for memory frames: a particle that was dark for that long can still continue its track. The simple linker takes the nearest pairs first; the global assignment takes, per frame, the set of links with the smallest sum of squared jumps.

3. Tracks. The chains of links are numbered 1, 2, ... in the order they start. A chain of fewer than minimum length localizations – a lone localization included – gets -1.

Simulated tracks over 60 frames, the fluorophores dark in 15% of the frames for 1.5 frames on average. Left, the truth; middle, linked without memory: every dark frame cuts a track in two (and lone localizations, grey, are in none); right, with memory 2 the dark frames are bridged and most tracks come out whole; where three particles cross (bottom left) some are still mixed up.

In detail

Candidates. Localization is a candidate to continue localization when

with the frame, the position (x and y, or x, y and z with in 3D), the memory and the maximum jump. The same holds for a link across dark frames as for one between consecutive frames, as in Crocker and Grier's code and trackpy. A particle diffusing for frames goes times as far as in one, so a fast particle's dark frames are bridged less often than a slow one's: set for the longest gap that should be bridged.

All candidates of all frames come from one search: x is shifted by the frame times a stride wider than the field plus , so a search around meets only the localizations of frame – one search per gap length, no loop over frames.

Simple. The candidates are visited by the frame they lead to, then by distance, then by gap length (at equal distance the shorter gap first), and a link is taken when its earlier localization has no successor yet and its later one no predecessor. This is exactly "frame by frame, nearest first", done in one pass in C++.

Global assignment. Per frame, among the open track ends and the frame's localizations , the links are those that minimise

Crocker and Grier's criterion: a track end not continued costs as much as the longest allowed jump. It is the same as maximising over the links, which scipy.optimize.linear_sum_assignment solves for each group of candidates that compete; a link nobody else wants is taken without a solve. It differs from the simple linker where two particles pass close by: the simple one gives the closest pair first and may leave the other particle with no link, where the global one may prefer two slightly longer jumps. On the benchmark below, global assignment found exactly trackpy's links.

Groups. Each file is linked on its own, and with per channel each channel too, so that two files or two channels are never one track. Track ids continue from one group to the next.

Benchmark. Simulated tracks (smappy.simulate.simulate_tracks): 300 frames of a 20 µm field, particles lasting 20 frames on average, dark in 10% of the frames for 1.5 frames on average, 20 nm precision; memory 3 and the maximum jump – three times the root-mean-square jump as it is measured, with the precision of both ends. Over densities of 0.02 to 1 particles per µm² and jumps of 50 to 400 nm, compared by the ratio of the jump to the mean distance between nearest neighbours, at density (the study studies/tracking/bench.py):

jump / spacing true links found wrong links whole tracks
below 0.198.6-99.6%, the two within 0.3%under 1%simple within 1.6% of global
0.1 to 0.2simple 0.3-1% fewer0.5-5%simple 1-3% fewer
0.25 to 0.4simple 1-3% fewer5-15%under half, both
0.6 to 0.863-81%20-40%almost none, both

The simple linker took 1.4-2.5 µs per localization (up to 11 µs at the densest), the global assignment 4-31 µs. trackpy (0.7, the same jump and memory) gave the global assignment's links exactly, at 7-25 µs per localization, and gave up (a subnetwork too large) from a ratio of 0.4 on. On 880,000 localizations over 4000 frames: simple 2.3 s, global 4.6 s, trackpy 5.5 s. Where a single-molecule tracking experiment can be – jumps well below the distance between molecules – the two linkers agree, and the simple one is the default for being faster and easier to reason about. Where global assignment is better, by a few percent, both get too many links wrong to be trusted: lower the density.

The two linkers against the truth at 0.5 particles per µm², over the ratio of the jump to the distance between molecules: the true links each finds (solid) and the fraction of tracks it finds whole (dashed). They agree while the ratio is small; past about 0.2 the global assignment is a little better, and both lose most whole tracks.

Parameters

settingdefaultwhat it does
algorithm
algorithm
simpleSimple: nearest first; global: least squared jumps per frame.

simple unless the particles come close to each other within a jump – then global assignment gets a few percent more links right, at a few times the time (still seconds for a million localizations).

Choices: simple; global assignment
maximum jump
max_jump_nm
500 nmThe farthest a particle moves between the frames it is seen in.

About three times the root-mean-square jump as measured, precision included: for a particle with diffusion coefficient (µm²/s) over a frame time (s), µm in 2D, and the maximum jump about . Too small, and the fast steps (and the bridged gaps) are cut, splitting tracks; too large – near the distance between molecules – and a track ending next to another particle's start is joined to it. For a population with fast and slow particles, set it for the fast ones.

at least 1 nm
memory
memory
2 framesDark frames a track survives.

As many frames as the fluorophore's dark runs usually last; a longer run still cuts the track. Each frame more lets a track continue after a longer gap, but also lets an ending track be joined to a particle that appears near its end. 0 cuts a track at every missed frame.

minimum length
min_length
2Localizations in a track; shorter ones get track_id -1, in none.

2 drops only the lone localizations. An analysis of motion wants more: an MSD needs several steps per track, so 5 or more. It changes nothing about the links, only which tracks get an id.

at least 1
in 3D
use_z
onJumps in x, y and z when the table has z_nm.
per channel
per_channel
onLink each channel on its own.
output attribute (more)
column
track_idWhere the ids go; the lengths go to the same name with _length for _id.

track_id unless there is a reason: link a second time with other settings into track_id_strict, say, to compare the two, or link a MINFLUX file without touching its tid. The lengths go to the same name with _length for _id (track_id_strict_length). It writes a new attribute, track_id, or one it wrote before – never over an attribute of the table's own, so a typo cannot overwrite frame. What reads tracks (the tracks render mode, Tracking analysis) has a track id to choose the attribute.

Output

The table with track_id and track_length, a line with the number of tracks, the localizations in them, the mean length and the settings, and a figure: the tracks drawn as lines (at most 3000 of them), and how many localizations the tracks have. Good tracking shows long tracks with a length distribution that falls off smoothly; many tracks of 2-3 localizations, where long ones are expected, mean the maximum jump or the memory is too small. Both attributes keep their value on merged blinks (the largest, a recipe with the rule max), so a layer that merges blinks still shows the tracks.

Differences from SMAP

Based on SMAP's SimpleTracking (Ries 2020), which links with Crocker and Grier's code (mytrack.m). The main changes:

References