From 7852b58e211a1bb87568e6d0c3ad4a46a67b99f4 Mon Sep 17 00:00:00 2001 From: Simon Penel Date: Wed, 15 May 2024 17:01:14 +0200 Subject: [PATCH] Adding gene_colors in Options --- Cargo.toml | 2 +- examples/test_colors.rs | 45 +++++++++++++++++++++++++++++++++++++++++ src/arena.rs | 3 +++ src/drawing.rs | 10 ++++++++- 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 examples/test_colors.rs diff --git a/Cargo.toml b/Cargo.toml index 8c25d35..9c8bb06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "light_phylogeny" -version = "2.1.8" +version = "2.1.9" authors = ["Simon Penel "] edition = "2018" description ="Methods and functions for phylogeny." diff --git a/examples/test_colors.rs b/examples/test_colors.rs new file mode 100644 index 0000000..c33a1fe --- /dev/null +++ b/examples/test_colors.rs @@ -0,0 +1,45 @@ +// Display a reconciled tree form recPhyloXML format + +use light_phylogeny::{ArenaTree,Options,Config,read_recphyloxml_multi,recphyloxml_processing}; + +fn main() { + + let transfers = vec![]; + let mut options: Options = Options::new(); + let config: Config = Config::new(); + + options.free_living = true; + options.gene_internal = true; + options.species_internal = true; + + + let mut sp_tree: ArenaTree = ArenaTree::default(); + let mut gene_trees:std::vec::Vec> = Vec::new(); + let mut global_roots: std::vec::Vec = Vec::new(); + read_recphyloxml_multi("examples/free_living_reconciliated_quadruple.recphylo".to_string(), + &mut sp_tree, &mut gene_trees, &mut global_roots); + recphyloxml_processing(&mut sp_tree, &mut gene_trees, &mut options, &config, true, + &transfers, "test_colors1.svg".to_string()); + println!("Please open output file 'test_colors1.svg' with your browser"); + + + let transfers = vec![]; + let mut options: Options = Options::new(); + let config: Config = Config::new(); + + options.free_living = true; + options.gene_internal = true; + options.species_internal = true; + options.gene_colors.push("green".to_string()); + options.gene_colors.push("pink".to_string()); + options.gene_colors.push("#7A5050".to_string()); + + let mut sp_tree: ArenaTree = ArenaTree::default(); + let mut gene_trees:std::vec::Vec> = Vec::new(); + let mut global_roots: std::vec::Vec = Vec::new(); + read_recphyloxml_multi("examples/free_living_reconciliated_quadruple.recphylo".to_string(), + &mut sp_tree, &mut gene_trees, &mut global_roots); + recphyloxml_processing(&mut sp_tree, &mut gene_trees, &mut options, &config, true, + &transfers, "test_colors2.svg".to_string()); + println!("Please open output file 'test_colors2.svg' with your browser"); +} diff --git a/src/arena.rs b/src/arena.rs index 5ab85a3..2b42f43 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -436,6 +436,8 @@ pub struct Options{ /// place les duplication et les branchingout /// a mi distance de leur parent pub mid_dist: bool, + /// user-defined list of colors for genes + pub gene_colors: Vec } impl Options { pub fn new() -> Self { @@ -472,6 +474,7 @@ impl Options { trans_start:None, trans_end:None, mid_dist:false, + gene_colors: Vec::new(), } } } diff --git a/src/drawing.rs b/src/drawing.rs index abc71e1..156e8c3 100644 --- a/src/drawing.rs +++ b/src/drawing.rs @@ -536,11 +536,19 @@ pub fn draw_sptree_gntrees ( 4 => Color::Yellow, _ => Color::Monochrome, // Jamais }; - let gene_color = RandomColor::new() + let mut gene_color = RandomColor::new() .hue(base_couleur) .luminosity(Luminosity::Bright) // Optional .alpha(1.0) // Optional .to_rgb_string(); // + + + if options.gene_colors.len() > 0 { + let _idx_user_color = &idx_rcgen % options.gene_colors.len(); + println!("DEBUG {:?} {}",options.gene_colors,_idx_user_color); + gene_color = options.gene_colors[_idx_user_color].clone(); + } + // Style de la font pour le gene let added_style = " .gene_".to_owned() + &idx_rcgen.to_string() + " { font-size: " + &config.gene_police_size.to_string() + "px; fill:"