Skip to content

Commit b91c982

Browse files
authored
Merge pull request #114 from mbel-tech/docs/wiki-pages
docs: wiki pages for analysis, statistics, glossary and known issues
2 parents 6143d01 + 60a8f25 commit b91c982

21 files changed

Lines changed: 1398 additions & 9 deletions

‎.github/workflows/wiki.yml‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Publish docs/wiki/ to the GitHub wiki.
2+
#
3+
# The wiki is a second repository with no pull requests and no CI, so pages edited there
4+
# are unreviewed and unchecked -- and this project has already watched a hand-copied wiki
5+
# drift from its source within a day. So docs/wiki/ is the source of truth, reviewed like
6+
# code (scripts/check_wiki.py runs in the test gate), and this workflow is the only writer.
7+
# Tick Settings -> Features -> Wikis -> "Restrict editing to collaborators only" to keep it
8+
# that way.
9+
name: Wiki
10+
11+
on:
12+
push:
13+
branches: [main]
14+
paths:
15+
- "docs/wiki/**"
16+
- "scripts/check_wiki.py"
17+
- ".github/workflows/wiki.yml"
18+
workflow_dispatch:
19+
20+
permissions:
21+
contents: write
22+
23+
concurrency:
24+
group: wiki
25+
cancel-in-progress: false
26+
27+
jobs:
28+
publish:
29+
name: Publish to wiki
30+
runs-on: ubuntu-22.04
31+
steps:
32+
- uses: actions/checkout@v7
33+
34+
- name: Check the wiki source
35+
# Same check as tests/test_docs/test_wiki.py, run here too so a broken link can
36+
# never reach the published wiki even if the gate was bypassed.
37+
run: python scripts/check_wiki.py
38+
39+
- name: Publish
40+
# The default GITHUB_TOKEN can push to the wiki repository. If an organisation
41+
# policy blocks that, add a fine-grained PAT with wiki write access as the
42+
# WIKI_TOKEN secret and it is used instead.
43+
env:
44+
TOKEN: ${{ secrets.WIKI_TOKEN || secrets.GITHUB_TOKEN }}
45+
run: |
46+
set -euo pipefail
47+
git clone --quiet \
48+
"https://x-access-token:${TOKEN}@github.com/${GITHUB_REPOSITORY}.wiki.git" wiki
49+
rm -f wiki/*.md
50+
cp docs/wiki/*.md wiki/
51+
rm -f wiki/README.md # docs/wiki/README.md documents the source, not the wiki
52+
cd wiki
53+
git config user.name "github-actions[bot]"
54+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
55+
git add -A
56+
if git diff --cached --quiet; then
57+
echo "wiki already up to date"
58+
else
59+
git commit -m "Publish wiki from ${GITHUB_SHA::7}"
60+
git push --quiet
61+
echo "wiki updated"
62+
fi

‎CHANGELOG.md‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,50 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
1717
fixes (a name, suffix, folder or header row); nothing is added.
1818
- **GUI driver verbs `scan`, `confirm` and `shot-dialog`** drive the scan, the confirm dialog and
1919
Add as a user would, and a guard makes every file picker answer "cancelled" instead of blocking.
20+
- **Wiki: the pages between an export and a result.** Five new pages in
21+
`docs/wiki/`, written for the step the repository documentation did not
22+
cover — what to do with the numbers once they exist. *Analysis Recipes*
23+
works four designs (open-field thigmotaxis, shoaling cohesion, activity and
24+
freezing, within-session habituation) from `metrics_long.csv` to a fitted
25+
model, naming the metrics to select and the columns they produce.
26+
*Statistics and Pseudoreplication* states the unit of replication for each
27+
metric family — notably that every GL-\* metric is one value per session, so
28+
a tank of eight fish is one observation — plus bounded-ratio models, count
29+
offsets, circular headings and a reporting checklist. *Glossary* maps every
30+
term to the column that carries it. *Known Issues* is the dated list of what
31+
is currently wrong or in flux, which a tagged release cannot hold.
32+
*Reanalysing After a Metric Fix* answers the question the pre-1.0 warning
33+
raises: whether a dataset exported weeks ago is still current, via
34+
`manifest.json`, the changelog and a diff of the long tables.
35+
36+
The wiki is now published from `docs/wiki/` by `.github/workflows/wiki.yml`
37+
rather than copied by hand, which had already drifted in three of six pages
38+
within a day. `scripts/check_wiki.py` — in the test gate via
39+
`tests/test_docs/test_wiki.py` — resolves every `[[wiki link]]`, checks every
40+
repository link points at a file and heading that exist, rejects relative
41+
links (they do not resolve from a wiki page) and fails on a page orphaned
42+
from `_Sidebar.md`. A `_Footer.md` now carries the licence and the
43+
version-scope caveat on every page, and `README.md` links the wiki at last:
44+
wiki pages are excluded from code search and from search-engine crawling, so
45+
an unlinked wiki is unreachable.
46+
- **Wiki: install, recording, compatibility and citation pages.** Four more
47+
pages in `docs/wiki/`, covering what a user needs before and around a run.
48+
*Install and First Run* walks the unsigned-binary dialogs on each OS, the
49+
checksum verification that makes them safe to accept, what the app writes and
50+
where (`.t2d_cache` beside the project file, nothing outside the output
51+
directory), and how to uninstall. *Before You Record* is the pre-experiment
52+
checklist for the decisions that cannot be fixed afterwards: frame rate, a
53+
scale object in frame or body lengths accepted as the unit, identities,
54+
session-folder naming as `session_id`, and a metadata CSV template in both
55+
per-session and per-animal shapes with the Validator-label-versus-position
56+
trap spelled out. *Compatibility* is one table for idtracker.ai 6.x, legacy
57+
v5 and unsupported v4, the formats a scan names but cannot read, the pickle
58+
gate, the three OS install routes and the Python versions under CI.
59+
*Citing Track2Data* gives the idtracker.ai and software BibTeX, states that
60+
there is no release DOI yet and to cite the `app_version` / `project_hash`
61+
from `manifest.json` instead, and points at `METRIC_REFERENCES.csv` and the
62+
export's own `codebook.csv` for the per-metric citations a behavioural
63+
reviewer expects.
2064
- **`scripts/validate_blob_diagnostics.py`** — run it on a directory of real
2165
`session_*` folders to settle what the synthetic tests cannot: how far the
2266
blob-derived body length sits from the session-wide value (issue #72), how

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ A rendered site is published from these files at
203203
**<https://mbel-tech.github.io/Track2Data/>**, including a browsable
204204
catalogue of all 50 metrics with their formulas, units and DOIs.
205205

206+
The **[wiki](https://github.com/mbel-tech/Track2Data/wiki)** covers what sits
207+
around that reference material and is not pinned to a release:
208+
[analysis recipes](https://github.com/mbel-tech/Track2Data/wiki/Analysis-Recipes)
209+
from an export to a fitted model,
210+
[statistics and pseudoreplication](https://github.com/mbel-tech/Track2Data/wiki/Statistics-and-Pseudoreplication),
211+
a [glossary](https://github.com/mbel-tech/Track2Data/wiki/Glossary) of every
212+
exported column, and
213+
[known issues](https://github.com/mbel-tech/Track2Data/wiki/Known-Issues).
214+
Its source is [`docs/wiki/`](docs/wiki/).
215+
206216
**Using it**
207217

208218
- [`docs/guide/`](docs/guide/USER_GUIDE.md) — the user guide (also as a [PDF](docs/guide/Track2Data_User_Guide.pdf)): every screen, with screenshots, plus the output-file reference and troubleshooting

‎docs/wiki/Analysis-Recipes.md‎

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# Analysis recipes
2+
3+
**Applies to:** Track2Data v0.1.0 and later. Column names are as exported; check
4+
`codebook.csv` for units.
5+
6+
Four worked designs, from a finished export to a fitted model. Each one names the metrics to
7+
tick on the **Metrics** screen, the columns they produce, the model the design calls for, and
8+
the mistake that specific design invites. They are starting points for common assays, not
9+
recommendations for your experiment.
10+
11+
Runnable versions of the loading and modelling code ship with the repo:
12+
[`examples/analysis/analyse.R`](https://github.com/mbel-tech/Track2Data/blob/main/examples/analysis/analyse.R)
13+
and
14+
[`examples/analysis/analyse.py`](https://github.com/mbel-tech/Track2Data/blob/main/examples/analysis/analyse.py).
15+
The statistical reasoning behind the random-effects structure used throughout is in
16+
[[Statistics and Pseudoreplication]].
17+
18+
## Loading the export (all recipes start here)
19+
20+
`metrics_long.csv` is one row per value: `session_id`, `individual_id`, `zone_name`,
21+
`metric_id`, `column`, `value`, `unit`. Reshape the rows you need and nothing else.
22+
23+
```r
24+
library(dplyr); library(tidyr); library(readr)
25+
26+
run <- "out"
27+
long <- list.files(run, "^metrics_long\\.csv$", recursive = TRUE, full.names = TRUE) |>
28+
lapply(read_csv, show_col_types = FALSE) |> bind_rows()
29+
sessions <- read_csv(file.path(run, "sessions.csv"), show_col_types = FALSE)
30+
codebook <- read_csv(file.path(run, "codebook.csv"), show_col_types = FALSE)
31+
32+
# Per-individual metrics, excluding zone rows and the provenance diagnostic.
33+
individual <- long |>
34+
filter(is.na(zone_name), !is.na(individual_id), metric_id != "D-11") |>
35+
select(session_id, individual_id, column, value) |>
36+
pivot_wider(names_from = column, values_from = value)
37+
38+
# Coverage, to weight or exclude by.
39+
quality <- long |> filter(metric_id == "D-11") |>
40+
select(session_id, individual_id, column, value) |>
41+
pivot_wider(names_from = column, values_from = value)
42+
```
43+
44+
Join your treatment labels from the metadata you supplied on the **Metadata** screen (they
45+
travel through to every table), or from `sessions.csv` if the treatment is per session.
46+
47+
---
48+
49+
## Recipe 1 — Open-field thigmotaxis
50+
51+
**Question.** Do treated animals spend more time near the wall?
52+
53+
**Metrics to select.** Z-1 (time in each zone), Z-8 (Jacobs' D), IL-14 (wall-distance
54+
thigmotaxis), IL-3 (distance from arena centre). Draw `wall` and `centre` zones on the
55+
**Zones** screen, or use IL-3/IL-14, which need no zones.
56+
57+
**Columns.** `time_pct` and `time_s` per `zone_name` (Z-1); `jacobs_d` (Z-8);
58+
`wall_contact_time_pct`, `mean_wall_distance_px` (IL-14); `time_in_centre_pct`,
59+
`mean_centre_distance` (IL-3).
60+
61+
```r
62+
wall <- long |>
63+
filter(metric_id == "Z-1", zone_name == "wall", column == "time_pct") |>
64+
select(session_id, individual_id, wall_time = value) |>
65+
inner_join(filter(quality, frac_frames_used >= 0.80) |>
66+
select(session_id, individual_id), by = c("session_id", "individual_id")) |>
67+
left_join(treatments, by = "session_id")
68+
69+
# A fraction in [0, 1]: beta, not Gaussian.
70+
glmmTMB::glmmTMB(wall_time ~ treatment + (1 | session_id),
71+
family = glmmTMB::beta_family(), data = wall)
72+
```
73+
74+
**The trap.** `time_pct` is a fraction, and zone occupancy sums to 1 across zones — so wall
75+
and centre time are not two independent outcomes, they are one. Pick the zone you
76+
pre-registered, or use `jacobs_d`, which is already corrected for how much of the arena each
77+
zone occupies. Zone fractions also depend on where you drew the boundary: keep the zone
78+
definition identical across sessions, and check the resolution warning if you reused zones
79+
drawn on a different image size.
80+
81+
---
82+
83+
## Recipe 2 — Shoaling cohesion across a treatment
84+
85+
**Question.** Does the treatment change how tightly the group swims together?
86+
87+
**Metrics to select.** GL-1 (NND), GL-2 (IID), GL-3 (polarisation), GL-6 (cohesion index);
88+
optionally GL-4 (hull area), GL-10 (group spread), GL-11 (order state).
89+
90+
**Columns.** `mean_nnd_px` / `_cm` / `_bl`, `mean_iid_*`, `mean_polarisation`,
91+
`cohesion_index`, `mean_hull_area_px2`, `mean_group_spread_*`, `polarised_time_pct`,
92+
`milling_time_pct`, `swarm_time_pct`.
93+
94+
```r
95+
group <- long |>
96+
filter(metric_id %in% c("GL-1", "GL-3", "GL-6"),
97+
column %in% c("mean_nnd_bl", "mean_polarisation", "cohesion_index")) |>
98+
select(session_id, column, value) |>
99+
pivot_wider(names_from = column, values_from = value) |>
100+
left_join(select(sessions, session_id, n_animals, fps, duration_s), by = "session_id") |>
101+
left_join(treatments, by = "session_id")
102+
103+
stopifnot(dplyr::n_distinct(group$n_animals) == 1) # see below
104+
lm(mean_nnd_bl ~ treatment, data = group) # n = sessions, not animals
105+
```
106+
107+
**The trap.** These are **one value per session**. A tank of eight fish is one observation,
108+
so the design needs replicate tanks; with four tanks per treatment you have *n* = 4. Group
109+
size is the second trap: NND falls as animals are added, for geometric reasons alone, so an
110+
unmatched group size will look like a treatment effect. Match group size, or model
111+
`n_animals` explicitly and expect to defend it. Prefer `mean_nnd_bl` to `mean_nnd_cm` when
112+
body size differs between groups — distance in body lengths is the comparable quantity.
113+
114+
---
115+
116+
## Recipe 3 — Activity and freezing
117+
118+
**Question.** Does the treatment change how much animals move, and how their freezing is
119+
organised in time?
120+
121+
**Metrics to select.** IL-4 (activity / freezing fraction), IL-7 (freezing-bout statistics),
122+
IL-2 (speed), IL-1 (path length).
123+
124+
**Columns.** `active_fraction`, `freezing_fraction`, `threshold_px_s` (IL-4);
125+
`freezing_bout_count`, `mean_freezing_duration_s`, `total_freezing_duration_s`,
126+
`min_bout_frames_used`, `bout_criterion_effective` (IL-7); `mean_speed_cm_s`,
127+
`median_speed_cm_s`, `max_speed_cm_s` (IL-2); `path_length_cm` (IL-1).
128+
129+
```r
130+
act <- individual |>
131+
left_join(select(sessions, session_id, duration_s), by = "session_id") |>
132+
left_join(treatments, by = "session_id")
133+
134+
# A rate: model it directly.
135+
lme4::lmer(mean_speed_cm_s ~ treatment + (1 | session_id), data = act)
136+
137+
# A count: exposure offset, not a ratio.
138+
glmmTMB::glmmTMB(freezing_bout_count ~ treatment + offset(log(duration_s)) + (1 | session_id),
139+
family = glmmTMB::nbinom2, data = act)
140+
```
141+
142+
**The trap.** "Freezing" is a threshold decision, not an observation: IL-4 reports the speed
143+
threshold it used (`threshold_px_s`), and IL-7 reports the minimum bout length actually
144+
applied (`min_bout_frames_used`, `bout_criterion_effective`). Both must be reported, and both
145+
must be identical across the groups you compare. Smoothing matters more here than for any
146+
other family — a wider window suppresses the small displacements that decide whether a frame
147+
counts as freezing — so check `track2data sensitivity` before publishing a bout result.
148+
`path_length_cm` is a total: use speed, or an offset.
149+
150+
---
151+
152+
## Recipe 4 — Habituation over time within a session
153+
154+
**Question.** Does activity decline across the session, and does the treatment change the
155+
slope?
156+
157+
**Setup.** Set **time bins** on the Metrics screen (for example 60 s). Summary tables then
158+
carry one row per animal per bin, with `bin_index`, `bin_start_s`, `bin_end_s`.
159+
160+
**Metrics to select.** IL-2, IL-1, IL-4, plus Z-1 if the question is zone use over time.
161+
162+
```r
163+
bins <- read_csv(file.path(run, "tiny_session", "trial_activity_summary.csv"),
164+
show_col_types = FALSE) |>
165+
filter(!is.na(bin_index)) |>
166+
left_join(treatments, by = "session_id")
167+
168+
lme4::lmer(mean_speed_cm_s ~ treatment * bin_index + (1 | session_id/individual_id),
169+
data = bins)
170+
```
171+
172+
**The trap.** Bins are repeated measures within a session, not extra sessions — the random
173+
structure has to keep both levels, and bins are autocorrelated, so a residual correlation
174+
structure (`glmmTMB` with `ar1(...)`, or `nlme::lme(correlation = corAR1())`) is often the
175+
honest model. Metrics that are not meaningful per window keep a single row with empty bin
176+
columns; filter on `!is.na(bin_index)` rather than assuming every row is binned. Short bins
177+
make every per-bin ratio noisy: check `n_frames_used` per bin before reading a trend.
178+
179+
---
180+
181+
## Before you report any of these
182+
183+
Confirm the sessions were poolable (`fps`, `n_animals`, segmentation settings — see
184+
`PROJECT_SUMMARY.md`), state your coverage threshold and the preprocessing settings from
185+
`manifest.json`, and record the `app_version` that produced the numbers. The full reporting
186+
checklist is at the end of [[Statistics and Pseudoreplication]]; what can still change before
187+
1.0 is in [[Known Issues]].

0 commit comments

Comments
 (0)