diff options
| author | Pjotr <wrk@bosa.lan> | 2026-11-09 14:01:00 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-11-09 14:01:00 +0000 |
| commit | a698c48ee204cd68efc479b01132ae9c037213bb (patch) | |
| tree | 9af621bc16457d1ea99ddb4ffa7a28588e5316a7 /tests | |
| parent | 195ee5d285da98bc911813d8e578f4f17e9ba7ba (diff) | |
| download | genenetwork4-a698c48ee204cd68efc479b01132ae9c037213bb.tar.gz | |
covariates: refuse a mostly-numeric attribute, and teach the skill to use them
Fitting `SeqCvge` as a covariate came back as `502 gemma_failed` with a message about LU decomposition: its values are depths (`40`, `41`) with a few two-library entries (`36+39L`), so the attribute was coded as **twenty categories** and GEMMA died on the resulting dummies. The failure named GEMMA, which is the wrong place to look. `code_case_attribute` now refuses that shape at the covariate step, naming the values and what to send instead: 422 invalid_covariate: case attribute 'SeqCvge': the attribute mixes numbers with number-like text (14 of 19 values look numeric, but e.g. '36+30L' does not), so coding it as categories would fit a quantity as a factor -- and GEMMA fails on the result. Pass an explicit `map` giving each of those a number (there are 5 such value(s): ...), or send the numbers inline. The rule is deliberately narrow: an odd level with *no* digits (`1, 2, unknown`) is still a level and still coded, so nothing that worked stops working; only dirty numbers are caught. Also, the skill's covariate coverage -- which the review above found thin: * when a covariate is worth trying (metadata that could confound: sex, age, epoch, batch, sequencing depth), and the covariate step in the session outline; * read `.data.descriptions` before choosing one -- they are the only place that says `SeqCvge` is sequencing depth and `Epoch` a family subgroup -- and the endpoint table now says so; * read the covariate line in `notes` for the coding and the complete-case n, and report that n beside any LOD/p change; plus `Cyro`/`Cryo` being two levels in BXD; * the categorical-vs-numeric rule measured rather than asserted: `RRID` refused (82 distinct), `Status`/`Epoch` accepted, and the compound-value trap written up with the `map` workaround; * GEMMA's dummy columns, the column it drops when a level has no fitted individual, and that R/qtl's note has no such line; missing values dropping individuals; the 8-covariate cap and the `group` requirement. * src/covariates.rs: the refusal, with a unit test for both sides of it; * tests/gemma.rs: `SeqCvge` is a 422 naming `map`, not a GEMMA failure; * docs/www/SKILL.md: the covariate section, the session line, and the case-attributes rows in the endpoint table. 300 tests pass; the same four as before do not.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/gemma.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/gemma.rs b/tests/gemma.rs index c1c1201..6c98a43 100644 --- a/tests/gemma.rs +++ b/tests/gemma.rs @@ -809,3 +809,50 @@ async fn compute_gemma_reports_the_effect_next_to_the_score() { "and the response says what the three columns mean: {notes:?}" ); } + +/// A mostly-numeric attribute (`SeqCvge`: depths beside two-library values +/// like `36+39L`) must be refused with a message pointing at `map`, not +/// coded as a factor and handed to GEMMA -- which used to come back as a +/// `502 gemma_failed` about LU decomposition, saying nothing about the +/// covariate. +#[tokio::test] +async fn a_mostly_numeric_covariate_is_refused_with_a_map_hint() { + let _serial = serialised(); + let Some(token) = common::auth_token().await else { + eprintln!("skipping a_mostly_numeric_covariate_is_refused_with_a_map_hint: no token (see docs/gn-auth.md)"); + return; + }; + if !common::db_available() { + eprintln!("skipping a_mostly_numeric_covariate_is_refused_with_a_map_hint: no usable database"); + return; + } + let body = serde_json::json!({ + "group": "BXD", + "genotype_version": "BXD.4", + "trait_name": "BXD::10001", + "samples": [ + {"name": "BXD1", "value": 61.4}, {"name": "BXD11", "value": 53.1}, + {"name": "BXD12", "value": 45.9}, {"name": "BXD13", "value": 49.2}, + {"name": "BXD14", "value": 45.5}, {"name": "BXD15", "value": 60.1} + ], + "covariates": [{"case_attribute": "SeqCvge"}] + }); + let response = common::post_json_with_token( + "POST /compute/gemma (SeqCvge)", + "/compute/gemma", + &token, + &body, + ) + .await; + assert_eq!( + response.status(), + StatusCode::UNPROCESSABLE_ENTITY, + "refused before GEMMA runs" + ); + let bytes = response.into_body().collect().await.unwrap().to_bytes(); + let error: Value = serde_json::from_slice(&bytes).unwrap(); + assert_eq!(error["code"], "invalid_covariate", "{error}"); + let detail = error["detail"].as_str().unwrap(); + assert!(detail.contains("mixes numbers"), "{detail}"); + assert!(detail.contains("`map`"), "it says what to send: {detail}"); +} |
