Tracking analysis

Analysis › Tracking · version 3 · can run once per region

How the tracks move: the mean squared displacement, with D and alpha

What it does

Measures how tracks move. It needs tracks, an id attribute that says which localizations belong to one particle – the track id: on auto, track_id from Link tracks, else MINFLUX's tid, else a simulation's track_id_true. Two analyses, each ticked on or off:

All take the localization precision into account: a molecule that does not move still seems to, by its localization error, and an analysis that ignores it finds every molecule mobile.

Time comes from the file's frame time (recorded by the camera, set in File > File properties, or here under frame time); a table with its own clock (time_s, MINFLUX) uses that. It analyses the localizations the layer's filter and the ROI keep. Per region it runs too: in each ROI of the ROI manager, or in a block over track_id, once per track. With write per track, each track's D and α are written onto its localizations (track_D_um2_per_s, track_alpha), to colour or filter the tracks by.

How it works

1. Displacements. The tracks are sorted by id and time. For every lag of k frames, the squared distance between every two localizations of a track exactly k frames apart is averaged: that track's MSD at lag k. Pairs across a dark frame count at their true lag. The MSD of all tracks pools the pairs of every track.

2. The offset. A particle's measured position is off by its localization error, so even at a lag of zero frames the MSD would not be zero: in two dimensions it starts at , with the precision. It is taken from the precisions of the localizations (offset: from the precisions), or fitted with the slope.

3. How many points. The first MSD points are averaged over many pairs but carry the localization error; the later ones are averaged over few. Somewhere between is the number of points that gives the most precise D. It depends on how long the track is and on how large the error is compared with a frame's motion, and it is computed for each track (see In detail).

4. D and α. A straight line through the offset fitted to those points gives D; the slope of the MSD above the offset on a log-log plot gives α.

Left: simulated tracks at D = 0.1 µm²/s with 30 nm precision; the MSD of all of them (dots), the points the fit used (blue) and the line through the offset. Right: how precise D is when fitted to the first p points, for a track of 50 positions, at three ratios of the localization error to a frame's motion: when the error is small one point is best, when it dominates many are, and fitting the wrong number can be several times worse.

5. Jump distances. The distances between localizations of a track exactly 1, 2, ... frames apart are collected, up to lags frames. Each diffusive state gives jumps of a known shape – wider for a larger D and a longer lag, and widened by the two localizations' errors – and the states' D and fractions are those that make the observed jumps, at all lags together, most likely.

Two populations, 35% at 0.01 µm²/s and 65% at 0.5 µm²/s. Left: D per track, on a log axis – two groups, broad because each track is short. Right: the jumps between consecutive frames, the two states fitted to them and their sum (black), which give back both coefficients and fractions.

6. The focus. A camera sees a particle only while it is within a few hundred nm of the focal plane – the axial range. A slow particle stays there for many frames; a fast one diffuses out of it in z within a few. So the fast state makes fewer jumps than its number of particles, fewer still at longer lags, and a fit that counts jumps finds it too small a fraction. For each D the fraction of particles still in focus after 1, 2, ... frames is computed (left in the figure below), and each state's share of the jumps at each lag is its fraction of the particles times that. The fractions reported are then of the particles.

Half the particles slow (0.05 µm²/s), half fast (3 µm²/s), seen in a 700 nm focus. Left: the fraction of particles still in focus after each frame, for several D. Middle: fitted without the axial range, the fast state's share of the jumps falls with lag (dots, the jumps) away from the flat model (line), and the fast fraction comes out far too small. Right: with it, the model follows the jumps' fall and the fractions of the particles (dashed) come back at a half each.

7. The D spectrum. Each track is cut into pieces of at most piece jumps. For every piece and every D of a grid of 100, from 0.001 to 100 µm²/s, the probability of its jumps is computed exactly – the jumps of a piece are not independent, since each two consecutive ones share a localization and so its error. Then the share of the jumps at each D (the occupation) is found that makes all pieces together most probable, with each piece weighed over the D*s by how well each explains it. The populations are the peaks of the occupations; their fractions are the occupations under each peak. Each piece's *D is its average over the D*s by that weight. With an *axial range, the occupations are corrected for the focus as the jumps are.

