about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-11 13:07:03 +0000
committerPjotr <wrk@bosa.lan>2026-11-11 13:07:03 +0000
commitf4d2d719f90774e85bc47eca041bc469f0f0951d (patch)
treeb31f206be9e954cc11de6db5523438e9521e1164
parentc9db07f6d372b0b8812e5f6698257a9df94dc1ef (diff)
downloadgenenetwork4-f4d2d719f90774e85bc47eca041bc469f0f0951d.tar.gz
gemma: the permutation refusal names both routes, including running GEMMA itself
We do not run GEMMA permutations -- each repeats the whole LOCO scan and the
gate gives GEMMA one slot -- but "not supported here" is not the same as
"not available". The refusal now says both:

  1. POST /compute/bulklmm with nperm: 1000 -- an LMM whose thresholds come
     from rotations that keep the kinship (R/qtl's nperm does not, and is
     anti-conservative on a structured panel);
  2. run GEMMA's own permutation locally. The reply's notes already name the
     bimbam pair and the phenotype file, so `gemma-wrapper --permutate` or
     `gemma -lmm 9 --permutate` on those inputs reproduces exactly the null
     GEMMA would have used -- hours instead of seconds, which is the honest
     price of that particular null.

docs/bulklmm.md gains the table this belongs in: three ways to get a
threshold, ordered by how honest the null is for a structured panel
(rotation with kinship; GEMMA's own LOCO permutation run locally; R/qtl's
nperm as a sanity check only). SKILL.md says the same in two lines.

tests/gemma.rs now asserts both halves of the refusal, and the earlier
assertion on /compute/rqtl -- which stopped being true when the refusal was
rewritten -- is replaced rather than left passing by accident.
-rw-r--r--docs/bulklmm.md14
-rw-r--r--docs/www/SKILL.md5
-rw-r--r--src/routes/gemma.rs17
-rw-r--r--tests/bulklmm.rs7
-rw-r--r--tests/gemma.rs8
5 files changed, 43 insertions, 8 deletions
diff --git a/docs/bulklmm.md b/docs/bulklmm.md
index cc6bc73..8a39798 100644
--- a/docs/bulklmm.md
+++ b/docs/bulklmm.md
@@ -14,6 +14,20 @@ things that are easy to get wrong when a result is quoted.
 | `/compute/qtl2` | LMM, LOCO, HMM probabilities | LOCO | no |
 | `/compute/bulklmm` | LMM, **global** kinship | one K for the whole genome | **yes, cheaply**: rotates by K's eigen decomposition |
 
+**Three ways to get a threshold, in order of honesty for a structured panel:**
+
+| where | null | cost |
+|---|---|---|
+| `/compute/bulklmm` with `nperm` | rotations that keep the kinship | seconds |
+| GEMMA's own `--permutate`, **run locally** | GEMMA's exact LOCO null | one full LOCO scan per permutation: hours |
+| R/qtl `nperm` on the same values | phenotypes shuffled across individuals — relatedness destroyed, anti-conservative on RI lines and DO collapses | minutes |
+
+The GEMMA endpoint does not run permutations: each repeats the whole LOCO scan
+and the gate gives GEMMA one slot. Its refusal says both alternatives — and
+names the files it used (the `bimbam/` pair and the phenotype file) so a user who
+wants GEMMA's own null can reproduce it locally, which is the only way to get
+*that* null.
+
 So BulkLMM is the only engine here that can say *"this peak is genome-wide
 significant at α = 0.05"* against a null that respects relatedness. That is what
 `/compute/gemma`'s `permutations_not_supported` refusal now points at.
diff --git a/docs/www/SKILL.md b/docs/www/SKILL.md
index 33cf516..880b569 100644
--- a/docs/www/SKILL.md
+++ b/docs/www/SKILL.md
@@ -171,6 +171,11 @@ header (peak and, for GEMMA, the Bonferroni line).
   depend on relatedness, or when the panel is multiparent; it is slower than
   `/compute/rqtl` (a DO cross costs minutes of genotype probabilities, cached
   per panel). Autosomes only, and `notes` says what was left out.
