about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/routes/gemma.rs44
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).