Skip to main content

VolcanoPlot

Struct VolcanoPlot 

Source
pub struct VolcanoPlot {
Show 13 fields pub points: Vec<VolcanoPoint>, pub fc_cutoff: f64, pub p_cutoff: f64, pub color_up: String, pub color_down: String, pub color_ns: String, pub point_size: f64, pub label_top: usize, pub label_style: LabelStyle, pub pvalue_floor: Option<f64>, pub legend_label: Option<String>, pub show_tooltips: bool, pub tooltip_labels: Option<Vec<String>>,
}
Expand description

Builder for a volcano plot.

A volcano plot visualises differential expression results by plotting log₂ fold change (x-axis) against −log₁₀(p-value) (y-axis). Points that pass both the fold-change cutoff and p-value threshold are colored as up-regulated (right) or down-regulated (left); all others are shown as not-significant (gray).

Dashed threshold lines are drawn automatically at ±fc_cutoff and at the y position corresponding to p_cutoff.

§Gene labels

Call with_label_top(n) to label the n most significant points. Three placement styles are available via with_label_style: LabelStyle::Nudge (default), LabelStyle::Exact, and LabelStyle::Arrow.

§Zero p-values

p-values of exactly 0.0 cannot be log-transformed. They are automatically capped at the smallest non-zero p-value in the data. Set an explicit cap with with_pvalue_floor to control the y-axis ceiling across multiple plots.

§Example

use kuva::plot::VolcanoPlot;
use kuva::backend::svg::SvgBackend;
use kuva::render::render::render_multiple;
use kuva::render::layout::Layout;
use kuva::render::plots::Plot;

let vp = VolcanoPlot::new()
    .with_points(vec![
        ("EGFR",   3.2_f64, 1e-4_f64),
        ("AKT1",   3.5,     5e-5   ),
        ("VHL",   -3.0,     5e-4   ),
        ("GAPDH",  0.3,     0.5    ),
    ])
    .with_label_top(3)
    .with_legend("DEG status");

let plots = vec![Plot::Volcano(vp)];
let layout = Layout::auto_from_plots(&plots)
    .with_title("Tumour vs. Normal")
    .with_x_label("log₂ fold change")
    .with_y_label("−log₁₀(p-value)");

let svg = SvgBackend.render_scene(&render_multiple(plots, layout));
std::fs::write("volcano.svg", svg).unwrap();

Fields§

§points: Vec<VolcanoPoint>

All data points.

§fc_cutoff: f64

|log₂FC| threshold for up/down classification (default 1.0). Dashed vertical lines are drawn at ±fc_cutoff.

§p_cutoff: f64

p-value threshold for significance (default 0.05). A dashed horizontal line is drawn at −log10(p_cutoff).

§color_up: String

Color for up-regulated points: |log2FC| ≥ fc_cutoff and p ≤ p_cutoff (default "firebrick").

§color_down: String

Color for down-regulated points: log2FC ≤ −fc_cutoff and p ≤ p_cutoff (default "steelblue").

§color_ns: String

Color for not-significant points (default "#aaaaaa").

§point_size: f64

Circle radius in pixels (default 3.0).

§label_top: usize

Number of most-significant points to label (default 0 — no labels).

§label_style: LabelStyle

Label placement style (default LabelStyle::Nudge).

§pvalue_floor: Option<f64>

Explicit p-value floor for the −log10 transform. When None, the minimum non-zero p-value in the data is used automatically.

§legend_label: Option<String>

When Some, a legend box shows Up / Down / NS entries.

§show_tooltips: bool§tooltip_labels: Option<Vec<String>>

Implementations§

Source§

impl VolcanoPlot

Source

pub fn new() -> Self

Create a volcano plot with default settings.

Defaults: fc_cutoff 1.0, p_cutoff 0.05, firebrick/steelblue/gray colors, point size 3.0, no labels, no legend.

Source

pub fn floor(&self) -> f64

Compute the p-value floor used for -log10 transformation. Uses explicit floor if set, otherwise finds minimum non-zero p-value.

Source

pub fn with_point<S, F, G>(self, name: S, log2fc: F, pvalue: G) -> Self
where S: Into<String>, F: Into<f64>, G: Into<f64>,

Add a single point by name, log₂FC, and raw p-value.

Useful when building a plot incrementally. For bulk input prefer with_points.

let vp = VolcanoPlot::new()
    .with_point("EGFR", 3.2_f64, 1e-4_f64)
    .with_point("GAPDH", 0.3, 0.5);
Source

