diff options
| author | Pjotr <wrk@bosa.lan> | 2026-11-11 13:46:24 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-11-11 13:46:24 +0000 |
| commit | 9cb59caa1f13ee44ed6fcf7bc6526a87311e8e9f (patch) | |
| tree | c33a6fe1a61ee76dcb688abab2c19a1df6832963 /src | |
| parent | 25f376a8d9e7b5511e0799fd3b09898bb682a202 (diff) | |
| download | genenetwork4-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 'src')
| -rw-r--r-- | src/routes/bulklmm.rs | 14 | ||||
| -rw-r--r-- | src/routes/plot.rs | 65 |
2 files changed, 79 insertions, 0 deletions
diff --git a/src/routes/bulklmm.rs b/src/routes/bulklmm.rs index c173d5e..ea4b805 100644 --- a/src/routes/bulklmm.rs +++ b/src/routes/bulklmm.rs @@ -631,6 +631,20 @@ pub async fn compute_bulklmm( body: None, }); } + // And, when thresholds were computed, the GEMMA plot can carry them: same + // values, two models, one picture -- labelled so the lines cannot be mixed up. + if let Some(lod) = output.thresholds.get("0.05") { + envelope = envelope.with_action(crate::response::SuggestedCall { + method: "POST".to_string(), + href: format!( + "/plot/gemma?thresholds={lod:.2}&threshold_labels=bulklmm%20alpha%200.05" + ), + description: "Or draw a GEMMA result for the same values with this threshold on it \ + (the request body is the /compute/gemma reply)" + .to_string(), + body: None, + }); + } envelope = envelope.with_action(crate::response::SuggestedCall { method: "POST".to_string(), href: "/plot/bulklmm".to_string(), diff --git a/src/routes/plot.rs b/src/routes/plot.rs index cae2463..5ce7c4f 100644 --- a/src/routes/plot.rs +++ b/src/routes/plot.rs @@ -38,6 +38,61 @@ pub struct PlotParams { pub title: Option<String>, /// GEMMA only: set to false to omit the Bonferroni reference line. pub bonferroni: Option<String>, + /// Reference lines on a GEMMA plot, in LOD / -log10 p units, comma + /// separated: the thresholds another engine computed for the same values + /// (`/compute/bulklmm` prints them in its `notes`). Drawn alongside + /// GEMMA's own Bonferroni line and labelled, so the two are never confused. + pub thresholds: Option<String>, + /// Labels for those lines, comma separated and in the same order, e.g. + /// "bulklmm alpha 0.05". Anything missing defaults to "bulklmm threshold". + pub threshold_labels: Option<String>, +} + +/// The reference lines a caller passed, validated: `(value, label)`. +fn external_thresholds( + thresholds: Option<&str>, + labels: Option<&str>, + rid: &crate::response::RequestInfo, +) -> Result<Vec<(f64, String)>, ApiError> { + let Some(thresholds) = thresholds else { return Ok(Vec::new()) }; + let values: Vec<&str> = thresholds.split(',').map(str::trim).filter(|v| !v.is_empty()).collect(); + if values.is_empty() { + return Ok(Vec::new()); + } + let labels: Vec<&str> = labels + .map(|labels| labels.split(',').map(str::trim).collect()) + .unwrap_or_default(); + let mut lines = Vec::with_capacity(values.len()); + for (index, value) in values.iter().enumerate() { + let parsed = value.parse::<f64>().map_err(|_| { + ApiError::new( + StatusCode::UNPROCESSABLE_ENTITY, + "invalid_threshold", + "Invalid threshold", + format!("'{value}' is not a number; `thresholds` takes LOD / -log10 p values"), + "plot", + ) + .with_request_id(rid.clone()) + })?; + if !parsed.is_finite() || parsed <= 0.0 { + return Err(ApiError::new( + StatusCode::UNPROCESSABLE_ENTITY, + "invalid_threshold", + "Invalid threshold", + format!("{parsed}: a reference line has to be a positive number"), + "plot", + ) + .with_request_id(rid.clone())); + } + let label = labels + .get(index) + .copied() + .filter(|label| !label.is_empty()) + .unwrap_or("bulklmm threshold") + .to_string(); + lines.push((parsed, label)); + } + Ok(lines) } /// The trait a posted compute response says it mapped: the `Trait: ...` @@ -235,6 +290,16 @@ pub async fn plot_gemma( if matches!(plot_params.bonferroni.as_deref(), Some("false") | Some("0") | Some("no")) { extra.push("--no-bonferroni".to_string()); } + // Thresholds from another engine (`/compute/bulklmm` prints them): drawn on + // GEMMA's own scale, labelled, so a reader can see which is which. + for (value, label) in external_thresholds( + plot_params.thresholds.as_deref(), + plot_params.threshold_labels.as_deref(), + &rid, + )? { + extra.push("--threshold".to_string()); + extra.push(format!("{value}:{label}")); + } let borrowed: Vec<&str> = extra.iter().map(String::as_str).collect(); let rendered = plot::render( &config.plot_python, |
