#[derive(Debug, Clone, PartialEq)]
pub enum Strand {
Forward,
Reverse,
}
#[derive(Debug, Clone)]
pub struct SyntenySequence {
pub label: String,
pub length: f64,
pub color: Option<String>,
}
#[derive(Debug, Clone)]
pub struct SyntenyBlock {
pub seq1: usize,
pub start1: f64,
pub end1: f64,
pub seq2: usize,
pub start2: f64,
pub end2: f64,
pub strand: Strand,
pub color: Option<String>,
}
#[derive(Debug, Clone)]
pub struct SyntenyPlot {
pub sequences: Vec<SyntenySequence>,
pub blocks: Vec<SyntenyBlock>,
pub bar_height: f64,
pub block_opacity: f64,
pub shared_scale: bool,
pub legend_label: Option<String>,
}
impl Default for SyntenyPlot {
fn default() -> Self { Self::new() }
}
impl SyntenyPlot {
pub fn new() -> Self {
Self {
sequences: vec![],
blocks: vec![],
bar_height: 18.0,
block_opacity: 0.65,
shared_scale: false,
legend_label: None,
}
}
pub fn with_sequences<S, L>(mut self, seqs: impl IntoIterator<Item = (S, L)>) -> Self
where
S: Into<String>,
L: Into<f64>,
{
for (label, length) in seqs {
self.sequences.push(SyntenySequence {
label: label.into(),
length: length.into(),
color: None,
});
}
self
}
pub fn with_sequence_colors<C: Into<String>>(mut self, colors: impl IntoIterator<Item = C>) -> Self {
for (seq, color) in self.sequences.iter_mut().zip(colors) {
seq.color = Some(color.into());
}
self
}
pub fn with_block(mut self, seq1: usize, start1: f64, end1: f64,
seq2: usize, start2: f64, end2: f64) -> Self {
self.blocks.push(SyntenyBlock { seq1, start1, end1, seq2, start2, end2,
strand: Strand::Forward, color: None });
self
}
pub fn with_inv_block(mut self, seq1: usize, start1: f64, end1: f64,
seq2: usize, start2: f64, end2: f64) -> Self {
self.blocks.push(SyntenyBlock { seq1, start1, end1, seq2, start2, end2,
strand: Strand::Reverse, color: None });
self
}
#[allow(clippy::too_many_arguments)]
pub fn with_colored_block<C: Into<String>>(
mut self, seq1: usize, start1: f64, end1: f64,
seq2: usize, start2: f64, end2: f64, color: C,
) -> Self {
self.blocks.push(SyntenyBlock { seq1, start1, end1, seq2, start2, end2,
strand: Strand::Forward, color: Some(color.into()) });
self
}
#[allow(clippy::too_many_arguments)]
pub fn with_colored_inv_block<C: Into<String>>(
mut self, seq1: usize, start1: f64, end1: f64,
seq2: usize, start2: f64, end2: f64, color: C,
) -> Self {
self.blocks.push(SyntenyBlock { seq1, start1, end1, seq2, start2, end2,
strand: Strand::Reverse, color: Some(color.into()) });
self
}
pub fn with_blocks(mut self, blocks: impl IntoIterator<Item = SyntenyBlock>) -> Self {
self.blocks.extend(blocks);
self
}
pub fn with_bar_height(mut self, h: f64) -> Self {
self.bar_height = h;
self
}
pub fn with_opacity(mut self, opacity: f64) -> Self {
self.block_opacity = opacity;
self
}
pub fn with_shared_scale(mut self) -> Self {
self.shared_scale = true;
self
}
pub fn with_legend<S: Into<String>>(mut self, label: S) -> Self {
self.legend_label = Some(label.into());
self
}
}