about summary refs log tree commit diff
path: root/README.md
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-08 15:39:12 +0000
committerPjotr <wrk@bosa.lan>2026-11-08 15:39:12 +0000
commit336f18e1bc22cb330052dc1ff45d1d06073bfcc3 (patch)
tree4c029b46500edab067b35424b9e9ebbc7156221a /README.md
parentfb41143226f7e0231f863a8226ba077c7415b71f (diff)
downloadgenenetwork4-336f18e1bc22cb330052dc1ff45d1d06073bfcc3.tar.gz
compute: fit covariates in GEMMA, and share them with R/qtl
`POST /compute/gemma` now takes the same `covariates` list `/compute/rqtl`
does -- `{"case_attribute": "Status"}`, an explicit `map`, or per-sample
numbers -- and fits it with `-c` on the association step only. That needed
a covariate file of GEMMA's own, which is not R/qtl's: no header, no sample
names, positional over the genotype panel, numbers only. GEMMA has no
factors, so a categorical covariate is dummy-expanded here into k-1
columns named after their levels (`Status.Live`, the first level being the
reference), where R/qtl's wrapper does that expansion for itself.

The spec shape, the alignment onto the panel and the text coding are now
one module, `src/covariates.rs`, called by both routes; `/compute/rqtl`
behaves as before except that its note also reports the complete cases
(`... 34 with both the trait and the covariate`), which README and the
instructions had been promising all along.

A missing covariate value is written `NA`, which GEMMA treats exactly as
it treats a missing phenotype -- that individual leaves the fit (measured:
one fewer "number of analyzed individuals"). Deliberately not GeneNetwork2's
`-9`, which GEMMA fits as the value minus nine.

Found on live data, not in the fixtures: a level that exists in the panel
but that none of the *fitted* individuals carries becomes an all-zero dummy
column, and GEMMA stops with `LUDecomp ... input domain error` rather than
dropping the term the way R would. Columns that do not vary among the
individuals with both a trait and a covariate are now left out, and the
response names them (`Status.Cyro`, the `Cyro`/`Cryo` typo in BXD); a
covariate left with no columns runs without one, with a note saying so.

Covariates reach only the GWA step, never `-gk`, and gemma-wrapper hashes
its file arguments, so a different covariate set is a different cache entry
while the kinship already computed is still reused. Covariates need a
`group`: individuals are aligned by name, which an explicit
`genotype_file`/`snps_file` request does not carry (`422
covariate_unavailable`), and an attribute the group does not define lists
the ones it has.

* src/covariates.rs (new): `Spec`/`NamedValue` (the request shape, now
  `CovariateSpec`/`CovariateValue` in the OpenAPI document), `Level`,
  `Covariate`, `code_case_attribute`, `resolve`, `write_covarstruct_file`
  (moved out of src/rqtl.rs) and `write_gemma_covariates_file`.
* src/gemma.rs (gwa_args, compute, compute_gwa): the optional covariate
  file, `-c` after `-a` and before `-lmm`, and the notes about dropped
  individuals and dropped columns.
* src/routes/gemma.rs: the `covariates` field, resolved after the trait
  values so the note can count complete cases; `RqtlCovariate` replaced by
  the shared spec.
* tests: six new -- the GEMMA file (numerical with `NA`; two and three
  levels; inline codes; a dropped degenerate column) and an end-to-end
  `compute_gemma_fits_a_case_attribute_as_a_covariate` on BXD/BXD.4 with
  `Status`, which also pins that `-c` is in the GWA command and not in the
  kinship one, and that the covariate changes the fit rather than reusing
  the plain run's cache. The gemma tests now take a lock: the gate answers
  a second job from the same caller with 409 instead of queueing it.
* README.md (/compute/gemma covariates rewritten for GEMMA, /compute/rqtl
  points at the shared shape and explains `x` vs `NA`), docs/www/
  ai-instruction.md (both endpoints; what differs in `notes`).

Also in the instructions: `/version` reporting a `git` value you have not
seen before now says explicitly to pull the repository and re-read
`docs/www/ai-instruction.md` before the next call. This deployment is
updated in place and a stale page does not announce itself -- the API
accepts the request without the new option, or answers with fields the old
text never mentions.

272 tests pass; the four that do not (benchmark, no_db, and two search
parity/proxy replays) fail identically at the parent commit.
Diffstat (limited to 'README.md')
-rw-r--r--README.md54
1 files changed, 40 insertions, 14 deletions
diff --git a/README.md b/README.md
index 2444a5d..af41b51 100644
--- a/README.md
+++ b/README.md
@@ -992,10 +992,10 @@ genotype file, a SNP annotation file and a list of trait values. See
 real against the BXD fixtures -- GeneNetwork3's always errors out;
 GeneNetwork2's non-LOCO branch does too; only `--loco` works).
 
