diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/routes/plot.rs | 28 | ||||
| -rw-r--r-- | src/routes/rqtl.rs | 9 |
2 files changed, 34 insertions, 3 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 diff --git a/src/routes/rqtl.rs b/src/routes/rqtl.rs index ee0b159..104c041 100644 --- a/src/routes/rqtl.rs +++ b/src/routes/rqtl.rs @@ -361,9 +361,13 @@ pub async fn compute_rqtl( .map(|output| { let notes = output.notes.clone(); let num_rows = output.markers.len(); + // What was mapped comes first: it is the one thing that tells two + // responses from the same panel apart, and `/plot/rqtl` reads it + // for the title. let mut envelope = ctx .envelope(rqtl::to_json(output)) .with_columns(rqtl::MARKER_COLUMNS.iter().map(|s| s.to_string()).collect(), num_rows) + .with_note(&format!("Trait: {}", request.trait_name)) .with_note( "markers come from R/qtl's scanone output, positional (see meta.columns for names); permutation is null unless nperm > 0 was requested.", ); @@ -423,9 +427,12 @@ pub async fn compute_rqtl( // The picture: post this response back. The body is not // duplicated here -- it is the response the caller already has. + // The trait goes in the URL as well as the response: `/plot/rqtl` + // reads it from the posted `notes` now, but a caller that posts + // only `data` still gets the right title this way. envelope = envelope.with_action(crate::response::SuggestedCall { method: "POST".to_string(), - href: "/plot/rqtl".to_string(), + href: format!("/plot/rqtl?trait={}", path_segment(&request.trait_name)), description: "Draw this scan: POST this response back to /plot/rqtl (as-is, or its \ `data` member) and get an SVG Manhattan plot of these rows, with the \ permutation thresholds as dashed lines when nperm > 0. Nothing is \ |
