Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
88a7529
build(deps): tracksdata and HOCT in the track extra
tayllatheodoro Oct 20, 2026
f4f6e13
feat(track): choose the tracker: ultrack, tracksdata or HOCT
tayllatheodoro Oct 20, 2026
e7c9c98
feat(track): Trackastra as a tracker
tayllatheodoro Oct 20, 2026
77fc383
fix(track): merge one-child links of the label trackers into the parent
tayllatheodoro Oct 20, 2026
070c1f2
docs(skills): track-with-biahub, run and compare the trackers
tayllatheodoro Oct 20, 2026
9ec0ef1
docs(skills): A549 results of all four trackers in track-with-biahub
tayllatheodoro Oct 20, 2026
168faf9
fix(skills): compare_tracks picks v10 over v9 and scores F1 0 without…
tayllatheodoro Oct 22, 2026
47e0d6f
fix(track): require cellpose_config for label trackers; portable thre…
tayllatheodoro Oct 22, 2026
abb6b6a
docs(skills): track-with-biahub needs the segment extra for cellpose
tayllatheodoro Oct 22, 2026
13fef09
fix: tracksdata without candidate links; cells per frame over the who…
tayllatheodoro Oct 22, 2026
24e147e
docs(skills): restore the COMMANDS example in canonical-cli.md
tayllatheodoro Oct 22, 2026
5e0f8b0
fix(track): label trackers write empty outputs when there is nothing …
tayllatheodoro Oct 22, 2026
520c304
fix(skills): compare_tracks with unscored runs; tracksdata division_w…
tayllatheodoro Oct 22, 2026
64b7141
test(skills): compare_tracks summary with scored and unscored runs
tayllatheodoro Oct 22, 2026
d510d3a
fix(track): HOCT on edgeless graphs, partial solver overrides, missin…
tayllatheodoro Oct 22, 2026
038c1a3
build(deps): HOCT on Python < 3.14; gurobipy 13 stays on 3.14
tayllatheodoro Oct 22, 2026
e07f3bb
fix(track): check HOCT solver overrides at --init; Trackastra on one …
tayllatheodoro Oct 22, 2026
0c25299
docs(skills): view_runs.py to compare finished tracker runs in napari
tayllatheodoro Oct 22, 2026
dee5912
fix(skills): view_runs gives every run four layer slots
tayllatheodoro Oct 22, 2026
05265cc
docs(skills): tune a tracker with biahub track on one position, not d…
tayllatheodoro Oct 22, 2026
905c809
fix: HOCT on single-edge graphs; run-wide track length weighted by tr…
tayllatheodoro Oct 22, 2026
43ea1d8
fix(track): HOCT movies whose inference windows are all sparse
tayllatheodoro Oct 22, 2026
16fcd4e
Merge origin/main into feat/track-tracksdata-hoct
ieivanov Oct 26, 2026
e65d803
docs(track): Gurobi is optional; ilpy trackers use SCIP even with the…
tayllatheodoro Oct 26, 2026
aa24553
docs(track): tracked labels are the final segmentation; Gurobi token …
tayllatheodoro Oct 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .claude/skills/track-with-biahub/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
name: track-with-biahub
description: >-
Track nuclei in a mantis plate with `biahub track` and choose the tracker: ultrack
(default), tracksdata (ILP), HOCT (learned edge scores + ILP) or Trackastra
(transformer). Finds the segmented projected plate, builds one config per tracker from
templates, runs a few positions per tracker on Bruno into that plate side by side,
compares tracks and divisions
(and scores divisions against TrackEdit annotations when they exist), checks the
result visually, and recommends a tracker and settings. Use when asked to "track",
"compare trackers", "try trackastra / HOCT / tracksdata", "which tracker is better
for", or to tune tracking on a dataset. For a full pipeline run (reconstruction
through tracking), use reconstruct-with-nextflow instead.
---

# Track and compare trackers with biahub track

Invocation: `/track-with-biahub <DATASET_OR_PLATE> [--trackers ultrack,trackastra,...]
[--positions R/C/FOV ...]`, or any request to track a plate or compare trackers.

