about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-10-11 20:07:40 +0000
committerPjotr <wrk@bosa.lan>2026-10-11 20:07:40 +0000
commit53ae1b4cbf8bd68278e7a59cd41a4c145f8362ab (patch)
treed173a0648fa4b3726fc3b365920141103420ae0b /src
parent9e03cf40b875790c19d3fa1623297841b72b553e (diff)
downloadgenenetwork4-53ae1b4cbf8bd68278e7a59cd41a4c145f8362ab.tar.gz
gemma: default lmm to 9, matching GeneNetwork's own convention
GeneNetwork2 (wqflask/marker_regression/gemma_mapping.py) and gn-guile
(gn/runner/gemma.scm) both always use -lmm 9 in their working --loco
invocations. Checked by running it: gemma-gn2 accepts 9 fine, and the
resulting .assoc.txt carries p_lrt, not p_wald -- some mapping other
than stock GEMMA's 1-4 scale, not independently verified here, but
consistent with what both of those codebases rely on in production.

Widened validation from a 1-4 range to the explicit set {1, 2, 3, 4,
9}: 9 is now known-good, but 5-8 remain untested and stock-invalid, so
they're still rejected rather than guessed at.

Updated the real end-to-end test to assert on p_lrt (what lmm=9
actually produces) instead of p_wald, and moved the
out-of-range-lmm test from 9 (now valid) to 5.

Verified: cargo test passes in full, including the real gemma-wrapper/
GEMMA run against the BXD fixtures with the new default.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'src')
-rw-r--r--src/gemma.rs6
-rw-r--r--src/routes/gemma.rs24
2 files changed, 22 insertions, 8 deletions
diff --git a/src/gemma.rs b/src/gemma.rs
index b1f17ed..eee16b6 100644
--- a/src/gemma.rs
+++ b/src/gemma.rs
@@ -215,8 +215,10 @@ fn assoc_file_basenames(record: &Value) -> Vec<&str> {
 }
 
 /// One row of a GEMMA `.assoc.txt` file, keyed by its header column
-/// names. Columns vary with `-lmm` (1/2/3 run one test; 4 runs all
-/// three), so this stays a generic map rather than a fixed struct.
+/// names. Columns vary with `-lmm` (stock 1/2/3 run one test, 4 runs
+/// all three; this build's `9`, GeneNetwork's convention, was observed
+/// to carry `p_lrt`), so this stays a generic map rather than a fixed
+/// struct.
 pub type AssocRow = serde_json::Map<String, Value>;
 
 /// Parse a GEMMA `.assoc.txt` file (tab-separated, header row first)
diff --git a/src/routes/gemma.rs b/src/routes/gemma.rs
index 1506f1b..03b96bc 100644
--- a/src/routes/gemma.rs
+++ b/src/routes/gemma.rs
@@ -24,8 +24,15 @@ pub struct GemmaRequest {
     /// One phenotype value per strain, in the genotype file's strain
     /// order; `null` for a missing value.
     pub trait_values: Vec<Option<f64>>,
-    /// GEMMA's `-lmm` model selector: 1 = Wald, 2 = LRT, 3 = score,
-    /// 4 = all three. Defaults to 4 when omitted.
+    /// GEMMA's `-lmm` model selector: stock values are 1 = Wald,
+    /// 2 = LRT, 3 = score, 4 = all three. Defaults to 9 when omitted --
+    /// not a stock value, but the one GeneNetwork2
+    /// (wqflask/marker_regression/gemma_mapping.py) and gn-guile
+    /// (gn/runner/gemma.scm) both use, and the only value this has been
+    /// run against in the --loco shape (see `crate::gemma`). Confirmed
+    /// by actually running it: `gemma-gn2` accepts it and the output
+    /// carries `p_lrt`, not `p_wald` -- some other mapping than the
+    /// stock 1-4 scale, not independently verified here.
     pub lmm: Option<u8>,
 }
 
@@ -39,7 +46,7 @@ trait values, and returns the resulting rows of GEMMA's own \
     responses(
         (status = 200, description = "Mapped QTL rows from GEMMA's .assoc.txt output, as a JSON array of row objects", body = Envelope<serde_json::Value>),
         Unauthorized,
-        (status = 422, description = "lmm out of range (must be 1-4)", body = ApiError),
+        (status = 422, description = "lmm not one of the known-working values (1, 2, 3, 4, 9)", body = ApiError),
         (status = 502, description = "gemma-wrapper or GEMMA failed", body = ApiError)
     ))]
 pub async fn compute_gemma(
@@ -48,13 +55,18 @@ pub async fn compute_gemma(
     Json(request): Json<GemmaRequest>,
 ) -> Result<Json<Envelope<serde_json::Value>>, ApiError> {
     let rid = ctx.request_info();
-    let lmm = request.lmm.unwrap_or(4);
-    if !(1..=4).contains(&lmm) {
+    let lmm = request.lmm.unwrap_or(9);
+    // Only the values actually run against this GEMMA build (see the
+    // `lmm` field doc above) are allowed; 5-8 are stock-invalid and
+    // untested here, so they're rejected rather than guessed at.
+    if !matches!(lmm, 1 | 2 | 3 | 4 | 9) {
         return Err(ApiError::new(
             StatusCode::UNPROCESSABLE_ENTITY,
             "invalid_lmm",
             "Invalid lmm",
-            format!("lmm must be 1-4 (got {lmm}); 1=Wald, 2=LRT, 3=score, 4=all three."),
+            format!(
+                "lmm must be one of 1, 2, 3, 4, 9 (got {lmm}); 1=Wald, 2=LRT, 3=score, 4=all three, 9=GeneNetwork's convention (observed to behave like LRT)."
+            ),
             "compute_gemma",
         )
         .with_request_id(rid));