+* **Need a GEMMA threshold?** This API refuses `nperm` on GEMMA (one LOCO scan
+  per permutation, one GEMMA slot). Two routes: `/compute/bulklmm` with
+  `nperm` (rotation null, seconds), or run GEMMA's own `--permutate` locally on
+  the files the reply names (exact GEMMA null, hours). R/qtl's `nperm` is a
+  sanity check only — its null ignores relatedness.
 * **Need a threshold, not just a LOD?** `POST /compute/bulklmm` (BulkLMM.jl)
   fits an LMM per marker with a global kinship matrix and permutes by rotation,
   so `"nperm": 200` is cheap and its thresholds belong to the model that made the
diff --git a/src/routes/gemma.rs b/src/routes/gemma.rs
index 79bc445..bfb483a 100644
--- a/src/routes/gemma.rs
+++ b/src/routes/gemma.rs
@@ -304,12 +304,17 @@ pub async fn compute_gemma(
                 "{requested_permutations} permutations requested, but this endpoint runs none: \
                  each one repeats the entire LOCO association scan (gemma-wrapper --permutate), \
                  so a thousand is thousands of scans and hours of the one slot GEMMA has here. \
-                 For significance thresholds, send the same trait values to POST /compute/bulklmm \
-                 with \"nperm\": 200: it fits an LMM with a global kinship matrix and permutes by \
-                 rotating the data through that matrix, so the thresholds belong to a mixed \
-                 model (R/qtl's nperm works too, but its null ignores relatedness). Judge a GEMMA \
-                 peak against whichever threshold you use, or against the smallest p_lrt it \
-                 reached -- and remember BulkLMM is global-kinship, not LOCO."
+                 Two ways to get a threshold instead: (1) send the same trait values to \
+                 POST /compute/bulklmm with \"nperm\": 1000 -- it fits an LMM and permutes by \
+                 rotating the data through the kinship decomposition, so its thresholds respect \
+                 relatedness (R/qtl's nperm does not, and is anti-conservative on a structured \
+                 panel); (2) run GEMMA's own permutation locally on the same inputs -- the files \
+                 this endpoint used are named in the reply's notes (the bimbam pair and the \
+                 phenotype file), so `gemma-wrapper --permutate` or `gemma -lmm 9 --permutate` \
+                 reproduces exactly the null GEMMA would use, at hours rather than seconds. \
+                 Judge a GEMMA peak against whichever threshold you choose, or against the \
+                 smallest p_lrt it reached -- and remember BulkLMM's kinship is a single \
+                 genome-wide matrix, not LOCO like this scan."
             ),
             "compute_gemma",
         )
diff --git a/tests/bulklmm.rs b/tests/bulklmm.rs
index 1f55147..d567e56 100644
--- a/tests/bulklmm.rs
+++ b/tests/bulklmm.rs
@@ -248,8 +248,13 @@ async fn a_scan_plots_and_gemmas_refusal_points_here() {
     let error: Value = serde_json::from_slice(&bytes).unwrap();
     assert_eq!(error["code"], "permutations_not_supported");
     assert_eq!(error["next"], "/compute/bulklmm");
+    let detail = error["detail"].as_str().unwrap();
     assert!(
-        error["detail"].as_str().unwrap().contains("/compute/bulklmm"),
+        detail.contains("/compute/bulklmm"),
         "the refusal names the engine that can: {error}"
     );
+    assert!(
+        detail.contains("run GEMMA's own permutation locally"),
+        "and that the exact GEMMA null can be had by running it locally: {detail}"
+    );
 }
diff --git a/tests/gemma.rs b/tests/gemma.rs
index a208295..b5e3a42 100644
--- a/tests/gemma.rs
+++ b/tests/gemma.rs
@@ -690,10 +690,16 @@ async fn compute_gemma_refuses_permutations() {
         assert_eq!(error["code"], "permutations_not_supported", "{error}");
         let detail = error["detail"].as_str().unwrap();
         assert!(detail.contains("100 permutations"), "{detail}");
+        // Two routes are named: the endpoint that can permute in seconds, and
+        // running GEMMA itself for its exact null.
         assert!(
-            detail.contains("/compute/rqtl") && detail.contains("nperm"),
+            detail.contains("/compute/bulklmm") && detail.contains("nperm"),
             "the error points at the endpoint that can do it: {detail}"
         );
+        assert!(
+            detail.contains("run GEMMA's own permutation locally"),
+            "and at GEMMA itself, for the null only GEMMA has: {detail}"
+        );
     }
 
     // Zero permutations is not a request for any: the field is accepted