about summary refs log tree commit diff
path: root/docs
diff options
context:
space:
mode:
authorpjotr <pjotr.public01@thebird.nl>2026-11-09 12:07:23 +0000
committerpjotr <pjotr.public01@thebird.nl>2026-11-09 12:07:23 +0000
commita4ee14ca455103fcad6cebfe656c519a155e762b (patch)
tree29ebc8b0bc47f8a8e0c3b3f43b357fb1ca5c0b58 /docs
parent4528917f5c709071293e6b6670456963897a7040 (diff)
downloadgenenetwork4-a4ee14ca455103fcad6cebfe656c519a155e762b.tar.gz
Moved to SKILL file and updated
Diffstat (limited to 'docs')
-rw-r--r--docs/www/ai-instruction.md733
1 files changed, 0 insertions, 733 deletions
diff --git a/docs/www/ai-instruction.md b/docs/www/ai-instruction.md
deleted file mode 100644
index 81b17e4..0000000
--- a/docs/www/ai-instruction.md
+++ /dev/null
@@ -1,733 +0,0 @@
-# Using the GeneNetwork API from an AI assistant
-
-Read-only, public-data HTTP API. The base URL for every request is
-
-```
-https://vesuvio.pu.ac.ke/gn4
-```
-
-so `/gn4/species` below means `https://vesuvio.pu.ac.ke/gn4/species`.
-`/gn4` without the trailing slash redirects there; everything outside
-`/gn4/` is a 404 from the front end, not from the API.
-
-Machine-readable description of every endpoint: `GET /gn4/openapi.json`.
-Endpoint-by-endpoint prose: the repository's `README.md`.
-
-## Get this document, and the rest of the docs, by cloning
-
-The documentation lives in the public repository, which is small and
-worth cloning before you start — it is the authoritative version, and
-this copy may lag behind it:
-
-```sh
-git clone --depth 1 --sparse https://git.genenetwork.org/genenetwork4
-cd genenetwork4 && git sparse-checkout set docs
-ls docs docs/www
-```
-
-That is about 2.5 MB and a couple of seconds (the repository's pack is
-under 2 MB; `--sparse` just avoids writing the 17 MB source tree you do
-not need). Drop `--sparse`/`sparse-checkout` if you want the whole tree.
-Then read:
-
-| file | what it is |
-|---|---|
-| `docs/www/ai-instruction.md` | this page |
-| `docs/search-engines.md` | how `/search` works, engines, quirks |
-| `docs/nginx.md` | how the deployment is proxied (operator-level) |
-| `README.md` | every endpoint, parameter and response shape |
-| `docs/www/operator-checklist.md` | for whoever runs the deployment, not for you |
-
-**Clone; do not fetch the web UI.** `https://git.genenetwork.org/…/tree/…`
-pages sit behind a browser proof-of-work challenge (Anubis), and the
-forge's raw endpoint answers `403`, so a plain HTTP fetch of a file
-returns an HTML challenge page rather than Markdown. The git protocol
-itself passes, which is why `git clone` works. If a fetch does come back
-as HTML mentioning Anubis, stop — do not retry, and use the copy of this
-document you were given.
-
-To check you and the server are looking at the same revision, compare
-the clone's `git -C genenetwork4 log -1 --format=%h` with the `git` field
-of `GET /gn4/version`; they need not match exactly (docs can be newer
-than the running build), but a large gap means the API may not have what
-the docs describe. A `git` value ending in `-dirty` means that binary was
-built from a working tree with uncommitted changes: compare the part
-before `-dirty`, and quote `source_digest` if you need to identify the
-exact build.
-
-**A version change means refetch this document.** `/version` reports the
-build the *server* is running, and this deployment is updated in place —
-so a `git` value you have not seen before (or one that moved during your
-session) is the signal that the page you are reading may be out of date.
-When that happens, do not keep working from your copy: refresh it and
-re-read it before the next call.
-
-```sh
-git -C genenetwork4 pull --depth 1          # or re-run the clone above
-less genenetwork4/docs/www/ai-instruction.md
-```
-
-Endpoints, parameters and defaults get added between revisions (covariate
-support in `/compute/rqtl` and `/compute/gemma` arrived that way), and a
-stale copy does not announce itself: the API simply accepts a request
-without the new option, or answers with fields the old text does not
-mention. Re-reading a file is cheap; a wrong conclusion from a stale
-description is not.
-
-```
-1. You are given a token     → by the GeneNetwork team, out of band
-2. Send it on every request  → Authorization: Bearer <token>
-3. Read JSON, check meta     → {"data": ..., "meta": ..., "notes": [...], "next": [...]}
-```
-
-## 1. Get a token
-
-**A human on the GeneNetwork team has to issue it; you cannot mint one
-yourself.** It is not self-service: no sign-up, no login form, no token
-endpoint on the public host — `POST /gn4/get-test-token` is a deliberate
-`404`, and there is nothing else to authenticate against.
-
-So, before anything else, look for a token that was already given to you
-in your task context.
-
-### If you do not have one
-
-Stop and ask the user to get one for you. Say something like:
-
-> To read GeneNetwork data I need a GeneNetwork API token (a JWT) for
-> `https://vesuvio.pu.ac.ke/gn4`. Could you ask the GeneNetwork team to
-> issue one for me? It is issued by hand, not self-service. It helps
-> them to know who it is for, which species/groups/datasets you need,
-> roughly how long you need it (the default is 30 days) and what for.
-> Please pass it to me out of band — not in a public issue, a commit or
-> a shared chat.
-
-Then wait for it. Do not guess, invent, reuse a token that was not given
-to you, or try another route in: the only unauthenticated endpoints are
-`/version` and `/openapi.json`, and everything else answers `401` (no
-token) or `404` (not routed).
-
-### Using it
-
-```sh
-TOKEN=…     # the JWT you were given
-API=https://vesuvio.pu.ac.ke/gn4
-curl -s -H "Authorization: Bearer $TOKEN" "$API/groups/BXD/traits?limit=1"
-```
-
-* Send it on every request, and keep it for the whole session.
-* Never put it in a URL, a commit, a log line, or anything you show to
-  someone else. It is yours: do not hand it to other users or paste it
-  into shared state — a token identifies whoever holds it.
-* It carries no rights of its own. It gets you past the door; what you
-  may read is decided per dataset (§4), and non-public data answers
-  `403` whatever token you hold.
-
-### If it stops working
-
-A `401` means the token is missing, expired, or was issued for a
-different deployment — the `detail` distinguishes `ExpiredSignature`
-from `InvalidIssuer`. You cannot renew it, so:
-
-1. tell the user the token has expired (or is not accepted) and ask them
-   to request a fresh one from the GeneNetwork team, using the wording
-   above and quoting the `request_id` from the error body;
-2. retry **once** with the new token when it arrives;
-3. if it still fails, stop and report it — do not loop, and do not go
-   looking for another credential.
-
-## 2. Discover the API, don't guess
-
-Two routes are safe to call first and need no token:
-
-```sh
-curl -s "$API/openapi.json"   # every endpoint, parameter, schema
-curl -s "$API/version"        # build, git revision, and whether the database answers
-```
-
-`/version` is worth reading when something fails everywhere at once. It
-returns `git` (the commit the running binary was built from; a `-dirty`
-suffix means that build had uncommitted changes), `dirty`,
-`source_digest` (which identifies the build when a commit hash cannot),
-`database` (`reachable` or `unreachable`) and `date` (the *commit's* date,
-not the build time). If `git` is not the revision you started your session
-with, the server has been updated under you: refetch this document (see
-"Get this document" above) and re-read it before going on. If `database`
-is `unreachable`, every data endpoint
-will fail with `503 db_unavailable` or `500 database_error` and there is
-nothing you can do but report it — do not retry in a loop and do not
-conclude the resource does not exist.
-
-Every response is one envelope:
-
-| member | meaning |
-|---|---|
-| `data` | the payload |
-| `meta` | `state` (`complete` or `partial`), `took_ms`, `request_id`, plus `columns`/`num_rows` on tabular payloads |
-| `notes` | server-authored remarks; **read them**, they explain partial answers |
-| `next` | links to related endpoints — following them is the cheapest way to walk the data |
-| `actions` | suggested calls that are not plain GETs (e.g. `POST /compute/rqtl`), each with a body; present only where the server has something to suggest — on the per-trait values endpoints, with the values already filled in |
-
-`meta.state: partial` means the answer is usable but something is
-missing, with the reason in `notes`. Do not read `null` enrichment
-fields as "no such value in GeneNetwork"; read it as "ask again later".
-
-**How to use `next`.** Each `href` is already an absolute path
-including the mount point, e.g. `/gn4/groups/BXD/strains`. Resolve it
-against the origin, not against the URL you just fetched:
-
-```sh
-curl -s -H "Authorization: Bearer $TOKEN" "https://vesuvio.pu.ac.ke$href"
-```
-
-Joining it to the current URL's directory instead (`…/gn4/gn4/…`)
-double-prefixes it.
-
-## 3. What you can read
-
-All of these are read-only `GET`s on public data; all need the token.
-Paths are relative to `https://vesuvio.pu.ac.ke/gn4`.
-
-| endpoint | what it gives you |
-|---|---|
-| `/species`, `/species/{species}` | species records |
-| `/species/{species}/datasets` | expression datasets of a species, across its groups |
-| `/groups?species={name}`, `/groups/{group}` | populations/InbredSets (e.g. `BXD`) |
-| `/groups/{group}/strains` | samples/strains of a group |
-| `/groups/{group}/datasets` | expression datasets of a group |
-| `/groups/{group}/case-attributes` | case-attribute names and per-strain values |
-| `/groups/{group}/traits/{trait_id}/case-attributes/{attribute}` | one attribute's values, in that trait's sample order (the covariate source) |
-| `/groups/{group}/traits` | **every published (phenotype) trait of the group** — the list for bulk work |
-| `/groups/{group}/traits/{trait_id}` | one trait's metadata |
-| `/groups/{group}/traits/{trait_id}/values` | one trait's value per strain |
-| `/datasets/{dataset}`, `/datasets/{dataset}/probesets` | expression dataset and its probesets |
-| `/datasets/{dataset}/probesets/{probeset}` (+`/values`) | one expression trait, its values |
-| `/traits/{dataset}`, `/traits/{dataset}/{trait}` (+`/values`) | the same, by dataset |
-| `/publications/{pubmed_id}/traits` | traits a paper reports, across groups. `{pubmed_id}` is the **PubMed** id (`2760876`), which a trait record carries as `pubmed_id` — not the internal `publication_id` (`116`) beside it, which will 404 there |
-| `/accessions/{accession}` | resolve a GN accession (`GN600`) to its dataset |
-| `/groups/{group}/phewas` | **PheWAS**: every published trait whose QTL peak is within a window of one position (see §4b) |
-| `/groups/{group}/genotypes` (+`/{version}`, `/{version}/markers`) | which genotype files the group can be mapped with, and each one's panel, header and markers (see §4a) |
-| `/mapping-methods` | QTL methods offered |
-| `/search?q={query}` | Xapian full-text search over published phenotypes |
-
-### Case attributes
-
-Every group carries the metadata its studies recorded alongside the
-phenotypes — sex, age, tissue, batch, colony, diet — and
-`/groups/{group}/case-attributes` returns all of it:
-
-```sh
-curl -s -H "$AUTH" "$API/groups/BXD-Longevity/case-attributes"
-```
-
-```json
-{
-  "data": {
-    "names": ["Age", "B.Wt.", "Colony", "Diet…", "Sex", "Status", "Strain", "Tx"],
-    "values": [
-      {"strain": "F3092", "case_attributes": {"Sex": "F", "Age": "…", "Tx": "…"}},
-      {"strain": "F3093", "case_attributes": {"Sex": "F", …}}
-    ]
-  }
-}
-```
-
-Four things to know before using it:
-
-* **`strain` is the group's mapping unit**, not necessarily a strain
-  line: in `BXD-Longevity` these are individual animals (`F3092`…), in
-  `BXD` they are lines (`BXD1`…). Those are the same names
-  `/groups/{group}/traits/{id}/values` uses, which is what lets an
-  attribute be aligned onto a trait.
-* **The values are free text**, not numbers: `"Sex": "F"`, `"Status":
-  "Live"`, `"SeqCvge": "36+39L"`, and some are empty. Converting one into
-  something numeric (a covariate, a filter, a grouping) is your job —
-  `F → 1, M → 0`, anything unrecognised → missing.
-* **Which attributes exist is a property of the study.** `BXD` has
-  `Epoch, RRID, SeqCvge, Status` and **no Sex**; `BXD-Longevity`,
-  `BXD-NIA-AD`, `BXD-Micturition`, `BXD-MBD-UTHSC`, `BXD-UTHSC-PC`,
-  `BXD-JAX-OFS`, `BXD-Heart-Metals`, `B6D2RI` and others do have Sex.
-  Ask the endpoint rather than assuming.
-* **If the study publishes the attribute as a trait, prefer the trait** —
-  it is already numeric and keyed the same way. `BXD-Longevity` publishes
-  `Sex` as trait `10010` (`1.0`/`0.0` over the same 3281 animals), so
-  `/groups/BXD-Longevity/traits/10010/values` is the easier source than
-  parsing `"F"`/`"M"`.
-
-### Case attributes for one trait
-
-When what you want is an attribute **aligned to a trait**, ask for it
-per trait rather than sorting the whole group's attributes yourself:
-
-```sh
-curl -s -H "$AUTH" \
-  "$API/groups/BXD-Longevity/traits/10001/case-attributes/Sex"
-```
-
-`values` has one entry per sample of that trait, **in the trait's own
-order**, so it lines up with `/groups/{group}/traits/{trait_id}/values`
-without re-sorting; `value` is the text as recorded and `null` where a
-sample has none. `distinct` gives each value with its count, commonest
-first — the check that decides whether it is usable (a constant attribute
-is not), and `num_values` how many samples have one at all.
-
-A worked case: `AgeAtDeath` in `BXD-Longevity` (trait `10001`, 3281
-animals), where `.../case-attributes/Sex` returns all 3281 in the trait's
-order, `F` × 3101 and `M` × 180. That is exactly the kind of covariate a
-mapping wants — sex varies *within* the panel rather than describing the
-strain lines, and it has its own QTL here (LRS 76 at `rs13481466`), which
-is why leaving it out changes what the scan finds. (The same sex values
-are also published as trait `10010`, already numeric.)
-
-### Search
-
-`/search` is served by a **Xapian** index, queried with Xapian's own
-`QueryParser` in the same configuration GeneNetwork3 used. So the syntax
-is Xapian's, not Google's or SQL's, and a few of its behaviours will
-surprise you:
-
-* **Juxtaposed terms are OR** — `alcohol dependence` means
-  `alcohol OR dependence`, not AND. Write `AND` when you mean it: on
-  this index `alcohol` matches ~1 200 traits, `alcohol OR dependence`
-  ~1 660, `alcohol AND dependence` 45.
-* **Free text is English-stemmed and case-insensitive** — `insulin`,
-  `insulins` and `INSULIN` all match the same documents. You do not need
-  to guess singular/plural forms.
-* **Quoted phrases match nothing on this index.** `"central nervous
-  system"` returns 0 even though that text is everywhere in the
-  descriptions, because the free-text terms are indexed stemmed and
-  carry no positions in this index. `NEAR` and `ADJ` are in the same boat, and a
-  hyphenated word (`insulin-like`) is parsed as a phrase, so it matches
-  nothing either. Use `term AND term` instead of a phrase.
-* **No wildcards.** `alcohol*` behaves exactly like `alcohol`, and
-  `alco*` matches nothing — there is no prefix matching.
-* Operators are `AND`, `OR`, `NOT`, `XOR` (uppercase) and parentheses.
-  A dangling operator or an unbalanced quote is a `422 invalid_query`
-  with Xapian's own classification in `detail`; fix the query, do not
-  retry.
-
-Fields are written `field:value`:
-
-| kind | fields | behaviour |
-|---|---|---|
-| exact (boolean) | `group`, `dataset`, `species`, `author`, `tissue`, `symbol`, `chr`, `peakchr`, `position` (alias `pos`), `Hs`, `Mm` | match the stored term exactly; values are lowercased, so case does not matter (`dataset:BXDPublish` works). `Hs`/`Mm` are species-location shorthands |
-| stemmed text | `description`, `rif` (alias `RIF`), `wiki` (alias `WIKI`) | weighted, stemmed like free text |
-| numeric ranges | `mean`, `peak`, `peakmb`, `additive`, `year` | `field:lo..hi`; either end may be omitted (`mean:10..`, `mean:..15`) |
-
-A prefix whose value is not in the index simply matches nothing — it is
-not an error. `tissue:foo` returning 0 means "no such value", not "bad
-syntax". Check a hit's own fields to see the values that exist.
-
-`type` selects `phenotype` (default) or `gene`.
-
-`limit` defaults to 20 and caps at **100**; `page` pages through hits.
-There is **no total** in the response — to count, page until a short
-page, and note that each page costs time proportional to the number of
-matches remaining, so paging through ~15 000 hits takes about half a
-minute and hammers the server. For bulk work use
-`/groups/{group}/traits`, not search.
-
-## 4. What is public — and what you will not get
-
-A dataset is readable without further authorization when
-
-* `public > 0` **and** `confidentiality < 1`, **or**
-* it is older than five years (embargoes expire).
-
-That is the only rule, and it matches GeneNetwork2/3. Everything else
-answers `403 forbidden`.
-
-* Metadata (names, descriptions, dataset records, trait metadata) is
-  visible even for datasets whose **values** you may not read.
-* The search index holds public documents only, so search never reveals
-  private traits — it simply does not return them.
-* There are **no write endpoints** — nothing in the API changes data.
-* Server-side computation *is* available to any valid token, but it is
-  not about public data: see §4a.
-
-If your task needs private data or server-side computation, stop and ask
-a human: that needs an account and a grant, not a different URL.
-
-## 4a. Running QTL mapping (compute)
-
-**Never run R/qtl or GEMMA yourself.** Do not download a trait's values
-and fit a scan locally — not with R, not with a reimplementation, not
-"just to check". The API does this for you, and doing it yourself gives
-the *wrong answer*: the genome scan needs the genotype and marker files
-that match the strain panel the values came from, and those live with the
-deployment, not in what you can fetch. A local scan would use genotypes
-you do not have, a marker set you guessed, or a kinship you cannot
-compute, and would quietly disagree with GeneNetwork's own results.
-
-So: fetch the values, take the mapping call the API offers you (§ below),
-and **use its returned marker rows for downstream analysis** — fine
-mapping, candidate genes, plots, whatever the task needs. The computation
-itself, and the choice of genotypes, is the server's.
-
-`POST /gn4/compute/rqtl` (R/qtl scanone) and `POST /gn4/compute/gemma`
-(GEMMA, kinship then LOCO GWAS) run **on the server**, against files on
-the server's own filesystem. A valid token is the only requirement: they
-are not dataset-checked, so nothing about §4 applies — but the paths you
-name have to be paths the server can read, which means ones the
-deployment already holds. You cannot upload a genotype file.
-
-**Name the group, not a file.** Ask the API what a group can be mapped
-with:
-
-```sh
-curl -s -H "$AUTH" "$API/groups/BXD/genotypes"
-```
-
-That lists each `version` (e.g. `BXD.8`), its `title`, `individuals`,
-`markers`, whether `gemma` and `rqtl` can run on it, and which one is
-`current` — what a mapping gets if you name no version. Pass `group` to
-the mapping and the server resolves the files; add
-`"genotype_version": "BXD.4"` for an older panel.
-
-You do not have to map blind: `GET /groups/{group}/genotypes/{version}`
-gives that panel's file name, its header labels (`type`, `mat`, `pat`,
-…), the individuals in file order, the strains a mapping actually uses,
-and per-chromosome marker counts, and
-`GET /groups/{group}/genotypes/{version}/markers?page=&limit=&chr=` gives
-the markers themselves (name, chr, cM, Mb). That is enough to frame or
-check a mapping. The genotype calls are not served — do not look for
-them, and do not try to download a genotype matrix.
-
-The values and the genotype file have to describe the **same
-individuals, in the same order, one for one**: one entry per panel
-member, `null` where the trait has no value. Both engines match by
-position, not by name. Get that wrong and the computation is meaningless;
-GEMMA refuses outright, and R/qtl refuses a count mismatch rather than
-returning plausible-looking numbers for the wrong strains.
-
-You do not have to align anything: pass the trait's values as named
-`samples` and the server matches them onto the panel by name (names the
-panel does not have are dropped, individuals without a value get `null`).
-The response's `notes` tell you which version ran, how big the panel was
-and how many values were used — read them, they are the record of what
-happened. Like GeneNetwork2 and GeneNetwork3, a mapping uses the **RI
-strains only**: parents and F1s are excluded by default (BXD's panel is
-198 strains + 37 F1s; UM-HET3's is individual animals only), and
-`include_parents_f1: true` is the opt-in.
-
-For reference, the deployment maps BXD (34 values) in ~17 s with GEMMA
-and ~8 s with R/qtl, and UM-HET3 lifespan (6 447 individuals, 893
-markers) in ~83 s with R/qtl.
-
-A mapping's response ends with what to do next:
-
-* **`next`: a PheWAS at the peak** the run found — a `GET` that returns
-  200, so follow it (§4b). Present when the request named a `group`.
-* **`actions`: a plot of what you just got** — `POST /plot/rqtl` or
-  `/plot/gemma`, which take **the mapping response you are holding**,
-  posted back as-is (not a compute request: nothing is recomputed).
-  The reply is an **SVG document** (`image/svg+xml`), not JSON: LOD with
-  the permutation thresholds as dashed lines (R/qtl), or `-log10(p_lrt)`
-  with a Bonferroni line (GEMMA), whose one-line peak summary rides back
-  in the `x-plot-summary` header. Post the whole response for both, or
-  just its `data` member for `/plot/rqtl`; `/plot/gemma` needs
-  `meta.columns` to find the `p_lrt` column. A body that is not a
-  mapping result is a `422` saying so. The title names the trait, read
-  from the response's own `Trait: ...` note — post the whole response and
-  two traits' plots are told apart at a glance; post only `data` and add
-  `?trait=` yourself, or every one of them is titled the same.
-* **`actions`: the same scan with 100 permutations** (`nperm: 100`), when
-  you did not already ask for permutations. It is a `POST`, which is why
-  it is not a `next` link. Those 100 shuffles are what turn "this peak
-  has LOD 4.2" into "the significant threshold is 3.1" — the response's
-  `permutation` then carries `suggestive` and `significant`. It costs
-  about 100 scans, so it is the one call here worth an `?id=` and a
-  poller.
-* **a note saying what to plot**: `chr` against `lod` (R/qtl) or against
-  `-log10` of `p_lrt` (GEMMA). Rows are positional with `meta.columns`
-  naming them, so a Manhattan plot needs no reshaping.
-
-**Covariates.** Add `covariates` to fit the study's own metadata — sex,
-diet, batch — alongside the trait, in **both** `/compute/rqtl` and
-`/compute/gemma`. The easiest form names a case attribute (§3), and the
-server codes it. It is also the smallest: nothing is posted, where an
-inline covariate sends a value per individual — for a panel of thousands
-that is the difference between a few hundred bytes and a multi-megabyte
-body, and bodies are capped at 64 MiB (`413`, in plain text, if you pass
-it). Covariates need a `group` on the request: individuals are aligned by
-name, which an explicit `genotype_file` does not carry (`422`):
-
-```json
-"covariates": [{"case_attribute": "Sex"}]
-```
-
-That returns a `notes` line you must read: it says how the text was coded,
-how many levels it has and how many samples have both the trait and the
-covariate, e.g. `Covariate Sex: categorical coded F=0, M=1, 3281 of 3281
-samples have a value, 3281 with both the trait and the covariate; 2
-levels`. Missing covariate
-values drop those individuals, so *n* shrinks — compare `n` against the
-uncovaried run before reading anything into the LOD change. Use
-`{"case_attribute": "Diet", "map": {"HFD": 0, "LFD": 1}}` when the coding
-matters, or `{"name": …, "kind": "numerical", "values": […]}` when you
-already have numbers. An attribute the group does not define is a `422`
-listing the ones it has.
-
-The two engines fit the same covariates differently, which changes what
-you should expect in `notes`: R/qtl takes each categorical covariate as
-one column and dummy-expands it itself, while GEMMA gets a covariate file
-of its own with k‑1 dummy columns named after their levels
-(`Status.Live`) — GEMMA has no factors — and a column that does not vary
-among the individuals fitted is left out, with a note saying so (an
-all-zero column is singular, and GEMMA stops rather than dropping the
-term). Either way, covariates reach only the association step and not the
-kinship, so adding one does not recompute the relatedness matrix.
-
-**GEMMA has no permutation test, and do not ask for one.** A permutation
-run repeats the entire LOCO association scan for every permutation
-(`gemma-wrapper --permutate` shuffles the phenotype file and starts over),
-so a thousand permutations is thousands of full scans — hours to days on
-a real panel, on the one slot GEMMA has here. `/compute/gemma` therefore
-**refuses** `nperm`, `permutations` and `permutate` with `422
-permutations_not_supported` rather than ignoring them: an ignored flag is
-how you end up believing you have thresholds you never computed. Zero is
-accepted and means off, as elsewhere.
-
-For thresholds, use the endpoint that has the test: send the *same* panel
-and the *same* values to `POST /compute/rqtl` with `"nperm": 100`, which
-returns `suggestive` and `significant` LOD thresholds. Every successful
-GEMMA response already carries that call, pre-filled, in `actions` — take
-that rather than assembling your own. Until then, judge a GEMMA peak
-against the smallest `p_lrt` it reached, not against a genome-wide
-threshold of its own.
-
-**Large jobs are gated, small ones are not — and for GEMMA “large” starts
-at 50 individuals.** The gate is there to stop *large* computations piling
-up on the server. GEMMA runs share one cache directory (hundreds of
-megabytes of kinship archives extracted by content hash) and a real panel
-takes every core it can get, so `/compute/gemma` and
-`/compute/gemma/ravanan` gate from **50 individuals**: in practice every
-mapping request is gated, and only a handful of individuals runs free.
-`/compute/rqtl` gates later, from **1 000 individuals**, because a
-`scanone` over a few hundred is seconds of one core — so exploratory scans
-on small crosses take no slot, run alongside whatever else is running, and
-are never refused.
-
-Above the threshold, each endpoint has a fixed number of slots — **1** for
-`/compute/gemma`, **1** for `/compute/gemma/ravanan`, **8** for
-`/compute/rqtl` — and one large job per caller within them. A second large
-submission from *your* token while your job is still running or queued is
-refused at once with `409 compute_busy`, naming the run and linking its
-status endpoint; a large submission that finds every slot taken waits for
-one to come free and then runs. So a 409 here is not a retry-able failure:
-poll the status endpoint it names, and only then submit again. (If you want
-more parallelism, that is more *tokens*, not more requests from one.)
-
-Results are **cached** by input, so running the same request twice costs
-little the second time (a cached GEMMA run on the BXD fixtures comes back
-in ~2 s against ~20 s cold). That is another reason not to compute
-locally: repeat calls are cheap here.
-
-```sh
-curl -s -H "$AUTH" -H 'Content-Type: application/json' \
-  -X POST "$API/compute/rqtl" -d '{
-    "group": "BXD",
-    "trait_name": "BXDPublish::10001",
-    "samples": [{"name": "BXD1", "value": 61.4}, …]
-  }'
-```
-
-`/compute/gemma` takes `genotype_file`, `snps_file` and `trait_values`
-(one value per sample, `null` for missing), optionally `lmm`
-(default 9). `/compute/correlation` is a stub that returns canned data.
-
-**You rarely have to write these bodies by hand.** Every per-trait values
-endpoint (`/groups/{g}/traits/{id}/values`, `/datasets/{d}/probesets/
-{p}/values`, `/traits/{d}/{t}/values`) returns an `actions` member
-holding both a `POST /compute/rqtl` and a `POST /compute/gemma` call with
-the values you just fetched already in place — copy one, put in the
-genotype/SNP paths the deployment uses for that panel (ask if you do not
-have them), and send it. Do not hand-roll the values into a local R
-session instead.
-
-These are **synchronous and slow**: seconds on the fixtures, minutes on
-real data, and `/compute/gemma/ravanan` additionally waits on ravanan
-(and on a cluster when it is slurm-backed). So:
-
-* add `?id=<run-id>` to the `POST` (letters, digits, `-`, `_`, 1–64
-  characters, unique) and read progress on a second connection with
-  `GET /compute/….status/<run-id>?peek=<pointer>`; pass the `pointer`
-  back on each poll. `lines` is empty when nothing is new; unknown run
-  ids are `404`. A run whose last line is `GN4: computation complete`
-  has finished;
-* do not retry a slow `POST` — a second identical submission starts a
-  second computation (and `?id=` reuse is a `409`);
-* run one job at a time unless you know the box can take more; a GEMMA
-  run is CPU-bound and minutes long;
-* the timeout you see may be the proxy's, not the computation's: if a
-  `504` arrives, the job may still complete and still be readable
-  through its status endpoint.
-
-Responses are the usual envelope; `data` is positional with the column
-names in `meta.columns` (`chr`, `rs`, `ps`, … for GEMMA; `name`, `chr`,
-`pos`, `lod` for R/qtl), because the rows are many and repeated keys
-would dominate. `notes` carries the exact command line that ran, which
-is the fastest way to see what your request turned into.
-
-## 4b. PheWAS: what else peaks near a position
-
-A PheWAS asks the mirror question to a mapping: instead of "where does
-this trait's QTL lie?", "which other published traits peak *here*?" The
-answer comes from the peak marker each published trait already records,
-so it costs one request and no computation.
-
-### Where the position comes from
-
-Any of these gives you one:
-
-* **a mapping you just ran** — its response's `next` already points at
-  the PheWAS for the peak it found, so follow it (§4a);
-* **a trait's metadata** — `GET /groups/BXD/traits/10001` carries
-  `locus`, the marker that trait peaks at;
-* **a position you were given** — `chr` plus `mb` (megabases, the unit
-  mappings and trait records report).
-
-A marker name is finer than a position: it survives without your knowing
-the panel version's coordinates.
-
-### The call
-
-```sh
-# by marker (preferred: this is what a mapping or a trait gives you)
-curl -s -H "$AUTH" "$API/groups/BXD/phewas?locus=rs30524230&window=10000"
-
-# by position
-curl -s -H "$AUTH" "$API/groups/BXD/phewas?chr=9&mb=29.940961&window=10000"
-```
-
-| parameter | meaning |
-|---|---|
-| `locus` | marker to centre on; wins over `chr`/`mb` |
-| `chr`, `mb` | position to centre on when there is no marker name |
-| `window` | **half-width in base pairs, centred**: `10000` is 10 kb up *and* downstream (the default) |
-| `genotype_version` | whose marker table defines the window; omit for the group's current one |
-
-
-### What comes back
-
-`data` has `group`, `genotype_version`, `centre` (`locus`, `chr`, `mb`),
-`window_bp`, the `markers` the window covered (name + `mb`), and the
-`traits` peaking at one of them, strongest first. Each trait carries
-`trait_id` (usable in `/groups/{group}/traits/{trait_id}`), `dataset`,
-`abbreviation`, `description`, its peak `locus`/`chr`/`mb`, `lrs`,
-`lod`, `mean`, `additive`, `nsamples`, `pubmed_id` and a GeneNetwork
-trait `url`.
-
-### Reading it
-
-* **`traits: []` is an answer, not an error.** With markers present it
-  means nothing published peaks that close. Widen `window` — the
-  response's `next` offers a ten-times wider one. Marker spacing, not
-  the API, decides what fits: on BXD's WGS panel 10 kb usually holds a
-  handful of markers, on UM-HET3's 894-marker panel it almost always
-  holds none, so a 10 kb PheWAS there needs 100 kb or more.
-* **`markers: []`** means that genotype version has no marker at the
-  position at all — check the coordinates against
-  `/groups/{group}/genotypes/{version}/markers`.
-* **`lrs` is capped at 460** (LOD 99.91) in GeneNetwork. A tight cluster
-  at 99.91 is the ceiling, not a spectrum: order by `nsamples` or read
-  the descriptions before concluding one trait is "stronger".
-* **It is peak-based.** A trait whose QTL is broad but peaks a marker or
-  two outside the window will not appear, so absence is not evidence of
-  no shared locus — widen the window before concluding anything.
-* **Published traits only.** `PublishXRef` is the published-phenotype
-  table; expression (ProbeSet) traits are not in it.
-* **Several traits on one marker** are either the same locus measured
-  several ways or a pleiotropic effect — the `description` and
-  `pubmed_id` tell you which, and `nsamples` says whether the comparison
-  is fair.
-
-### Following up
-
-For each hit: `GET /groups/{group}/traits/{trait_id}` for its metadata,
-`…/values` for its per-strain values, or map it yourself with `group` +
-`samples` (§4a) — if it peaks your position, its genotype file and panel
-are the ones you were already using.
-
-### A real example
-
-`locus=rs30524230` (chr 9, 29.940961 Mb) with `window=10000` on BXD:
-
-```
-markers: rs37051848, rs30524230, rs29640022, rsm10000005868
-traits:  10
-  13032  ANPEP_band        LOD 99.91  nsamples 25   rs30524230   Lap-1 protein band variant
-  22744  OTU_412_HFD_log1  LOD  5.64  nsamples 29   rs37051848   microbiota OTU, high-fat diet
-  27141  Rv3421c           LOD  2.92  nsamples 21   rs37051848   M. tuberculosis antigen response
-  17858  HFD_HGB.Hemoglobin LOD 2.77  nsamples 37   rs37051848   haemoglobin at 29 weeks, HFD
-  …
-```
-
-Ten published traits peak within 10 kb of that one locus, one at the LRS
-cap and a tail of genuine others — exactly the shape to hand to a
-biologist, and exactly the kind of thing not to over-read: the first is
-capped, the rest are not, and they disagree on sample size.
-
-## 5. Errors and what to do
-
-Errors are RFC 7807-style JSON (`type`, `title`, `status`, `code`,
-`detail`, `operation_id`, `spec_url`, `request_id`, sometimes `next`).
-`type`, `spec_url` and `next` are absolute paths under `/gn4/`.
-
-| status | code (typical) | do |
-|---|---|---|
-| 401 | `invalid_token` | expired/invalid token (the `detail` distinguishes `ExpiredSignature` from `InvalidIssuer`); you cannot renew it — ask the user to request a fresh one from the GeneNetwork team (§1), then retry once |
-| 403 | `forbidden` | the data is not public: do not retry |
-| 404 | `not_found` | check the name; `next` often lists the valid values |
-| 422 | `invalid_query`, `invalid_lmm` | fix the query or parameter; do not retry |
-| 409 | `run_id_in_use`, `compute_busy` | the `?id=` you chose is taken (`run_id_in_use`: pick another), or your own compute job is still running (`compute_busy`: poll the status endpoint it links — do **not** resubmit) |
-| 413 | — (plain text, **not** JSON) | the request body is over the 64 MiB limit: send fewer values, or none at all (§4a's `case_attribute`) |
-| 429 | — | back off, honour `Retry-After` (not currently emitted, but written into the API's contract) |
-| 500 | `database_error` | if the `detail` mentions a connection (`Broken pipe`, `Connection reset`, `server has gone away`) it is transient: retry **once**, then report; otherwise treat it as a bug and report it with the `request_id` |
-| 502 / 503 | `backend_unreachable`, `db_unavailable` | transient: retry with exponential backoff, max ~5 tries |
-
-Two things about the error shape itself: a **413 comes back as plain
-text**, not the JSON error object (`Failed to buffer the request body:
-length limit exceeded`) — the body limit is enforced before any handler
-runs — and errors carry `took_ms` as well, like a success's `meta`.
-
-Quote `request_id` when reporting a problem — it is in the body, in the
-`x-request-id` header, and in the server's access log.
-
-No rate limit is configured on this deployment today. Be considerate
-anyway: a few concurrent requests, no tight polling loops, and prefer
-one bulk call to a thousand small ones.
-
-## 6. A worked example
-
-```sh
-API=https://vesuvio.pu.ac.ke/gn4
-TOKEN=…                                       # from §1
-AUTH="Authorization: Bearer $TOKEN"
-
-curl -s -H "$AUTH" "$API/groups/BXD"                      # group record
-curl -s -H "$AUTH" "$API/groups/BXD/traits" \
-  | jq '.data | length'                                   # 15060 published traits
-curl -s -H "$AUTH" "$API/groups/BXD/traits/10001"         # one trait's metadata
-curl -s -H "$AUTH" "$API/groups/BXD/traits/10001/values" \
-  | jq '.data.strains[0:3]'                               # its values
-curl -s -H "$AUTH" --get --data-urlencode 'q=cerebellum AND group:BXD' \
-  --data 'limit=5' "$API/search"
-curl -s -H "$AUTH" "$API/datasets/Br_U_0803_M/probesets/100001_at"
-curl -s -H "$AUTH" "$API/publications/2760876/traits" | jq '.data | length'
-```
-
-Watch the two id spaces: a trait record carries both `publication_id`
-(internal, e.g. `116`) and `pubmed_id` (e.g. `2760876`); only the
-PubMed one works in `/publications/{pubmed_id}/traits`.
-
-For a bulk job: fetch `/groups/{group}/traits` once (it is the whole
-`PublishXRef` list for the group — `id`, `phenotype_id`, `dataset`,
-`abbreviation`, `nsamples`), then fetch `…/traits/{id}/values` per
-trait, a few at a time.
-
----
-
-Operator-side notes (deployment, token issuance, what must not be
-routed) are in [`operator-checklist.md`](operator-checklist.md). You do
-not need them to use the API.