use kuva::plot::{UpSetPlot, UpSetSort};
use kuva::backend::svg::SvgBackend;
use kuva::render::render::render_multiple;
use kuva::render::layout::Layout;
use kuva::render::plots::Plot;
const OUT: &str = "docs/src/assets/upset";
fn main() {
std::fs::create_dir_all(OUT).expect("could not create docs/src/assets/upset");
basic();
precomputed();
custom();
println!("UpSet SVGs written to {OUT}/");
}
fn basic() {
let cond_a: Vec<u32> = (1..=40).collect(); let cond_b: Vec<u32> = (21..=55).collect(); let cond_c: Vec<u32> = (31..=58).collect(); let cond_d: Vec<u32> = (1u32..=10).chain(45..=60).collect();
let up = UpSetPlot::new()
.with_sets(vec![
("Condition A", cond_a),
("Condition B", cond_b),
("Condition C", cond_c),
("Condition D", cond_d),
]);
let plots = vec![Plot::UpSet(up)];
let layout = Layout::auto_from_plots(&plots)
.with_title("DEG Overlap Across Treatment Conditions");
let svg = SvgBackend.render_scene(&render_multiple(plots, layout));
std::fs::write(format!("{OUT}/basic.svg"), svg).unwrap();
}
fn precomputed() {
let intersections: Vec<(u64, usize)> = vec![
(0b001, 45), (0b010, 35), (0b100, 28), (0b011, 62), (0b101, 55), (0b110, 48), (0b111, 118), ];
let up = UpSetPlot::new()
.with_data(
["GATK", "FreeBayes", "Strelka"],
[280usize, 263, 249],
intersections,
)
.with_max_visible(5)
.without_set_sizes();
let plots = vec![Plot::UpSet(up)];
let layout = Layout::auto_from_plots(&plots)
.with_title("Variant Calls by Pipeline (top 5 intersections)");
let svg = SvgBackend.render_scene(&render_multiple(plots, layout));
std::fs::write(format!("{OUT}/precomputed.svg"), svg).unwrap();
}
fn custom() {
let cond_a: Vec<u32> = (1..=40).collect();
let cond_b: Vec<u32> = (21..=55).collect();
let cond_c: Vec<u32> = (31..=58).collect();
let cond_d: Vec<u32> = (1u32..=10).chain(45..=60).collect();
let up = UpSetPlot::new()
.with_sets(vec![
("Condition A", cond_a),
("Condition B", cond_b),
("Condition C", cond_c),
("Condition D", cond_d),
])
.with_sort(UpSetSort::ByDegree)
.with_bar_color("#1d4ed8")
.with_dot_color("#1e3a8a");
let plots = vec![Plot::UpSet(up)];
let layout = Layout::auto_from_plots(&plots)
.with_title("DEG Overlap — Sorted by Degree");
let svg = SvgBackend.render_scene(&render_multiple(plots, layout));
std::fs::write(format!("{OUT}/custom.svg"), svg).unwrap();
}