The flow is `biahub project` (the Z=1 plate) -> `biahub segment` (cellpose labels,
`labels/nuclei`, written into that plate) -> `biahub track` once per tracker -> compare.
The A549 pipeline does the first two (and one ultrack run, `labels/tracks_nuclei`); this
skill runs the trackers. Track neither projects nor segments: every tracker reads the same
`labels: nuclei`. `ultrack` re-segments from them and links; `tracksdata`, `hoct` and
`trackastra` link the labels as they are. Each run writes INTO the plate, named by its
config's `output_label` (`nuclei_<tracker>`): `labels/nuclei_<tracker>` (value = track id)
and `tracks_nuclei_<tracker>_<fov>.csv` per position; ultrack also writes
`tracks_nuclei_ultrack.geff`, the other three no GEFF yet. All go through the sibling
filter (`min_sibling_length`), so outputs compare directly. The tracked labels are the final
segmentation (prefer them over `labels/nuclei` downstream); only ultrack changes the masks,
so its detections can differ from the other trackers' even on the same input.

## 0. Load context

- `references/trackers.md`: what each tracker does, its settings, solver and licence notes,
what the A549 benchmark found, known pitfalls.
- `references/evaluation.md`: how to compare runs, with and without annotations, and the
visual check.

## 1. Confirm the environment

- On Bruno (`squeue` works); the biahub checkout on `main`, `source .venv/bin/activate`,
installed with the `track` (trackers) extra, and `segment` (cellpose) if the plate still
needs segmenting (`uv sync --extra segment --extra track`): `python -c "import ultrack,
tracksdata, hoct, trackastra"` succeeds.
- Run launches from tmux or as `sbatch` jobs, never in a login shell that may drop.

## 2. Find the input plate

The plate `biahub track` reads: the projected (Z=1) plate of a mantis-v2 run,
`<project>/<N>-assemble/<dataset>_proj.zarr`, with the segment label image
`labels/nuclei` in every position (`ls <plate>/<R>/<C>/<FOV>/labels`). A549 pipeline runs
have both. Without the labels, segment the chosen positions first with the A549 segment
config (`nextflow/configs/a549/segment.yml`; `run_track.sh` has the two commands); without
the projected plate, run `biahub project` (`nextflow/configs/a549/project.yml`) on the
assembled plate first. hoct and Trackastra also read the image the labels were segmented
from (the first channel segment recorded, e.g. `nuclei_prediction`): check it is in the
plate (`iohub info <plate>/<R>/<C>/<FOV>`). Read one chunk to confirm the store is intact.

## 3. Pick positions and trackers

- Positions: 2-4 FOVs covering each condition (mock and infected wells behave differently;
infected wells have more false divisions). Prefer FOVs with TrackEdit annotations
(`references/evaluation.md`), so divisions can be scored.
- Trackers: those asked for; otherwise all four, with ultrack as the reference.

## 4. Build the configs

Copy `templates/track-<tracker>.yml` for each tracker into the run directory. They share
`labels: nuclei`, `output_mode: "2D"` and `min_sibling_length: 3`, and differ only in
`tracker:`, its block and `output_label: nuclei_<tracker>`, so differences come from the
tracker alone. Adapt per dataset: `labels` (the segment model name), distances (in um) for
other pixel sizes, and `image_channel` in `hoct_config` / `trackastra_config` when the
label image was not written by `biahub segment` or another channel should be read
(default: the first channel segment recorded in the labels' `biahub-segment`
provenance). Segmentation settings (cellpose model, diameter, min_size) belong to the
segment config, not here. An `output_label` already in the plate is reused and
overwritten: pick a new one per run to keep. A test keeps the templates on the current
schema.

## 5. Present the plan

Show: the plate and positions (with conditions), the trackers and their non-default
settings and `output_label`s (the label images that will be added to the plate), whether
the positions need segmenting first, the run directory, cost (one job per tracker;
~10-15 min per A549 FOV when track still ran cellpose, less now; tracksdata and HOCT
solve with SCIP, see `references/trackers.md`), and whether annotations
exist for scoring. Wait for a go.

## 6. Scaffold and launch

