about summary refs log tree commit diff
path: root/tests/plot.rs
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-11 13:46:24 +0000
committerPjotr <wrk@bosa.lan>2026-11-11 13:46:24 +0000
commit9cb59caa1f13ee44ed6fcf7bc6526a87311e8e9f (patch)
treec33a6fe1a61ee76dcb688abab2c19a1df6832963 /tests/plot.rs
parent25f376a8d9e7b5511e0799fd3b09898bb682a202 (diff)
downloadgenenetwork4-9cb59caa1f13ee44ed6fcf7bc6526a87311e8e9f.tar.gz
plot/gemma: draw thresholds computed elsewhere, labelled with their source
GEMMA has no permutation test here, so its plot carries a Bonferroni line.
A threshold from /compute/bulklmm belongs to a different null and must not
look like GEMMA's, so it is passed in and named:

  POST /plot/gemma?thresholds=3.50,3.65
                   &threshold_labels=bulklmm%20alpha%200.10,bulklmm%20alpha%200.05

Each is drawn dashed in the series colour with "label: value" beside the
line, with GEMMA's Bonferroni line still there, and the plotter's
x-plot-summary names the reference lines it drew. A threshold that is not
a positive number is a 422 invalid_threshold rather than a silent omission.

/compute/bulklmm's reply offers that href already, with its alpha 0.05
threshold filled in -- so "same values, two models, one picture" is one
link from the scan, and the labels keep the two nulls apart.

tests/plot.rs: the plain plot has no bulklmm line; with thresholds both
are drawn and labelled; a non-numeric threshold is refused.
Diffstat (limited to 'tests/plot.rs')
-rw-r--r--tests/plot.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/plot.rs b/tests/plot.rs
index 123784b..594fc73 100644
--- a/tests/plot.rs
+++ b/tests/plot.rs
@@ -312,3 +312,82 @@ async fn two_traits_draw_two_different_plots() {
         "every chromosome's trace differs between the two traits"
     );
 }
+
+/// GEMMA's own reference line is a Bonferroni threshold; a threshold from
+/// another engine (BulkLMM's rotations) is a different null and must be
+/// labelled as such, not drawn as if it were GEMMA's.
+#[tokio::test]
+async fn a_gemma_plot_takes_labelled_thresholds_from_another_engine() {
+    let Some(token) = common::auth_token().await else {
+        eprintln!("skipping a_gemma_plot_takes_labelled_thresholds_from_another_engine: no token");
+        return;
+    };
+    if !common::db_available() {
+        eprintln!("skipping: no database");
+        return;
+    }
+    let values = common::get_with_token(
+        "GET /groups/BXD/traits/16627/values",
+        "/groups/BXD/traits/16627/values",
+        &token,
+    )
+    .await;
+    assert_eq!(values.status(), StatusCode::OK);
+    let bytes = values.into_body().collect().await.unwrap().to_bytes();
+    let samples: Value = common::data(&bytes);
+    let mapped = common::post_json_with_token(
+        "POST /compute/gemma (for the plot)",
+        "/compute/gemma",
+        &token,
+        &serde_json::json!({
+            "group": "BXD", "genotype_version": "BXD.8", "trait_name": "BXD::16627",
+            "samples": samples,
+        }),
+    )
+    .await;
+    assert_eq!(mapped.status(), StatusCode::OK);
+    let bytes = mapped.into_body().collect().await.unwrap().to_bytes();
+    let envelope: Value = serde_json::from_slice(&bytes).unwrap();
+
+    // Without them: GEMMA's Bonferroni line only.
+    let plain = common::post_json_with_token(
+        "POST /plot/gemma",
+        "/plot/gemma",
+        &token,
+        &envelope,
+    )
+    .await;
+    assert_eq!(plain.status(), StatusCode::OK);
+    let bytes = plain.into_body().collect().await.unwrap().to_bytes();
+    let svg = String::from_utf8_lossy(&bytes).to_string();
+    assert!(svg.contains("Bonferroni"), "GEMMA's own line is there");
+    assert!(!svg.contains("bulklmm"), "and nothing claims to be BulkLMM's");
+
+    // With them: drawn and named.
+    let with = common::post_json_with_token(
+        "POST /plot/gemma?thresholds=",
+        "/plot/gemma?thresholds=3.50,3.65&threshold_labels=bulklmm%20alpha%200.10,bulklmm%20alpha%200.05",
+        &token,
+        &envelope,
+    )
+    .await;
+    assert_eq!(with.status(), StatusCode::OK);
+    let bytes = with.into_body().collect().await.unwrap().to_bytes();
+    let svg = String::from_utf8_lossy(&bytes);
+    assert!(svg.contains("bulklmm alpha 0.10: 3.50"), "labelled with its source");
+    assert!(svg.contains("bulklmm alpha 0.05: 3.65"), "and the second one");
+    assert!(svg.contains("Bonferroni"), "GEMMA's line is still drawn beside them");
+
+    // A threshold that is not a number is refused, not silently dropped.
+    let bad = common::post_json_with_token(
+        "POST /plot/gemma?thresholds=",
+        "/plot/gemma?thresholds=abc",
+        &token,
+        &envelope,
+    )
+    .await;
+    assert_eq!(bad.status(), StatusCode::UNPROCESSABLE_ENTITY);
+    let bytes = bad.into_body().collect().await.unwrap().to_bytes();
+    let error: Value = serde_json::from_slice(&bytes).unwrap();
+    assert_eq!(error["code"], "invalid_threshold");
+}