A synteny plot displays collinear blocks between sequences as horizontal bars connected by ribbon polygons. Used for genome comparisons, showing conserved regions (forward) and inversions (crossed ribbons).
Constructor
new
Create a synteny plot with default settings.
use kuva::plot::SyntenyPlot;
let synteny = SyntenyPlot::new();
Returns: SyntenyPlot
Defaults:
- Bar height: 18.0 pixels
- Block opacity: 0.65
- Shared scale: false (per-sequence scale)
- No legend
Sequence Configuration
with_sequences
Add sequences from (label, length) pairs.
pub fn with_sequences<S, L>(self, seqs: impl IntoIterator<Item = (S, L)>) -> Self
where
S: Into<String>,
L: Into<f64>,
seqs
impl IntoIterator<Item = (String, f64)>
Iterator of (sequence_label, length) pairs
Sequences are rendered top to bottom in the order provided.
Example:
let synteny = SyntenyPlot::new()
.with_sequences(vec![
("chr1", 100_000.0),
("chr2", 95_000.0),
("chr3", 85_000.0),
]);
with_sequence_colors
Override bar colors (parallel to sequences).
pub fn with_sequence_colors<C: Into<String>>(self, colors: impl IntoIterator<Item = C>) -> Self
colors
impl IntoIterator<Item = String>
CSS color strings (one per sequence)
Example:
let synteny = SyntenyPlot::new()
.with_sequences(seqs)
.with_sequence_colors(["steelblue", "firebrick", "seagreen"]);
Block Methods
with_block
Add a forward (non-inverted) collinear block.
pub fn with_block(self, seq1: usize, start1: f64, end1: f64,
seq2: usize, start2: f64, end2: f64) -> Self
Start coordinate on first sequence
End coordinate on first sequence
Start coordinate on second sequence
End coordinate on second sequence
Example:
let synteny = SyntenyPlot::new()
.with_sequences(seqs)
.with_block(0, 1000.0, 5000.0, 1, 2000.0, 6000.0); // seq0 to seq1
with_inv_block
Add an inverted (crossed) collinear block.
pub fn with_inv_block(self, seq1: usize, start1: f64, end1: f64,
seq2: usize, start2: f64, end2: f64) -> Self
Parameters are identical to with_block, but the ribbon is drawn crossed to indicate a strand inversion.
Example:
let synteny = SyntenyPlot::new()
.with_sequences(seqs)
.with_inv_block(0, 10000.0, 15000.0, 1, 20000.0, 25000.0); // inverted block
with_colored_block
Add a forward block with an explicit color.
pub fn with_colored_block<C: Into<String>>(
self, seq1: usize, start1: f64, end1: f64,
seq2: usize, start2: f64, end2: f64, color: C,
) -> Self
CSS color string for this block
Example:
let synteny = SyntenyPlot::new()
.with_sequences(seqs)
.with_colored_block(0, 1000.0, 5000.0, 1, 2000.0, 6000.0, "steelblue");
with_colored_inv_block
Add an inverted block with an explicit color.
pub fn with_colored_inv_block<C: Into<String>>(
self, seq1: usize, start1: f64, end1: f64,
seq2: usize, start2: f64, end2: f64, color: C,
) -> Self
CSS color string for this block
with_blocks
Batch-add pre-built blocks.
pub fn with_blocks(self, blocks: impl IntoIterator<Item = SyntenyBlock>) -> Self
blocks
impl IntoIterator<Item = SyntenyBlock>
Iterator of SyntenyBlock structs
Display Configuration
with_bar_height
Set the pixel height of each sequence bar.
pub fn with_bar_height(self, h: f64) -> Self
Bar height in pixels (default: 18.0)
with_opacity
Set the ribbon fill opacity.
pub fn with_opacity(self, opacity: f64) -> Self
Opacity from 0.0 to 1.0 (default: 0.65)
with_shared_scale
Opt in to a shared coordinate ruler.
pub fn with_shared_scale(self) -> Self
By default, each sequence bar fills the full width (per-sequence scale). Call this to use a shared ruler where shorter sequences draw narrower bars.
Example:
let synteny = SyntenyPlot::new()
.with_sequences(seqs)
.with_shared_scale(); // all sequences share the same coordinate ruler
Legend
with_legend
Enable a legend.
pub fn with_legend<S: Into<String>>(self, label: S) -> Self
Full Example
use kuva::plot::SyntenyPlot;
use kuva::backend::svg::SvgBackend;
use kuva::render::render::render_multiple;
use kuva::render::layout::Layout;
use kuva::render::plots::Plot;
let synteny = SyntenyPlot::new()
.with_sequences(vec![
("chr1", 100_000.0),
("chr2", 95_000.0),
("chr3", 85_000.0),
])
.with_sequence_colors(["steelblue", "firebrick", "seagreen"])
.with_block(0, 10_000.0, 30_000.0, 1, 15_000.0, 35_000.0)
.with_block(0, 50_000.0, 70_000.0, 1, 55_000.0, 75_000.0)
.with_inv_block(1, 20_000.0, 40_000.0, 2, 10_000.0, 30_000.0) // inverted
.with_opacity(0.7)
.with_legend("Collinear blocks");
let plots = vec![Plot::Synteny(synteny)];
let layout = Layout::auto_from_plots(&plots)
.with_title("Genome Synteny");
let svg = SvgBackend.render_scene(&render_multiple(plots, layout));
std::fs::write("synteny.svg", svg).unwrap();