diff options
| author | Pjotr <wrk@bosa.lan> | 2026-11-08 15:45:48 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-11-08 15:45:48 +0000 |
| commit | fc0e8fff3c1bed8d40e982a0a5e808180e772590 (patch) | |
| tree | be76e5db9c0566adc50f9d193a786601010f554d /src | |
| parent | 386aed031612abc118e3390638cb5aff144be971 (diff) | |
| download | genenetwork4-fc0e8fff3c1bed8d40e982a0a5e808180e772590.tar.gz | |
compute: refuse GEMMA permutations instead of ignoring them
`gemma-wrapper --permutate n` repeats the *whole* LOCO association scan per permutation -- it shuffles the phenotype file and starts over -- so a thousand permutations is thousands of full scans: hours to days on a real panel, against the single slot `/compute/gemma` has. That is not a test this deployment carries, and an assistant asked for significance thresholds will ask for it, so the answer has to be an explicit one. Until now the request type simply had no such field and serde ignores unknown keys, which is the worst of the three outcomes: the caller gets a 200, no thresholds, and no indication that what it asked for was dropped. `nperm`, `permutations` and `permutate` are now named fields and refused with `422 permutations_not_supported`, naming the cost, pointing at `POST /compute/rqtl` with `nperm` (the endpoint that does have the test, over the same panel and values) and at the `actions` member every successful GEMMA response already carries, pre-filled with exactly that call. Zero keeps its usual meaning -- off -- so a client sharing one body shape across the two endpoints still works. * src/routes/gemma.rs: the three fields, the refusal before anything expensive runs, and the response note now saying permutations are refused rather than merely absent. * tests/gemma.rs: `compute_gemma_refuses_permutations` pins all three spellings, the code, and that `nperm: 0` is not a request for any. It takes the compute lock: the gate answers before the handler does, so a concurrent job in the same test binary came back 409 instead. * README.md, docs/www/ai-instruction.md: what to do instead -- judge a peak against the smallest `p_lrt`, and get thresholds from R/qtl. 273 tests pass; the same four as before do not.
Diffstat (limited to 'src')
| -rw-r--r-- | src/routes/gemma.rs | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/routes/gemma.rs b/src/routes/gemma.rs index 38f0a8f..66caf57 100644 --- a/src/routes/gemma.rs +++ b/src/routes/gemma.rs @@ -78,6 +78,14 @@ pub struct GemmaRequest { /// carries `p_lrt`, not `p_wald` -- some other mapping than the /// stock 1-4 scale, not independently verified here. pub lmm: Option<u8>, + /// Refused unless 0: GEMMA permutations are not supported here (see + /// `permutations_not_supported`). Named so that asking for them is an + /// error rather than a silently ignored key. + pub nperm: Option<u32>, + /// Refused unless 0, as `nperm`. + pub permutations: Option<u32>, + /// Refused unless 0, as `nperm`. + pub permutate: Option<u32>, } /// One trait value, by individual name. @@ -141,6 +149,36 @@ pub async fn compute_gemma( } } + // Permutations are refused rather than ignored: gemma-wrapper's + // `--permutate` shuffles the phenotype file and runs the *whole* LOCO + // GWA again for each permutation, so 1000 of them is thousands of + // full scans -- hours to days on a real panel, with the single slot + // this endpoint has. R/qtl has the permutation test (nperm), on the + // same panel and the same values. + let requested_permutations = [request.nperm, request.permutations, request.permutate] + .into_iter() + .flatten() + .max() + .unwrap_or(0); + if requested_permutations > 0 { + return Err(ApiError::new( + StatusCode::UNPROCESSABLE_ENTITY, + "permutations_not_supported", + "GEMMA permutations are not supported", + format!( + "{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/rqtl \ + with \"nperm\": 100 -- R/qtl has the permutation test and reports the \ + suggestive and significant LOD thresholds; judge a GEMMA peak against the \ + smallest p_lrt it reached." + ), + "compute_gemma", + ) + .with_request_id(rid)); + } + let config = Config::load(); let mut extra_notes: Vec<String> = Vec::new(); let request_group = request.group.clone(); @@ -402,7 +440,11 @@ pub async fn compute_gemma( ); envelope = envelope.with_note( "GEMMA reports a p-value per marker, not a permutation threshold: judge a peak \ - against the smallest p_lrt it reached, not against a genome-wide threshold.", + against the smallest p_lrt it reached, not against a genome-wide threshold. \ + Permutations are deliberately not run here -- each one repeats the whole LOCO \ + scan -- so a request asking for them is refused, not silently ignored. Use \ + POST /compute/rqtl with nperm for suggestive and significant LOD thresholds on \ + the same values.", ); // The picture: post this response back (no body duplicated here // -- it is the response the caller already has). |