-**Covariates.** `covariates` fits one or more covariates (`--addcovar`
-and a generated `--covarstruct` file), each either a **case attribute of
-the group** by name, which the server reads, aligns onto the panel and
-codes, or explicit per-sample numbers:
+**Covariates.** `covariates` fits one or more covariates alongside the
+trait -- the same request shape `/compute/rqtl` takes (below), each
+either a **case attribute of the group** by name, which the server reads,
+aligns onto the panel and codes, or explicit per-sample numbers:
 
 ```json
 "covariates": [
@@ -1006,15 +1006,31 @@ codes, or explicit per-sample numbers:
 ]
 ```
 
-Text with 2–20 distinct values is coded 0..k‑1 in sorted order and passed
-as `categorical` (the wrapper dummy-expands more than two levels); numeric
+GEMMA wants numbers, positional over the genotype panel, in a file of its
+own (`-c`), so `src/covariates.rs` writes one: one row per individual,
+no header, no sample names, and a categorical covariate **dummy-expanded**
+into k‑1 columns named after their levels (`Sex.M`) -- GEMMA knows nothing
+about factors, unlike R/qtl's wrapper, which does that expansion itself.
+The first level is the reference. A level none of the fitted individuals
+carries is left out (an all-zero column is singular and GEMMA stops with
+`LUDecomp` rather than dropping the term the way R would), and the
+response says so in `notes`.
+
+Text with 2–20 distinct values is coded 0..k‑1 in sorted order; numeric
 text is passed through as `numerical`; more than 20 levels, one level, or
-an explicit `map` that misses a value is a `422` asking for a `map`.
-An unknown attribute is a `422` listing the group's own. Missing values
-become `NA`, so R/qtl drops those individuals -- both the coding and how
-many samples have both the trait and the covariate are reported in
-`notes`, 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`.
+an explicit `map` that misses a value is a `422` asking for a `map`. An
+unknown attribute is a `422` listing the group's own. A missing value is
+written `NA`, which GEMMA treats as it does a missing phenotype -- it
+drops that individual (measured; GeneNetwork2 instead writes `-9`, which
+GEMMA fits as a value). Both the coding, how many individuals have a
+value, and any column left out are reported in `notes`.
+
+Covariates reach **only the association step**, never the K-matrix step,
+and `gemma-wrapper` hashes its file arguments, so a different covariate
+set is a different cache entry while the kinship it was computed against
+still is not recomputed. Covariates need a `group`: individuals are
+aligned by name, which an explicit `genotype_file`/`snps_file` request
+does not carry (`422 covariate_unavailable`).
 
 **Concurrency.** `/compute/rqtl` runs up to `RQTL_MAX_CONCURRENT` scans
 at once (default 8), **one per caller**: a second submission from the same
@@ -1288,14 +1304,24 @@ plus permutation thresholds if `nperm > 0`. Same request/response shape
 as `/compute/gemma` -- synchronous, `?id=`/`GET .../status/{run_id}`
 progress-streaming reusing the same infrastructure (`src/streaming.rs`)
 -- see `src/rqtl.rs` for the invocation itself, its documented scope
-(no covariates, interval mapping or pair-scan `scantwo` -- just the
-common single-scan case), and a fix made relative to GeneNetwork3:
+(no interval mapping or pair-scan `scantwo` -- just the common
+single-scan case), and a fix made relative to GeneNetwork3:
 its own cache-key hashing of the genotype/phenotype files never
 actually looks at their contents (a key-name mismatch between
 `generate_rqtl_cmd` and its real caller), so two different phenotypes
 mapped with the same other options could silently reuse each other's
 cached result there; fixed here by always hashing both files' contents.
 
+**Covariates.** The same `covariates` list as `/compute/gemma` (above)
+-- case attributes by name, or per-sample values -- fitted here with
+`--addcovar` and a generated `--covarstruct` file. R/qtl's wrapper takes
+categorical covariates as a single column and dummy-expands more than two
+levels itself, so a level with no observations is its problem, not a
+singular column: no columns are dropped on this path. A missing value is
+`x` (the marker the wrapper calls missing), so R/qtl drops those
+individuals; the coding and the count of complete cases come back in
+`notes`.
+
 **Give it a group, not a path.** `group` (an InbredSet name) plus an
 optional `genotype_version` resolves the `.geno` server-side; see
 `GET /groups/{group}/genotypes`. `samples` are then matched onto the