Write the tracking and two-state diffusion analysis of a microscopy core's single-molecule tracking pipeline from its localisation tables (linking through blinking gaps, beads and false spots, localisation-error and motion-blur corrections, switching rates, per-spot states) under a time limit; it is run on further movies with known molecular motion.
harbor run -t reactive-labs/smt-diffusion-statesharbor download reactive-labs/smt-diffusion-statesYou are Marta Ferreira, postdoc in the Castellanos lab at the Tarnwell Institute for Cell Biology. The institute's
Light Microscopy Core runs TIRF-2, the single-molecule TIRF set-up both the Castellanos lab (Halo-EGFR) and the
Okonkwo lab (GPI-anchored Halo probe) use for tracking. Today is Monday 7 December 2026. Ana Castellanos has asked
you for the program that turns the core's localisation tables into tracks and two-state diffusion parameters on the
core's analysis server. Her mail is in /app/inputs/mail/.
You have 60 minutes. Whatever is in /app/output when the time is up is graded, so keep a working program saved as
you go.
In /app/inputs:
localisations/: the core's localisation tables for the ten single-colour movies of the two projects, one CSV per
movie, named like the movie.acquisitions/: the twelve movies of the current projects, one folder each with the Halde Acquire record (.ini)
and the raw frames (.raw), and manifest.csv.calibration/: PSF z-stacks, dark references, registration-bead stacks, EM gain checks and the camera's defect map.docs/: LMC-SOP-031 rev C, the camera test sheet and manual excerpt, the grid calibration report, the vendor's
service report and the TIRF-2 logbook export.legacy/: the scripts used so far, msd_states_v1.py among them, and their author's handover notes./app/output/smt_states.py, run as
python3 /app/output/smt_states.py <record.ini> <localisations.csv> <out_dir>
<record.ini> is the movie's Halde Acquire record and <localisations.csv> its localisation table in the format
of SOP-031 section 8 (the raw frames are not given). The program writes two files into <out_dir>:
summary.json, an object with these keys (numbers):
| Key | Content |
|---|---|
D_bound_um2_s |
diffusion coefficient of the bound (slow) state, um^2/s |
D_free_um2_s |
diffusion coefficient of the mobile (fast) state, um^2/s |
bound_fraction |
fraction of molecules in the bound state at steady state, 0 to 1 |
k_bound_to_free_per_s |
switching rate from the bound to the mobile state, 1/s |
k_free_to_bound_per_s |
switching rate from the mobile to the bound state, 1/s |
The diffusion coefficients are those of the molecules' true motion: what the localisation error and the camera exposure do to the measured displacements is not part of them.
states.csv, with a header line row,track,state and one line per row of the localisation table: row the
0-based index of the table's data row, track an integer track id (rows of one molecule share it), state 1 for
bound, 2 for mobile, 0 for a row that is not a molecule (bead, false spot).
The program runs with Python 3.12, numpy, scipy and pandas, on one CPU core with 3 GB of memory and no network,
and must finish each movie within 20 seconds. Tables have up to 3000 frames and about 60000 rows. It is run as
another user from a copy of /app/output: it may load helper files that you put in /app/output (found relative
to __file__), but /app/inputs is not there when it runs.
/app/output/results/<movie>/summary.json and /app/output/results/<movie>/states.csv for each of the ten movies
in localisations/ (for example /app/output/results/20260309_EGFR_d1_c03/summary.json).
Rafael Domingues, the core's facility engineer, runs the program on the core's validation set: 30 further TIRF-2 movies, given as record and localisation table, that the core generates with its model of the instrument and of the two probes, so the molecules' true motion and states are known. Twelve re-image the cells of the movies in hand in other sessions; eighteen use protocols, settings, dye concentrations and dates that SOP-031 and the groups' plans allow, some of which the movies in hand show once or not at all. The ten result sets in hand are compared with their known values in the same way.
Per movie, each quantity's error against the true value is compared with the error of the core's reference analysis on the same movie (allowance: the larger of the reference's error and the floor below):
| Quantity | Error | Floor | Full credit up to | No credit at |
|---|---|---|---|---|
D_free_um2_s |
|ln(reported / true)| | 0.03 | allowance + 0.03 | allowance + 0.09 |
D_bound_um2_s |
|ln(reported / true)| | 0.10 | allowance + 0.08 | allowance + 0.24 |
bound_fraction |
|reported - true| | 0.03 | allowance + 0.03 | allowance + 0.09 |
| each switching rate | |ln(reported / true)| | 0.15 | allowance + 0.12 | allowance + 0.36 |
| states | balanced accuracy of state over the rows of true molecules (mean of the bound and the mobile rows' accuracy), shortfall against the reference |
0.025 below (protocol C: 0.06) | 0.075 below (protocol C: 0.18) |
Credit falls linearly between the last two columns. Movie score = (0.25 + 0.75 x states credit) x (0.30 D_free + 0.25 D_bound + D_free credit x (0.20 bound fraction + 0.125 + 0.125 rates)). For 200 ms dwell movies (protocol C) the mobile state is not observed: there the movie score is (0.25 + 0.75 x states credit) x D_bound credit. A crash, a time-out, a missing or unreadable file or a missing key scores zero for that movie. The final score is 80 % the mean over the 30 validation movies and 20 % the mean over the ten movies in hand.