about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-10 18:49:09 +0000
committerPjotr <wrk@bosa.lan>2026-11-10 18:49:09 +0000
commitfc99de3a5e8dfe2f54ac7e34e7422672baaa97bc (patch)
tree48d75b7ece7f67bbc22b623aa7e02ed6128411af /tests
parentd614b073351773fa5b698a3c8a4374191e9341b9 (diff)
downloadgenenetwork4-fc99de3a5e8dfe2f54ac7e34e7422672baaa97bc.tar.gz
api: scans point at the class counts behind their own peak
The gotcha notes in SKILL.md tell an agent to count the animals per
genotype class before believing a peak; a note in a document is only
found by whoever reads it, so the replies now say it too, at the peak
they just computed.

  * suggest::class_hint builds
    /groups/{g}/genotypes/{v}/markers/{peak}/classes?trait={trait_id} --
    a real GET with one placeholder, because a scan knows the trait's
    values, not its PublishXRef.Id.
  * /compute/{rqtl,gemma,qtl2,fitqtl} add it to `next` after the PheWAS
    link, naming the peak each reply found and the version the request
    named (a {version} placeholder when it named none).
  * The genotype subtree carries the template too: a version's detail,
    and a concrete marker's own links.
  * /compute/qtl2 gains the sentence that explains the divergence: on a
    riself (riset) panel heterozygous calls are dropped before the scan
    (R/qtl's convert2riself) and the HMM re-imputes them, while GEMMA
    keeps them at dosage 0.5, so a mostly-H marker cannot peak there and
    two engines can name different markers of one region without either
    being wrong.

tests/links.rs: a scan's reply offers the class counts at its own peak --
the link names the version and the peak marker the reply reports, and
leaves {trait_id} for the caller.
Diffstat (limited to 'tests')
-rw-r--r--tests/links.rs71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/links.rs b/tests/links.rs
index 498181a..3c2c01b 100644
--- a/tests/links.rs
+++ b/tests/links.rs
@@ -155,3 +155,74 @@ async fn a_marker_leads_to_its_tally_and_its_phewas() {
         "a marker leads to the PheWAS at it: {links:?}"
     );
 }
+
+/// A scan's reply carries the forward hint that reads the peak for what it
+/// is: how many animals sit in each genotype class there. Without it, "LOD
+/// 2.93" is the same sentence whether it rests on two animals or a hundred.
+#[tokio::test]
+async fn a_scan_points_at_the_class_counts_behind_its_peak() {
+    let Some(token) = common::auth_token().await else {
+        eprintln!("skipping a_scan_points_at_the_class_counts_behind_its_peak: no token");
+        return;
+    };
+    if !common::db_available() {
+        eprintln!("skipping a_scan_points_at_the_class_counts_behind_its_peak: no database");
+        return;
+    }
+    let response = common::get_with_token(
+        "GET /groups/BXD/traits/10001/values",
+        "/groups/BXD/traits/10001/values",
+        &token,
+    )
+    .await;
+    assert_eq!(response.status(), StatusCode::OK);
+    let bytes = response.into_body().collect().await.unwrap().to_bytes();
+    let samples: Value = common::data(&bytes);
+    let body = serde_json::json!({
+        "group": "BXD",
+        "genotype_version": "BXD.4",
+        "trait_name": "BXD::10001",
+        "samples": samples,
+    });
+    let response =
+        common::post_json_with_token("POST /compute/rqtl", "/compute/rqtl", &token, &body).await;
+    assert_eq!(response.status(), StatusCode::OK);
+    let bytes = response.into_body().collect().await.unwrap().to_bytes();
+    let envelope: Value = serde_json::from_slice(&bytes).unwrap();
+    let links: Vec<&str> = envelope["next"]
+        .as_array()
+        .unwrap()
+        .iter()
+        .map(|action| action["href"].as_str().unwrap())
+        .collect();
+    let hint = links
+        .iter()
+        .find(|href| href.contains("/classes?trait="))
+        .unwrap_or_else(|| panic!("a scan offers the class counts at its peak: {links:?}"));
+    assert!(
+        hint.starts_with("/groups/BXD/genotypes/BXD.4/markers/"),
+        "the hint names this scan's own version and marker: {hint}"
+    );
+    assert!(
+        hint.contains("{trait_id}"),
+        "the trait id is the caller's to fill in: {hint}"
+    );
+    // And the marker it names is the peak the reply reported.
+    // /compute/rqtl's rows live under data.markers.
+    let rows = envelope["data"]["markers"].as_array().unwrap();
+    let peak = rows
+        .iter()
+        .max_by(|left, right| {
+            left[3]
+                .as_f64()
+                .unwrap()
+                .partial_cmp(&right[3].as_f64().unwrap())
+                .unwrap()
+        })
+        .unwrap();
+    assert!(
+        hint.contains(peak[0].as_str().unwrap()),
+        "the hint is at the peak marker {}: {hint}",
+        peak[0]
+    );
+}