about summary refs log tree commit diff
path: root/src/routes/plot.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/plot.rs')
-rw-r--r--src/routes/plot.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/routes/plot.rs b/src/routes/plot.rs
index bd4a68b..00119dc 100644
--- a/src/routes/plot.rs
+++ b/src/routes/plot.rs
@@ -40,6 +40,20 @@ pub struct PlotParams {
     pub bonferroni: Option<String>,
 }
 
+/// The trait a posted compute response says it mapped: the `Trait: ...`
+/// note `/compute/rqtl` writes. It is what makes two plots of two traits
+/// distinguishable at a glance -- the *data* differs, but without this the
+/// title of every one of them said "trait rqtl".
+fn trait_from_document(posted: &serde_json::Value) -> Option<String> {
+    posted["notes"]
+        .as_array()?
+        .iter()
+        .filter_map(|note| note.as_str())
+        .find_map(|note| note.strip_prefix("Trait: "))
+        .map(|trait_name| trait_name.trim().to_string())
+        .filter(|trait_name| !trait_name.is_empty())
+}
+
 /// What `/plot/gemma` validates in a posted GEMMA result: GEMMA's own
 /// `.assoc` rows are positional, 11 columns wide, with `rs` second and
 /// `p_lrt` last.
@@ -155,7 +169,12 @@ pub async fn plot_rqtl(
         &config.rqtl_plotter,
         std::path::Path::new(&config.rqtl_cache_dir),
         &document,
-        plot_params.trait_label.as_deref().unwrap_or("rqtl"),
+        plot_params
+            .trait_label
+            .clone()
+            .or_else(|| trait_from_document(&document))
+            .as_deref()
+            .unwrap_or("rqtl"),
         &borrowed,
     )
     .await
@@ -222,7 +241,12 @@ pub async fn plot_gemma(
         &config.gemma_plotter,
         std::path::Path::new(&config.gemma_cache_dir),
         &document,
-        plot_params.trait_label.as_deref().unwrap_or("gemma"),
+        plot_params
+            .trait_label
+            .clone()
+            .or_else(|| trait_from_document(&document))
+            .as_deref()
+            .unwrap_or("gemma"),
         &borrowed,
     )
     .await