diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-27 11:22:38 +0000 |
|---|---|---|
| committer | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-27 11:22:38 +0000 |
| commit | cd9f46633bcc55ab2a72cda1a0f1a667e79c2e57 (patch) | |
| tree | e56b04e85f9d69b28695ed57345c1dff28d8d14c /docs | |
| parent | f76043bf82b6c86b5e844b27b53e957d770aeb33 (diff) | |
| parent | 4f609454ba5b8db543863d6f20b042ca15cfe99f (diff) | |
| download | genenetwork4-cd9f46633bcc55ab2a72cda1a0f1a667e79c2e57.tar.gz | |
Merge branch 'main' into search/extract-engine-merge
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/genotypes.md | 17 | ||||
| -rw-r--r-- | docs/listings.md | 78 | ||||
| -rw-r--r-- | docs/migration.md | 2 | ||||
| -rw-r--r-- | docs/ravanan-slurm.md | 11 | ||||
| -rw-r--r-- | docs/www/SKILL.md | 99 | ||||
| -rw-r--r-- | docs/www/operator-checklist.md | 30 |
6 files changed, 209 insertions, 28 deletions
diff --git a/docs/genotypes.md b/docs/genotypes.md index 55f7a6d..127ff68 100644 --- a/docs/genotypes.md +++ b/docs/genotypes.md @@ -85,9 +85,20 @@ QTLReaper and R/qtl; 2 → GEMMA; 3 → R/qtl; 4 → GEMMA and PLINK. On this database: `BXD` = 1, `HET3-ITP` = 3, `HSNIH-Palmer` = 2, `HS` = NULL. `HET3-ITP` is UM-HET3, a 4-way cross (`@type:4-way`, `@mat:AB`, -`@pat:CD` in its `.geno` header), so R/qtl is the right engine even -though `bimbam/HET3-ITP.*` files exist — those are a biallelic -projection of a four-founder panel. +`@pat:CD` in its `.geno` header), so R/qtl is the right engine. The +`bimbam/HET3-ITP.*` files are **empty stubs** — every genotype cell is +`NA` — so every GEMMA route refuses them with `422 no_samples_aligned` +(after `individuals_with_genotypes` finds nobody with a call), while the +same panel is 45.8% dense in the `.geno` R/qtl reads. A real projection +has to pick a *founder* contrast: tried parent-of-origin +(`scripts/geno-to-bimbam.py`, maternal 1,2 -> 0, paternal 3,4 -> 1, mixed +-> 0.5) and it produced a working pair -- pangemma then ran HET3-ITP +10000 for 21.9 min -- but with **no associations**, because an advanced +4-way intercross is ~99.4% heterozygous, so that dosage is constant (881 +of 893 markers had exactly zero variance). The numeric-code -> +founder-pair table is not in the header, this repository, or +`rdata/HET3-ITP.RData` (qtl2 allele-probability arrays, not calls), so a +founder projection is a decision for the panel's owner. ## Measured runs (2026-11-07, this deployment) diff --git a/docs/listings.md b/docs/listings.md new file mode 100644 index 0000000..86b2fb0 --- /dev/null +++ b/docs/listings.md @@ -0,0 +1,78 @@ +# The listing shape: `limit_to`, `ids_only`, `names_only` + +Three optional query parameters, the ones GeneNetwork2 offers and this API did +not, on the listings a client has to enumerate: + +``` +GET /groups?names_only=true +GET /groups/BXD/traits?ids_only=true&limit_to=10001,BXD_0001 +GET /datasets/HC_M2_0606_P/probesets?names_only=true +``` + +## The rule that makes it safe + +**No listing parameters means exactly the answer this API has always given.** +The reply body is an untagged `Rows` enum (`Objects` or `Plain`), so the wire +shape is a plain JSON array either way and the default path is unchanged; only +the slim forms answer one value per row. That was the point of the design: the +default tenant of this API is an existing client, and a wrapper object would +have been a breaking change dressed up as a feature. + +* `limit_to=a,b,c` keeps the rows whose id, name, trait name, display name or + full name matches one of the values, case-insensitively. Rows keep their + order. +* `ids_only=true` answers one id per row; `names_only=true` one name. +* Asking for both shapes at once is a **422 `invalid_listing`** rather than a + parse-order coin toss. +* A `limit_to` value that matches nothing is **named in the reply's note**. A + silent empty answer is how "my trait is missing" becomes undiagnosable. + +## Where it is wired (2026-11-16) + +| endpoint | state | +|---|---| +| `GET /groups` | yes | +| `GET /groups/{group}/strains` | yes | +| `GET /groups/{group}/datasets` | yes | +| `GET /groups/{group}/traits` | yes — 15 060 traits in BXDPublish, the case that motivated this | +| `GET /datasets/{dataset}/probesets` | yes — 45 101 probesets | +| `GET /traits/{dataset}` | **no** — see below | + +Payloads for scale: `/datasets/HC_M2_0606_P/probesets` is 45 101 objects, +`/groups/BXD/traits` 15 060, `/groups/BXD/strains` 396. + +## Why `/traits/{dataset}` is not wired + +This listing returns probe *and* phenotype traits in one array, each row tagged +`category: "probeset"` (verified against a live reply — the rows are flattened, +so `category` is a field and a probeset's identifier is `probeset_id`; there is +no `id`). A bare id is therefore ambiguous, and the intended slim form is +`category:value` (`"probeset:1427571_at"`, `"publish:10001"`). + +Wire it was attempted and withdrawn: with the fields read correctly the +parameters were still ignored — every request answered the full 45 101 objects, +which is what a handler that never sees its `Query` does. Before editing that +handler again, settle one question: **which function serves `/traits/{dataset}`**. +`src/lib.rs` registers `traits`, `trait_info` and `trait_values` on overlapping +prefixes, so check the `operationId` of that path in `/openapi.json` rather than +assuming it is `traits.rs`'s `traits`. + +## Mechanics, for whoever adds the next one + +Three edits per handler plus one that is easy to miss: + +1. the three fields on the handler's query struct — or, if it has none, take + `crate::listing::ListingParams` directly (it is `IntoParams`, so it documents + itself); +2. the return type: `Envelope<Vec<T>>` → `Envelope<crate::listing::Rows>`; +3. shape the rows where the envelope is built, appending the `limit_to` note; +4. **and** the `body =` type in the handler's `utoipa::path` block. + `utoipa` typechecks that annotation against the return type, so changing one + and not the other fails as `could not find __path_<handler>` pointing at + `lib.rs`'s `routes!` macro — a misleading error that sends you to the wrong + file. This is the whole reason a `Rows` enum beats an `Envelope<Value>`: the + annotation changes by one word and the compiler keeps checking the real type. + +Also: `axum::extract::Query` must be in scope (three of the six handlers never +used it), and a handler whose `Found` branch builds its envelope inline +(`Ok(Json(ctx.envelope(...)))`) has to open that branch into a block. diff --git a/docs/migration.md b/docs/migration.md index b3f0d64..bd9879d 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -30,7 +30,7 @@ already exists in the API. | feature | GN1 | GN2 | GN3 | effort | why | +--------------------------------------+------+-----+------+--------+-----------------------------------------------------------+ | correlation matrix | yes | yes | no | S-M | decisions recorded; N^2 calls to the live correlate_named | - | limit_to / ids_only / names_only | no | yes | no | S | optional query params on existing listings | + | limit_to / ids_only / names_only | no | yes | no | S | 5 of 6 listings done 2026-11-16 (docs/listings.md); /traits/{dataset} open -- its rows are flattened and its Query never arrives, so check which handler serves it first | | tissue correlation | yes | yes | yes | S-M | TissueProbeSetData is in the DB; the maths already exists | | literature correlation | yes | yes | yes | S-M | LCorrRamin3 is a lookup table, no statistics involved | | whole-dataset sample matrix export | yes | yes | yes | S-M | one SQL sweep; the only choice is streaming/CSV vs JSON | diff --git a/docs/ravanan-slurm.md b/docs/ravanan-slurm.md index 391c447..ba715f3 100644 --- a/docs/ravanan-slurm.md +++ b/docs/ravanan-slurm.md @@ -28,6 +28,13 @@ backend): …`). | `RAVANAN_SLURM_NICE` | optional integer `--slurm-nice` | | `RAVANAN_SCRATCH` | optional `--scratch`; defaults to `RAVANAN_CACHE_DIR` when the backend is slurm | | `RAVANAN_CACHE_DIR` | where pheno files, logs, the compiled CWL and ravanan's `--store` live | +| `GEMMA_RAVANAN_WORKFLOW_MDB` | ccwl source for `"engine": "pangemma"` (default `cwl/gemma/gemma-loco-mdb.scm`) | +| `GEMMA_RAVANAN_MANIFEST_MDB` | manifest naming `pangemma-git` for that workflow (default `cwl/gemma/manifest-mdb.scm`); a manifest change needs a cold run, since ravanan keys a step on (script, inputs) | +| `GENO2MDB_CMD` | the lmdb store builder (`geno2mdb.py` from gemma-wrapper's `bin/`), staged into the store workflow as a `File` input | +| `GEMMA_PREPARE_WORKFLOW` | ccwl source of the missing-genotype treatment (default `cwl/gemma/prepare.scm`), run as its own job before the mapping workflow | +| `GEMMA_STORE_WORKFLOW` | ccwl source that builds pangemma's lmdb store (default `cwl/gemma/store.scm`) | +| `GEMMA_ARTIFACTS_MANIFEST` | manifest for both of those jobs (default `cwl/gemma/manifest-artifacts.scm`: bash, gawk, R/qtl2, python, numpy, lmdb) -- a different toolchain from the mapping steps, and ravanan builds one profile per workflow | +| `IMPUTE_SCRIPT` | `scripts/qtl2-impute-bimbam.R`, staged into the prepare job | Selecting slurm without an endpoint or a JWT file is a startup error (fail closed, like `GN4_DB_MODE`): ravanan would fail every step, and a @@ -45,7 +52,9 @@ Two things the cluster needs that a plain dev box may not have: - `gemma` reachable in the profile ravanan builds from `GEMMA_RAVANAN_MANIFEST` (the workflow invokes `gemma` itself, not - `gemma-wrapper` -- see `cwl/gemma/gemma-loco.scm`); ravanan resolves that + `gemma-wrapper` -- see `cwl/gemma/gemma-loco.scm`); `"engine": + "pangemma"` instead needs `pangemma` from `GEMMA_RAVANAN_MANIFEST_MDB`. + ravanan resolves that manifest against the *ambient* Guix process, so `GUIX_PACKAGE_PATH` (or a pulled `guix-bioinformatics` channel) must be set in the server's environment, as it already must for the single-machine diff --git a/docs/www/SKILL.md b/docs/www/SKILL.md index 2fa2385..0b97fec 100644 --- a/docs/www/SKILL.md +++ b/docs/www/SKILL.md @@ -78,7 +78,10 @@ Every JSON reply is `{"data","meta","notes","next"}` and sometimes `"actions"`. * `notes`: read them. They say how many strains were matched, what was run, and caveats. * `next`: GET links to related things. Each `href` already includes `/gn4`: - resolve against the origin (`https://vesuvio.pu.ac.ke$href`). + resolve against the origin (`https://vesuvio.pu.ac.ke$href`). A link that is a + *shape* rather than an address — one still holding a `{placeholder}` the scan + cannot fill, such as `{trait_id}` or a genotype file name — carries + **`"template": true`**; following the rest returns 200 as it stands. * **`actions`: ready-to-send POSTs.** On a trait's `/values` they are the R/qtl and GEMMA calls with the body already filled in; on a **compute reply** they are the matching plot call (href with `?trait=` already set; post the reply @@ -194,10 +197,37 @@ Two endpoints run the same computation, and the reply shape is identical: | endpoint | runs | |---|---| | `/compute/gemma/ravanan` | `gemma` itself, one invocation per chromosome, scattered by ravanan (Slurm) | -| `/compute/gemma` | `gemma-wrapper` (kinship, then GWA, both `--loco`) as a server subprocess, no cluster | +| `/compute/gemma` | the **same Slurm route by default** (`GEMMA_ENGINE=slurm`): ravanan, one `gemma` job per chromosome, falling back to the in-process `gemma-wrapper` only when the cluster route answers 5xx | + +**Sending the same body to `/compute/gemma` and `/compute/gemma/ravanan` no +longer compares two runners**: by default both are the Slurm route, so they +answer the same numbers through the same process. They still differ in *scope* +(covariates, normalization, permutations are refused on the ravanan endpoint), +and a reply says which engine ran in `meta.timing.engine` and whether the +cluster was used at all in `meta.timing.cluster.jobs_submitted` (`0` = every step +came from ravanan's store). The in-process `gemma-wrapper` run is reachable only +as the fallback (its reply carries an "Engine: the Slurm route was unavailable" +note). + +**A run can outlast your client, so there is an async form.** A cold fit on a +large panel is tens of minutes (measured: 21 min for 20 concurrent GWA jobs on a +133 217-marker rat panel), and a closed connection used to take the answer with +it: -**Use `/compute/gemma/ravanan` by default.** Reach for `/compute/gemma` only -when: +```sh +POST /compute/gemma/async?id=<name> # same body; 202 at once +{ "id": "<name>", "state": "running", "status": "/compute/gemma/result/<name>" } +GET /compute/gemma/result/<name> # progress, then the finished reply +``` + +The status route reports `state`, `elapsed_ms` and what the cluster is doing +(`meta.timing.cluster.jobs_submitted` — `0` means everything came from cache), +and returns exactly the body the blocking call would have. `?id=` on the +blocking endpoints still works with `/compute/gemma/status/{id}` for the run +log, but that one tails text; use `result` to collect the answer. Give a long +run an id *before* starting it, or a timeout leaves you nothing to poll. + +Reach for `/compute/gemma` when: - **Slurm is down or job submission fails** (`502`/`ravanan_failed`, or a job that never leaves `PENDING`) -- the in-process runner needs no cluster; @@ -218,7 +248,11 @@ verify costs almost nothing. **Mapping and plots (POST, verified working)** * `/compute/rqtl`: R/qtl `scanone` (Haley-Knott) over the group's genotypes. - Columns `name, chr, pos, lod`. `nperm=0` by default, so no permutation lines. + `data` is the marker rows, positional, columns `name, chr, pos, lod` (named in + `meta.columns`); the permutation null, when asked for, is **`meta.permutation`** + (`significant`, `suggestive`, `values`), not a second member of `data`. + `nperm=0` by default, so no permutation lines. Every compute endpoint keeps its + rows in `data` — one loop reads them all. * `/compute/gemma`: GEMMA LMM with leave-one-chromosome-out kinship. Columns `chr, rs, ps, n_miss, allele1, allele0, af, beta, se, l_mle, additive, p_lrt`. Pass `?id=` and poll `/compute/gemma/status/{id}` for long runs. Per-marker @@ -360,25 +394,34 @@ verify costs almost nothing. `{"basket": "<matrix>.<column>"}` on any compute endpoint. `GET /matrices` lists yours, `GET /matrices/{name}/values` reads the table back. `scripts/example-matrix.py` writes a valid example from a genotype file. +* **A file request can still be named.** `genotype_file` + `snps_file` takes + `samples` (or a `basket`) and aligns them by name onto the genotype file's + individuals — but a **BIMBAM has no names**, so for GEMMA the names come from + the `.geno` kept beside it (`genotype/<stem>.geno` next to + `genotype/bimbam/<stem>_geno.txt`), and the values are placed in the BIMBAM's + column order. With neither a `.geno` sibling nor a group, send positional + `trait_values`. The reply's `Genotype:` note says which happened. * **Uploading genotypes**: `POST /uploads/genotypes` with `{"name":"<user>-GENONAME","base_version":"BXD.4","contents":"<tsv>"}` — tab-delimited, header = individuals from column 4, then marker/chr/pos. It **updates** a population: ≤50 new individuals, at least one overlapping, ≤200 000 markers, and the values must be the same kind as the base's - (letters, whole numbers, probabilities). The reply's - Every compute endpoint takes it by name — `{"genotype_upload": "<name>"}` on - `/compute/{rqtl,gemma,qtl2,fitqtl}` — with `samples` (or a `basket`) matched - **by name**; the server writes the form each engine reads. Uploading the same - name again **replaces** it, and the digest in the reply says which version - ran. A one-chromosome upload scans flat or empty under LOCO - kinship — use `"kinship": "overall"` if that is all you have. `scripts/example-genotype-upload.py` - makes a valid one from any `.geno`. + (letters, whole numbers, probabilities); the reply reports the individuals, + markers and digest it stored. Every compute endpoint then takes it by name — + `{"genotype_upload": "<name>"}` on `/compute/{rqtl,gemma,qtl2,fitqtl}` — with + `samples` (or a `basket`) matched **by name**; the server writes the form each + engine reads. Uploading the same name again is a **`409`**, not a replacement: + `DELETE /uploads/genotypes/{name}` and post it again, and `updated_at` in the + listing is the version that ran. A one-chromosome upload scans flat or empty + under LOCO kinship — use `"kinship": "overall"` if that is all you have. + `scripts/example-genotype-upload.py` makes a valid one from any `.geno`. * **Changing values**: there is no write endpoint for traits, and there never will be — but a user's own column can be stored and mapped. `POST /baskets` with `{"name", "values":[{name,value}…]}` (values may be numbers, strings like `"NA"`, or null), `PATCH /baskets/{name}` to edit (a new revision, a new - digest), then `POST /compute/qtl2` with `"basket": "<name>"` instead of - `samples`. Baskets are private to the token's user, live in their own SQLite + digest), then map it with **`"basket": "<name>"`** in place of `samples` on any + of `/compute/rqtl`, `/compute/qtl2`, `/compute/gemma` or + `/compute/gemma/ravanan`. Baskets are private to the token's user, live in their own SQLite file, and a mapping reply records the revision and digest it used — quote them when reporting a result. Each edit is a new revision with its own timestamp (`GET /baskets/{name}/revisions`), old revisions stay readable @@ -396,8 +439,11 @@ verify costs almost nothing. `image/svg+xml` plot. Do not draw your own. * Options (all optional, add to the posted body; full list in `components.schemas.RqtlRequest` / `GemmaRequest`): - * R/qtl: `nperm` (permutations; **100 takes about 14 s** and adds - `significant`/`suggestive` thresholds that `/plot/rqtl` then draws), + * R/qtl: `nperm` (permutations; the cost is **strains x permutations**, not + markers: measured, 1,000 permutations took 22 s on 21 strains, 221 s on 93 + and 463 s on 87 — so 100 permutations is roughly 2 s at 21 strains and 20-45 s + at ~90. Adds `meta.permutation` `significant`/`suggestive`, which + `/plot/rqtl` then draws), `method` (`hk` default, `ehk`, `mr`, `em`, `imp`), `model` (`normal` default, `np`), `control` (a marker to condition on), `genotype_version`, `include_parents_f1`, `covariates`. @@ -622,7 +668,12 @@ from an older cache entry (retry and it refreshes). finds 19. The reply's `next` offers a ten-times wider window. * Public-data rule: `public > 0` and `confidentiality < 1`, or older than five years; otherwise 403, do not retry. Metadata is visible even when values are not. -* There are no write endpoints, and the search index holds public documents only. +* The published data is read-only, but there **are** write endpoints for the + caller's own material: `POST|PATCH|DELETE /baskets` (columns of values), + `POST /matrices` (correlation matrices) and `POST /uploads/genotypes` + (population genotypes). A basket name that is taken is a `409`, not a `422`; + PATCH it or pick another name. Nothing here can change a published trait. +* The search index holds public documents only. * Older docs said `POST /compute/*` is refused with 403. On this build it works. If you do get a 403 there, that is the answer: do not work around it. If the task needs private data or computation you are not granted, stop and ask a @@ -691,8 +742,9 @@ you saw at the start of the session** and compare against it later. piece of work. 3. If the revision is no longer the baseline, GeneNetwork was updated while you worked. **Suggest to the user that you reload SKILL.md from the repo** - (`docs/www/SKILL.md` in `https://git.genenetwork.org/genenetwork4`; a sparse - clone of `docs` is enough), and use that copy from then on. One line is + (`docs/www/SKILL.md` in `https://git.genenetwork.org/genenetwork4`; a shallow + clone — not `--sparse`, which this server rejects — is enough), and use that + copy from then on. One line is enough, for example: "GeneNetwork was updated since we started (<old> -> <new>); I'd reload SKILL.md from docs/www/ to pick up any changes. Shall I?" Then set the new revision as your baseline. @@ -738,11 +790,12 @@ conclusion is also in a commit message and in these docs. The docs live in the public repo and are the authoritative version: ```sh -git clone --depth 1 --sparse https://git.genenetwork.org/genenetwork4 -cd genenetwork4 && git sparse-checkout set docs +git clone --depth 1 https://git.genenetwork.org/genenetwork4 ``` -About 2.5 MB; drop `--sparse` for the whole tree. Then read: +A whole shallow clone is about 19 MB and takes under two minutes; `--sparse` +does **not** work against this server ("dumb http transport does not support +shallow capabilities"), so do not add it. Then read: | file | what it is | |---|---| diff --git a/docs/www/operator-checklist.md b/docs/www/operator-checklist.md index a6267de..77628d4 100644 --- a/docs/www/operator-checklist.md +++ b/docs/www/operator-checklist.md @@ -345,6 +345,36 @@ build problem: write the resolved pid into the pid file (and start the replacement only after `:3000` has stopped answering). `source_digest` changes on every build, so it distinguishes two builds of the same commit. +### The auth stub is not restarted with it + +`run.sh restart` replaces the two genenetwork4 instances and nothing else. +The stub on `:8081` is a separate long-running process, and while it is down +every authenticated endpoint answers + + 401 invalid_token: fetching http://127.0.0.1:8081/auth/public-jwks: + io: Connection refused (os error 111) + +That is how it was found on 2026-11-19, after a restart that looked clean -- +`/version` and `/mapping-methods` still answer without a token, so the +service looks alive. A monitor run is what names it (18 failed, all 401): + +```sh +bin/monitor-gn4 --tier all --token-file <state>/<user>.token +``` + +Start the stub again (its key is fixed, so tokens minted before the outage +stay valid -- only the JWKS was missing): + +```sh +cd <checkout> && AUTH_SERVER_URL=http://127.0.0.1:8081/ \ + nohup scripts/gn-auth-stub.py --token-file <state>/stub.token \ + >> <state>/logs/stub.log 2>&1 & +``` + +It writes the token it mints to that file and prints it; keep it under the +deployment's state directory rather than `/run`, which does not survive a +reboot. + ## Optional but worth it * Rate limit per address at the proxy: `limit_req_zone` + |