pub fn with_points<I, S, F, G>(self, iter: I) -> Self
where I: IntoIterator<Item = (S, F, G)>, S: Into<String>, F: Into<f64>, G: Into<f64>,

Add multiple points from an iterator of (name, log2fc, pvalue) tuples.

This is the primary input method. Accepts any types that implement Into<String> / Into<f64>. Slices, Vec, or any other iterable of tuples all work.

let results = vec![
    ("EGFR",  3.2_f64, 1e-4_f64),
    ("AKT1",  3.5,     5e-5    ),
    ("VHL",  -3.0,     5e-4    ),
    ("GAPDH", 0.3,     0.5     ),
];
let vp = VolcanoPlot::new().with_points(results);
Source

pub fn with_fc_cutoff(self, cutoff: f64) -> Self

Set the absolute log₂FC threshold for up/down classification (default 1.0 — corresponding to a 2× fold change).

Dashed vertical lines are drawn at ±fc_cutoff. Points with |log2FC| < fc_cutoff are always shown as not-significant regardless of their p-value.

Source

pub fn with_p_cutoff(self, cutoff: f64) -> Self

Set the p-value significance threshold (default 0.05).

A dashed horizontal line is drawn at −log10(p_cutoff). Points with pvalue > p_cutoff are shown as not-significant regardless of their fold change.

Source

pub fn with_color_up<S: Into<String>>(self, color: S) -> Self

Set the color for up-regulated points (default "firebrick").

A point is up-regulated when log2fc ≥ fc_cutoff and pvalue ≤ p_cutoff. Accepts any CSS color string.

Source

pub fn with_color_down<S: Into<String>>(self, color: S) -> Self

Set the color for down-regulated points (default "steelblue").

A point is down-regulated when log2fc ≤ −fc_cutoff and pvalue ≤ p_cutoff. Accepts any CSS color string.

Source

pub fn with_color_ns<S: Into<String>>(self, color: S) -> Self

Set the color for not-significant points (default "#aaaaaa").

All points that do not meet both the fold-change and p-value thresholds are drawn in this color. Accepts any CSS color string.

Source

pub fn with_point_size(self, size: f64) -> Self

Set the circle radius in pixels (default 3.0).

Source

pub fn with_label_top(self, n: usize) -> Self

Label the n most significant points (lowest p-values) with their names.

When n = 0 (default) no labels are drawn. Use with_label_style to control placement.

let vp = VolcanoPlot::new()
    .with_points(vec![("EGFR", 3.2_f64, 1e-4_f64)])
    .with_label_top(10);  // label the 10 most significant genes
Source

pub fn with_label_style(self, style: LabelStyle) -> Self

Set the label placement style (default LabelStyle::Nudge).

  • LabelStyle::Nudge — labels are sorted by x and nudged vertically to reduce overlap. Best default for most datasets.
  • LabelStyle::Exact — labels are placed at the exact point position with no adjustment. May overlap on dense plots.
  • LabelStyle::Arrow — labels are offset by (offset_x, offset_y) px with a gray leader line back to the point.
use kuva::plot::{VolcanoPlot, LabelStyle};
let vp = VolcanoPlot::new()
    .with_points(vec![("EGFR", 3.2_f64, 1e-4_f64)])
    .with_label_top(10)
    .with_label_style(LabelStyle::Arrow { offset_x: 14.0, offset_y: 16.0 });
Source

pub fn with_pvalue_floor(self, floor: f64) -> Self

Set an explicit p-value floor for the −log10 transform.

Points with pvalue == 0.0 are clamped to this value before transformation, preventing infinite y positions. Also sets the y-axis ceiling to −log10(floor).

When not set, the floor is inferred as the minimum non-zero p-value in the data. Set it explicitly when comparing multiple plots that should share the same y-axis scale.

let vp = VolcanoPlot::new()
    .with_points(vec![("EGFR", 3.2_f64, 0.0_f64)])  // p = 0 is valid input
    .with_pvalue_floor(1e-10);  // y-axis ceiling = 10
Source

pub fn with_legend<S: Into<String>>(self, label: S) -> Self

Enable a legend showing Up, Down, and NS entries.

The legend uses the active up/down/NS colors. The string argument is not currently used as a title but must be set to enable the legend.

let vp = VolcanoPlot::new()
    .with_points(vec![("EGFR", 3.2_f64, 1e-4_f64)])
    .with_legend("DEG status");
Source

pub fn with_tooltips(self) -> Self

Source

pub fn with_tooltip_labels( self, labels: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Trait Implementations§

Source§

impl Default for VolcanoPlot

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<VolcanoPlot> for Plot

Source§

fn from(p: VolcanoPlot) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.