about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-10-15 12:04:46 +0000
committerPjotr <wrk@bosa.lan>2026-10-15 12:04:46 +0000
commitacdcb3a7ddfdfadf91531599f87190c451fd8624 (patch)
treecfc9b9a381842b27ff98750ceaa93272c7a7aee0 /src
parent6de7a3440048f870463f0c4ceb6efa86dc2d57da (diff)
downloadgenenetwork4-acdcb3a7ddfdfadf91531599f87190c451fd8624.tar.gz
rqtl: return marker rows positionally, columns in meta.columns
Same space-saving shape as the gemma commit: /compute/rqtl's markers
are now positional arrays (name, chr, pos, lod, plus any 4-way-cross
extra effect columns trailing) instead of one keyed object per row,
with the fixed column names in meta.columns.

Also fixes tests/gemma.rs, which still asserted the old keyed shape
from the gemma change -- missed in that commit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'src')
-rw-r--r--src/routes/rqtl.rs11
-rw-r--r--src/rqtl.rs27
2 files changed, 32 insertions, 6 deletions
diff --git a/src/routes/rqtl.rs b/src/routes/rqtl.rs
index 4535d30..638557c 100644
--- a/src/routes/rqtl.rs
+++ b/src/routes/rqtl.rs
@@ -73,7 +73,7 @@ concurrently -- same shape as /compute/gemma.",
     params(ComputeRqtlParams),
     request_body = RqtlRequest,
     responses(
-        (status = 200, description = "Mapped QTL markers (and, if requested, permutation thresholds)", body = Envelope<serde_json::Value>),
+        (status = 200, description = "Mapped QTL markers, as positional arrays (column names in meta.columns), and, if requested, permutation thresholds", body = Envelope<serde_json::Value>),
         Unauthorized,
         (status = 409, description = "id is already in use by another run", body = ApiError),
         (status = 422, description = "id not alnum/-/_ (max 64 chars)", body = ApiError),
@@ -122,9 +122,12 @@ pub async fn compute_rqtl(
     .await
     .map(|output| {
         let notes = output.notes.clone();
-        let mut envelope = ctx.envelope(rqtl::to_json(output)).with_note(
-            "markers come from R/qtl's scanone output; permutation is null unless nperm > 0 was requested.",
-        );
+        let mut envelope = ctx
+            .envelope(rqtl::to_json(output))
+            .with_columns(rqtl::MARKER_COLUMNS.iter().map(|s| s.to_string()).collect())
+            .with_note(
+                "markers come from R/qtl's scanone output, positional (see meta.columns for names); permutation is null unless nperm > 0 was requested.",
+            );
         for note in &notes {
             envelope = envelope.with_note(note);
         }
diff --git a/src/rqtl.rs b/src/rqtl.rs
index bac386d..9814efd 100644
--- a/src/rqtl.rs
+++ b/src/rqtl.rs
@@ -354,12 +354,35 @@ pub async fn compute(
     })
 }
 
+/// `MarkerResult`'s fixed fields, in the order `to_json` lays out each
+/// marker row -- the names a caller matches `markers`' positional rows
+/// up against (a 4-way cross's `extra` effect columns, if present,
+/// trail these and aren't named here; see `MarkerResult`'s own doc
+/// comment).
+pub const MARKER_COLUMNS: [&str; 4] = ["name", "chr", "pos", "lod"];
+
 /// `RqtlOutput` as the single JSON value the route returns -- see
 /// `crate::gemma`'s own note on why `serde_json::Value`, not a `Vec`,
-/// is what utoipa needs here.
+/// is what utoipa needs here. `markers` rows are positional (see
+/// `MARKER_COLUMNS`), the same space-saving shape `crate::gemma::compute`
+/// uses for its own (much larger) marker rows.
 pub fn to_json(output: RqtlOutput) -> Value {
+    let markers: Vec<Value> = output
+        .markers
+        .into_iter()
+        .map(|m| {
+            let mut row = vec![
+                Value::String(m.name),
+                Value::String(m.chr),
+                serde_json::json!(m.pos),
+                serde_json::json!(m.lod),
+            ];
+            row.extend(m.extra.into_iter().map(Value::String));
+            Value::Array(row)
+        })
+        .collect();
     serde_json::json!({
-        "markers": output.markers,
+        "markers": markers,
         "permutation": output.permutation,
     })
 }