Left: three populations, 30% at 0.02, 30% at 0.3 and 40% at 2 µm²/s (dotted); the D spectrum finds three peaks at their D with their fractions, without being told how many there are. Right: a particle that switches between 0.02 and 2 µm²/s; each piece of 10 jumps of its track gets its own D (dots), which follows the true D (grey) from piece to piece.

8. State switching. Each particle is in one of states states at any moment, each with its D, and switches from one to another at a fixed rate – so many times a second. The model follows each track localization by localization: for each state it keeps how likely the particle is to be in it, and where the particle truly is given the localizations so far (each is off by its precision). The *D*s and rates that make all tracks most likely are the answer. The fractions follow from the rates: in the long run, a particle spends in each state the share of time the rates into and out of it give. Each localization's state is then the most likely given the whole track, before and after.

Particles switching between 0.02 and 1 µm²/s, 2.5 times a second each way (a switch every 20 frames), half the time in each. Left: the fitted states, with the rates on the arrows – 2.5/s each way and half in each come back. Right: one track, the probability that the particle is fast at each localization (blue) against when it truly was (grey).

In detail

The MSD. For a track with positions in frames ,

over all pairs frames apart, overlapping – the usual estimator. Pooled, the sums and counts of all tracks are added. Lags up to 50 frames are computed, every one over the whole table at once, so 50,000 tracks of a million localizations take a few seconds.

The model. For free diffusion in dimensions, with frame time and a localization error per axis,

the offset in 2D. from the precisions takes as the mean of the track's xy_err_nm² (and z_err_nm² in 3D). It is the static error; a particle that moves during the exposure is blurred, which makes the true offset smaller (Michalet 2010). fitted fits the intercept too, which needs no precisions but leaves D less certain (Michalet & Berglund 2012).

How many points. With the offset known, is the slope through it, over ; with it fitted, the slope of an ordinary straight line. Michalet (2010) showed that the error of has a minimum in , set by the track's length and the reduced localization error

and gave an empirical formula for it. That formula is not used here: the optimum is computed from the model itself. The displacements of a Brownian track with Gaussian errors are jointly Gaussian, with covariances times the frames two displacements share plus where their ends meet; the MSD points are means of their squares, and for Gaussian variables , so the full covariance of the MSD points follows exactly. From it, the variance of for every , and the with the least. (Against 20,000 simulated tracks the covariance agrees to a few percent.) Since needs , Michalet's iteration: from , from , from , until repeats, at most 10 rounds. A track with dark frames is taken as the gap-free track over its span. For the optimum is one point with the offset known (two with it fitted); for and 50 positions it is about 35.

α is the slope of against over the same points, or the first two at least, where the MSD is above the offset; NaN for a track that hardly moves. Per track it is noisy: read the median, or the pooled value.

Jump distances. For the jumps between localizations exactly frames apart ( lags, every pair of every track), a state with coefficient gives per axis a Gaussian of variance

the two localizations' errors from their precisions, so is chi-square with degrees of freedom. The fractions and coefficients of the states maximise the likelihood of all jumps, by expectation maximisation: the fractions are the mean memberships, and each solves its weighted likelihood equation by a fixed point. At most 200,000 jumps are fitted (a random subset, the same each run). The BIC (Bayesian information criterion, for states and jumps) compares fits with different states: the lower is better. The jumps of one track are not independent, so the likelihood is overconfident, and no errors are given; with several lags the same displacement enters more than once, which makes it more so but moves no estimate.