In a run directory (e.g. `<project>/tracking-comparison/<date>/`), copy the configs and
`templates/run_track.sh`, fill in `BIAHUB`, `PLATE`, `POSITIONS`, run the `--init`s one
after another (concurrent `--init`s on one plate can drop each other's entry from the
positions' label list), then submit one job per tracker:

```bash
for c in track-*.yml; do INIT_ONLY=1 bash run_track.sh $c; done
for c in track-*.yml; do sbatch --job-name=track_$(basename $c .yml) run_track.sh $c; done
```

Each writes into the plate (`labels/<output_label>` and its CSVs); the run directory
holds the configs, the script and the job logs. No `-o`: it would only keep ultrack's
databases. hoct and Trackastra want the GPU; ultrack and tracksdata are CPU only, so
their jobs may go to `cpu` (drop `--gres`). Not `preempted`: tracking cannot resume, so a
preemption restarts it from scratch.

## 7. Monitor

`squeue -u $USER -n track_track-ultrack,...`; the job logs (`track_*_<jobid>.out`) print
`Tracking with <tracker>`, the cells per frame, and one `Sibling filter (min_length=3):
N -> M tracks` line per FOV when done.

## 8. Compare

```bash
python templates/compare_tracks.py --plate <plate> \
nuclei_ultrack nuclei_tracksdata nuclei_hoct nuclei_trackastra [tracks_nuclei] \
[--gt "<annotation dir>/{fov}/v*_tracks.csv" --pixel-size 0.1133]
```

Runs are named by their tracked label (`output_label`; `tracks_nuclei` is the pipeline's
own ultrack run). Per run: tracks, divisions, cells per frame, mean track length; with
annotations, division precision / recall / F1 (`references/evaluation.md` for how to
read them). Then check divisions visually on one FOV per condition with
`templates/view_runs.py` (`references/evaluation.md`).

## 9. Report and recommend

Report the comparison table per condition, what the visual check showed, and a
recommendation: which tracker, and which settings to tune next. With no annotations, say
the comparison is counts only. Write the result next to the runs (`RESULT.md`).

## 10. Handle errors

See "Known pitfalls" in `references/trackers.md` (solver fallback, model downloads,
one-child links, 2D only). Do not delete a run directory or a label image in the plate
to retry without asking.
57 changes: 57 additions & 0 deletions .claude/skills/track-with-biahub/references/evaluation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Comparing tracking runs

## With annotations (preferred)

TrackEdit-corrected tracks are the reference. Known annotated mantis-v2 FOVs:

- 2026_04_28_A549_SEC61B_DENV: `5-track/annotation/2026_04_28_A549_SEC61B_DENV_config_tracking/<fov>/v*_tracks.csv`
for `A_2_001002`, `A_2_002002` (mock) and `A_3_000002`, `A_3_001002` (DENV); 78 divisions.
Read-only: never write in an annotation folder.

`templates/compare_tracks.py --gt "<dir>/{fov}/v*_tracks.csv"` matches divisions: a division
is the daughters' first frame and the parent's last position; predicted and annotated
divisions match within 2 frames and 10 um, one-to-one. On the A549 FOVs it reproduces the
benchmark's scorer within 0.01 F1.

How to read it:
- **precision** low: false divisions (a virtual-staining hallucination or a neighbour linked as
a daughter, a lobed nucleus split for a frame). The sibling filter removes the short ones.
- **recall** low: missed divisions (daughters linked as one track, or the mitotic cell lost).
- report mock and infected wells separately: infected wells usually have more false
divisions.
- the annotations were curated from an ultrack run, which may favour ultrack slightly.

## Without annotations

Counts only, so say so in the report:
- `cells_per_frame` should agree across trackers (they share the labels); a large difference
means a tracker drops or duplicates objects.
- `tracks` vs cells per frame: more tracks per cell means more fragmentation.
- `divisions`: compare with the expected division rate (A549 divides roughly once a day); a tracker
with far more divisions than the others is likely calling false ones.
- `track_length`: longer is better, if divisions and cells per frame look right.

## Visual check

On one FOV per condition, open the finished runs side by side:

```bash
python templates/view_runs.py --plate <plate> --fov <row/col/fov> \
nuclei_ultrack nuclei_tracksdata nuclei_hoct nuclei_trackastra
```

One panel per run (the input channel, the run's labels, its tracks, and a yellow circle on
every division it calls), with shared time and zoom. Look at the divisions one tracker calls
and another does not: ten of those say more about which tracker to trust than the counts.
To tune one tracker on a single FOV, copy its config, change the settings and give it a
new `output_label` (e.g. `nuclei_<tracker>_v2`; reusing one overwrites that run), rerun
just that position, and view it next to the previous run:

```bash
biahub track --init -i <plate>/<row/col/fov> -c track-<tracker>-v2.yml
biahub track --cluster debug -i <plate>/<row/col/fov> -c track-<tracker>-v2.yml
python templates/view_runs.py --plate <plate> --fov <row/col/fov> \
nuclei_<tracker> nuclei_<tracker>_v2
```

(`scripts/debug_track.py` predates the current track settings and runs ultrack only.)
102 changes: 102 additions & 0 deletions .claude/skills/track-with-biahub/references/trackers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Trackers in `biahub track`

Select with `tracker:` in the track config. All four read the label image `biahub segment`
wrote into the plate (`segmentation_method: labels`, the default; `labels: nuclei`); ultrack
can also use the legacy `foreground_contour`. The other three need `segmentation_method:
labels` and `output_mode: 2D` (refused at `--init` otherwise). Track does not segment or
project: `cellpose_config`, `segmentation_method: cellpose` and `z_slicing` are refused.

All write into the `-i` plate, per position: the tracked labels `labels/<tracked label>`
(T, 1, Z, Y, X) and `<stem>_<row>_<col>_<fov>.csv`; ultrack also `<stem>.geff`, the other
three no GEFF yet (follow-up issue). The tracked label is `tracks_<labels>` and the stem
`tracks`, or with `output_label: X`, `X` and `tracks_X` (the templates set
`nuclei_<tracker>`).

The tracked labels are the final segmentation: downstream, prefer them over the label image
segment wrote. Only ultrack changes the masks (it picks among segmentation hypotheses built
from the labels' contours, so it can merge an over-split nucleus or split two touching
ones); tracksdata, HOCT and Trackastra keep the segment labels unchanged. When comparing
trackers, differences in detections come from ultrack's re-segmentation, not the linking.

| tracker | how it links | settings block | runs on | needs |
|---|---|---|---|---|
| `ultrack` (default) | re-segments a hierarchy from the labels, then an ILP picks segments and links | `tracking_config` (ultrack's MainConfig) | CPU | nothing extra |
| `tracksdata` | region nodes, distance + IoU edges, ILP | `tracksdata_config` | CPU | ILP solver |
| `hoct` | learned edge scores (HOCT's model), then an ILP; edges may skip frames | `hoct_config` | GPU if present | model weights, ILP solver |
| `trackastra` | a transformer predicts links; greedy or ILP | `trackastra_config` | GPU if present | model weights (ILP mode: solver) |

## Settings

Distances are in um, converted with the plate's pixel size. Defaults are the A549 benchmark's
pixel settings at 0.1133 um/px (mantis v2).

- **tracksdata**: `distance_threshold_um` (candidate edges, 22.66), `n_neighbors` (3),
`distance_norm_um` (edge weight `-IoU * exp(distance / norm)`, 11.33), `node_weight` (-2),
`appearance_weight` (5), `disappearance_weight` (5), `division_weight` (1),
`border_margin_um` (6.80) and `border_appearance_weight` (-1: appearing at the image edge is
cheap). Raising `division_weight` allows fewer divisions; edge rewards are in [-1, 0], so
weights on the scale of 10-100 suppress divisions entirely.
- **hoct**: `model` (`general_v1`, or a path), `image_channel` (below),
`distance_threshold_um` (33.99), `n_neighbors` (5), `max_delta_t` (3: edges may skip up to
2 frames), `solver` (HOCT's `ILPSolverConfig` fields). HOCT runs in pixel space, as its
models were trained.
- **trackastra**: `model` (`general_2d`, `ctc`, or a trained model folder), `mode`
(`greedy`, `greedy_nodiv` for no divisions, `ilp`) and `image_channel` (below). No
distance settings.
- **image_channel** (hoct, trackastra): the image they read with the labels. Default (null):
the first channel `biahub segment` recorded in the label image's `biahub-segment`
provenance (`nuclei_prediction` for A549). Set it to read another channel, or when the
label image was not written by segment; `--init` fails if it does not resolve to a
channel of the plate.
- **ultrack**: `tracking_config` with `segmentation_config` (`min_area`, `max_area`,
`min_frontier`), `linking_config` (`max_distance` in um, `distance_weight`, `max_neighbors`)
and `tracking_config` (appear / disappear / division weights), plus `labels_sigma` (contour
smoothing of the labels, 5 px).

## What the A549 benchmark found

Same cellpose labels (made by track itself then; now segment.yml + project.yml's 60-plane
mean, same settings) and `min_sibling_length: 3`, untuned defaults
for the three new trackers. 2026_04_28: 4 TrackEdit FOVs, 78 divisions (division F1, with
precision / recall). 2026_04_21: 5 DENV FOVs, 38 divisions from mitosis labels.

| tracker | 04_28 F1 | precision | recall | mock F1 | DENV F1 | tracks (GT 287) | 04_21 divisions found |
|---|---|---|---|---|---|---|---|
| ultrack | 0.68 | 0.60 | 0.79 | 0.70 | 0.63 | 376 | 19 |
| trackastra | 0.63 | 0.71 | 0.57 | 0.65 | 0.60 | 355 | 14 |
| hoct | 0.53 | 0.68 | 0.43 | 0.59 | 0.47 | 311 | 7 |
| tracksdata | 0.52 | 0.47 | 0.57 | 0.48 | 0.55 | 331 | 17 |

- ultrack is the default: best F1 and recall, and the best tuned.
- Trackastra and HOCT call fewer divisions with higher precision (Trackastra 0.82 in mock
wells): good when false divisions cost more than missed ones, and as independent opinions.
- tracksdata is the least accurate with these defaults and needs tuning (`division_weight`,
`appearance_weight`); HOCT fragments least (311 tracks).
- Each new tracker took ~13-16 min for 4-5 A549 FOVs on one GPU node with cellpose included
(now done by segment), ~11 GB peak.

## Known pitfalls

- **ILP solver**: Gurobi is optional; nothing fails without a licence. ultrack uses Gurobi
when licensed, otherwise CBC. Biohub HPC has a Gurobi token-server licence, but each user
must be added to it (ask HPC); then `~/gurobi.lic` with
`TOKENSERVER=license01.czbiohub.org` enables it. tracksdata, HOCT and Trackastra's `ilp` mode solve through ilpy, which uses
SCIP even with the Biohub token-server licence: ilpy reads `LicenseID == 0` as gurobipy's
size-limited pip licence, and token-server licences also report 0. The log then shows
`Solver failed with Gurobi, trying Scip.` That is expected, not an error. Gurobi is faster
and uses less memory; solved to the same gap, all solvers give similar solutions. SCIP can
take very long on larger problems: on A549 a tracksdata solve takes seconds per FOV, but
Trackastra's `ilp` mode took 8-35 min per run over ~50 FOVs. NVIDIA cuOpt (GPU, open
source; used by the OPS project, royerlab/hoct#9) is an alternative, not wired into
biahub. Trackastra's default `greedy` mode needs no solver.
- **Model weights** download on first use: `--init` fetches them once (HOCT to its pooch
cache, Trackastra to `~/.local/share/trackastra/models`). A worker without network needs
them cached first.
- **One-child links**: HOCT links across skipped frames; biahub merges a track that is its
parent's only child back into the parent (the sibling filter requires 0 or 2 children).
- **2D only** for tracksdata, HOCT and Trackastra.
- **Missing labels**: `--init` fails if a position lacks `labels/<labels>`: segment it first.
- **One plate, several runs**: run the `--init`s one after another (each adds its label to the
positions' label list); an `output_label` already in the plate is overwritten by a rerun.
- Jobs belong on `gpu` (hoct, Trackastra) or `cpu` (ultrack, tracksdata), not `preempted`:
tracking does not resume.
Loading
Loading