diff options
| -rw-r--r-- | src/gemma.rs | 6 | ||||
| -rw-r--r-- | src/routes/gemma.rs | 24 | ||||
| -rw-r--r-- | tests/gemma.rs | 8 |
3 files changed, 28 insertions, 10 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)); diff --git a/tests/gemma.rs b/tests/gemma.rs index 2529174..d08a088 100644 --- a/tests/gemma.rs +++ b/tests/gemma.rs @@ -66,7 +66,9 @@ async fn compute_gemma_maps_a_qtl_from_the_bxd_fixtures() { let first = &rows[0]; assert!(first.get("chr").is_some(), "{first}"); assert!(first.get("rs").is_some(), "{first}"); - assert!(first.get("p_wald").is_some(), "lmm defaults to 4 (all tests): {first}"); + // lmm defaults to 9 (GeneNetwork's convention); observed to behave + // like LRT, carrying p_lrt rather than p_wald. + assert!(first.get("p_lrt").is_some(), "{first}"); } #[tokio::test] @@ -80,7 +82,9 @@ async fn compute_gemma_rejects_an_out_of_range_lmm() { "genotype_file": test_data_path("BXD_geno.txt.gz"), "snps_file": test_data_path("BXD_snps.txt"), "trait_values": [1.0, 2.0], - "lmm": 9, + // 9 is now accepted (GeneNetwork's convention); 5-8 are stock- + // invalid and untested, so they're still rejected. + "lmm": 5, }); let response = common::post_json_with_token( "POST /compute/gemma (bad lmm)", |