The focus. The focus is the slab , the axial range. A particle in focus in one frame is equally likely anywhere in it – as the particles of a cell are at any moment – and moves in z by a Gaussian of variance per frame. The fraction still in focus in each of the next frames, , is computed frame by frame: the density in the slab is carried on 200 cells by the probability of moving from each cell into each other, and whatever lands outside is dropped. Looking once a frame is what the camera does; Spot-On instead uses the continuous absorbing series and widens the slab by an empirical , which this does not need (saSPT's choice). Against 200,000 simulated particles agrees to 0.1%. State 's share of the jumps at lag is then

its fraction of the particles. Bleaching takes every state alike and cancels. This couples each to every fraction, so the EM fit without the focus is the start, and the likelihood is then maximised over the and (L-BFGS, with the exact gradient but for the slope of in , taken by a difference).

Spot-On also uses only each track's first four jumps at each lag; here every jump is used. The correction holds for particles anywhere in the focus, while a track's first localizations are often of a particle that has just come in at its edge, and will soon leave: on simulated tracks (like the figure's) the first four jumps gave the fast state 79% for a true 50%, all jumps 51%. In 3D the fit with an axial range uses the lateral jumps alone: the particles that stay in focus are those that moved less in z, so their z jumps are too short (a 10% lower D on simulated tracks), while x and y do not care. A particle that comes back into focus is taken as a new one; a linker with a memory may join it to its old track across the gap, which the model does not count.

The D spectrum. Each track's jumps between consecutive localizations are cut, from its start, into pieces of at most piece jumps, the last shorter. Along a piece, jump over frames has per axis the variance ( localization 's error variance, from its precision), and jumps and share localization , so they covary by . The jumps of a piece are therefore jointly Gaussian with a tridiagonal covariance, whose determinant and quadratic form one pass along the piece gives (its LDL factorisation); the log-likelihood of piece at grid point is the sum over the axes. saSPT puts the localization error on a grid as well, one value for all; here each localization's own precision is used, which drops that grid.

The occupations follow by variational Bayes, saSPT's scheme: a Dirichlet over them with one pseudo-count per grid point, and, round by round,

with the piece's number of jumps and the digamma function, until no occupation moves by more than (at most 5000 rounds; saSPT stops after 200, when single grid points can still be several percent from where they settle, though the fraction under a peak no longer moves). The occupations are shares of the jumps. With an axial range they are divided by each D's fraction still in focus after one frame, above, and renormalised: a piece's jumps are mostly between consecutive frames. Each piece's D is , the posterior mean of . The peaks are the local maxima of the occupations, each with the grid points down to the minima on either side; a peak with less than 2% is not reported.

Against simulated tracks with three populations it gives back their D within 20% and their fractions within 0.04 (with 2,600 pieces), and a piece's D tells a slow from a fast state in 97% of pieces or more. Unlike the jumps' states, it needs no number of states and its likelihood is right for the correlated jumps. Close populations are where it is weakest: on simulated tracks two halves a factor of two apart in D still gave two peaks, but at 62% and 38%; a factor of three gave 55% and 45%. Short pieces spread every peak out.

State switching. The state is a Markov chain with a rate (per second) from state to ; over frames it moves by , the rate matrix. A particle's true position moves from localization to the next, frames later, by a Gaussian of variance per axis, the state at : the state holds over the interval. What is measured is the true position plus the localization's error, of variance per axis.

The likelihood of a track integrates out the true positions. For each state of the current localization the filter keeps its log-probability and a Gaussian of the true position, and goes on localization by localization: from each state , a Kalman step – the predicted position's variance grows by , the next localization updates it, and how well it was predicted is the step's likelihood – then into each state by the transition matrix. The exact belief is a mixture with a Gaussian per past sequence of states, which grows without bound; the Gaussians that end in the same state are merged into one with their mean and variance at every step. That is ExTrack's merging with the shortest memory (its frame_len of 1). With one state nothing is merged and the filter is exact: it agrees with the D spectrum's Gaussian of a whole track to .

The fit maximises the summed log-likelihood over , and the probabilities of the state a track starts in (L-BFGS, the gradient by differences), from the jump fit's *D*s and a switch every 20 frames. The starting probabilities are free rather than the chain's long-run ones, because how tracks start – a fast particle enters a thin focus more often – need not follow the rates. The fractions reported are the long-run ones, ; a state's dwell time is . At most 50,000 jumps are fitted, a random subset of whole tracks beyond (the same each run); two states take a few seconds for 10,000 jumps, three about four times as long.

Each localization's state is the posterior of the state over the jump it starts (the last of a track: the jump it ends), by the forward-backward algorithm with the fitted parameters. There the jumps are taken as independent given the states, each with the error variance , the standard hidden Markov model: the merged filter has no exact way back. On the simulations here it gets 95% (three states) to 98% (two) of localizations right.

Against simulated tracks (two states, 0.02 and 1 µm²/s, 2.5/s each way) the rates come back within 15%, at three states (six rates) within 30%, the fractions within 0.04. Two things are left out. A jump across dark frames is taken in the state it started in throughout. And a particle that leaves a thin focus ends its track: fast particles leave sooner, so the tracks seen for long are those that went slow, which the likelihood does not count. Six simulations of each (0.05 and 2 µm²/s, 2.5/s each way): without a focus the rates came back at 2.49 ± 0.16 and 2.66 ± 0.19/s and the fast fraction at 0.48; in a 700 nm focus at 1.99 and 3.77 ± 0.63/s and 0.35. A factor for staying in focus at each step made it no better – whether a particle stays depends on its z, which the model does not follow – so it is not applied, and with an axial range the run warns: take the fractions from the jump distances or the D spectrum there, and read the rates with care.

Crowding. The rates are only as good as the linking. Where particles are dense, a fast track sometimes picks up a slow neighbour's localization and goes on as that particle; in the data that is a fast particle that slowed down, a switch, and no model of the track can tell it from a real one. Two states 50 times apart (0.02 and 1 µm²/s, 10 ms frames, linked by the global linker at three times the fast jump) gave rates 10--20% too high where the fast state's rms jump in a frame, , was 0.13--0.18 of the mean distance from a particle to its nearest neighbour, 60% too high at 0.28 and twice too high at 0.4; with no switching at all, 0.3, 1.3 and 2.7 switches per second were found. The jump distances and their D*s hardly moved. So state switching measures that ratio: the distance from each localization to the nearest one in its frame, averaged over the localizations analysed (linked or not), against the fastest state's jump. It is written as hmm_crowding, and above 0.15 the run warns. A term for wrong links in the model (a link to anywhere, its probability fitted) was tried: it caught a sixth of them, halved the spurious rates at best, pulled the fast *D down by up to 7% and was left out.

MINFLUX. A table with time_s has no regular frames; its localizations are put on a grid of the median interval between consecutive localizations of a track, each at the nearest step.

Parameters

settingdefaultwhat it does
MSD
msd
onThe mean squared displacement over lag.
jump distances
jumps
onThe distribution of jumps, as diffusive states.
D spectrum
spectrum
offThe jumps over a grid of D, no number of states chosen, and each piece of a track's D (saSPT).
state switching
switching
offStates that switch in time: their D, the rates between them and each localization's state (HMM).
track id
id_column
autoThe attribute naming the tracks; auto: track_id, else tid, else track_id_true.

auto takes the first of track_id, tid and track_id_true the table has, and the list says which. Choose another integer attribute to compare two linkings (Link tracks' output attribute), or group_id to treat each merged blink as a track. An id of -1 is no track.

in 3D
use_z
onX, y and z when the table has z_nm.
frame time (more)
frame_time_ms
autoAuto: the file's, else its exposure. at least 0.001 ms
axial range
axial_range_nm
0 nmThe depth in which particles are seen, for the fast ones leaving it; 0: no correction.

The depth around the focal plane in which a particle is detected, not the PSF's width: about 700 nm for 2D tracking with HILO illumination is a common value; measure it as the z range over which beads are still detected and fitted. 0 when nothing leaves – 3D tracking over a deep range, MINFLUX, or particles on a membrane. A value too large undercorrects (the fast fraction too small), one too small overcorrects. It applies to the jump distances and the D spectrum, not to the MSD or the state switching (see In detail).

MSD
   offset
   msd_fit.offset
from the precisionsThe localization error's offset: from xy_err_nm, or fitted with the slope.

from the precisions when the fitter's precisions are trustworthy (the default); fitted when they are not, or when motion blur is large – a fast particle over a long exposure.

Choices: from the precisions; fitted
   lags
   msd_fit.lags
autoAuto: per track the number that gives the most precise D (Michalet 2010).

Leave on auto. A fixed number is what most papers use and what Michalet showed to be often far from the best: too few points for slow particles with large errors, too many for fast ones.

at least 1
   minimum length
   msd_fit.min_length
5Localizations a track needs for a D of its own.

In 2D, a track of 5 localizations gives a D uncertain by about 55% even with a small localization error, one of 20 by about 25%: for per-track values to mean something, 20 or more. The pooled MSD uses every track.

at least 2
   write per track
   msd_fit.write_columns
offtrack_D_um2_per_s and track_alpha onto the localizations.
jump distances
   lags
   jump_fit.lags
4 framesThe jumps 1, 2, ... this many frames apart, fitted together.

Several lags pin D and the fractions down better than one: longer lags spread the states apart against the localization error, which helps for slow states, and with an axial range the fall of the fast state's share with lag is itself information. Spot-On uses about 7. Too many, and particles that change state within the lag blur the states together, and few fast particles are left at the longest lags.

1 to 20 frames
   states
   jump_fit.states
2Diffusive states fitted, 1 to 3.

Fit 1, 2 and 3 and compare the BIC: a state more that does not lower it by at least about 10 (a common rule of thumb) is not supported by the data. Two states fitted to one population come out as two close values of D.

1 to 3
D spectrum
   piece
   spectrum_fit.split
10 jumpsTracks cut into pieces of at most this many jumps, each given its own D.

saSPT's 10. Shorter pieces follow a particle that changes state more closely, but each says less about its D, which broadens the spectrum's peaks; longer pieces sharpen the peaks but blur a change of state within a piece.

1 to 100 jumps
   D from (more)
   spectrum_fit.d_min
0.001 µm²/sThe smallest D of the grid.

The grid has 100 points, log-spaced. Keep it a decade beyond the slowest and fastest populations expected: occupation piled up at either end says the grid is too short. A D below what the localization error can tell from zero, roughly , is immobile.

at least 1e-06 µm²/s
   to (more)
   spectrum_fit.d_max
100 µm²/sThe largest D of the grid. at least 1e-05 µm²/s
   write per localization
   spectrum_fit.write_column
offD_post_um2_per_s: each piece's D onto its localizations.
state switching
   states
   switching_fit.states
2Diffusive states that switch, 1 to 3.

Compare the BIC of 1, 2 and 3 as for the jump distances. Three states have six rates, which need many switches to pin down: tracks long against the dwell times, or many of them. A state the data do not support comes out with a D close to another's or with rates at their bounds.

1 to 3
   write per localization
   switching_fit.write_columns
offhmm_state and hmm_p1, hmm_p2, ...: each localization's state and its probabilities.

Output

A line per analysis: the pooled D and α with the lags used and the offset, the median D and α per track; the states' D and fractions with the BIC, and with an axial range also each state's share of the jumps at one frame, before the correction. A figure: the pooled MSD with the line fitted, the histogram of D per track, the jumps at one frame with the fitted states, and, with several lags, each state's share of the jumps per lag – the model's (line), the jumps' own (dots, the mean of their memberships) and, with an axial range, its fraction of the particles (dashed). Per region, the values (msd_D_um2_per_s, msd_alpha, track_D_median_um2_per_s, jump_D1_um2_per_s, jump_fraction1, ..., jump_seen1, ..., spectrum_D1_um2_per_s, spectrum_fraction1, ..., n_pieces), the pooled MSD curve (lag_s, msd_nm2) and the spectrum (spectrum_D_um2_per_s, spectrum_occupation). The D spectrum adds a line with its peaks and their fractions and a panel of the occupations (with an axial range, of the particles, and of the jumps dashed); write per localization writes D_post_um2_per_s, each piece's D on its localizations (NaN on a track of one localization). State switching adds a line with each state's D, fraction and dwell time and the rates, the values hmm_D1_um2_per_s, hmm_fraction1, hmm_dwell1_s, hmm_rate12_per_s (from state 1 to 2), ..., hmm_bic, hmm_crowding (the fast jump over the spacing between particles: above 0.15 the rates come out high), and a panel of the states with the rates on arrows; write per localization writes hmm_state (0 the slowest state, -1 none) and hmm_p1, hmm_p2, ... (each state's probability), to colour the tracks by state or to measure where the particles bind.

Run on the view, the fit of every track is also kept as a region table of the track id ("per track_id: Tracking analysis"): n_locs, D_um2_per_s, alpha, lags and reduced_error (the localization error over D times the step), NaN for a track shorter than minimum length. Summarize/Histograms shows their distributions, and the region filter keeps the tracks of one population – alpha below 0.7, say – without a attribute per value; write per track is for colouring the tracks. Not when an ROI is drawn, since the table stands for every track the layer shows.

A good result: the MSD a straight line over its first points, α near 1 for free diffusion, the states' curves following the jumps' histogram, and the dots of the share per lag on their lines. Without an axial range, dots of the fast state that fall with lag below its flat line say that particles leave the focus: set one. A pooled MSD that bends down is confinement or a mixture of slow and fast particles; one that bends up, drift or directed motion. Per-track D of short tracks is broad even for one population: compare populations by the jumps' states, not by the width of that histogram.

Differences from SMAP

Based on SMAP's AnalyzeSPT (Ries 2020), rewritten. The main changes:

References