Skip to content

Commit

Permalink
Adding gene_colors in Options
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpenel committed May 15, 2024
1 parent 1d3883c commit 7852b58
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "light_phylogeny"
version = "2.1.8"
version = "2.1.9"
authors = ["Simon Penel <simon.penel@univ-lyon1.fr>"]
edition = "2018"
description ="Methods and functions for phylogeny."
Expand Down
45 changes: 45 additions & 0 deletions examples/test_colors.rs
Original file line number Diff line number Diff line change
@@ -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<String> = ArenaTree::default();
let mut gene_trees:std::vec::Vec<ArenaTree<String>> = Vec::new();
let mut global_roots: std::vec::Vec<usize> = 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<String> = ArenaTree::default();
let mut gene_trees:std::vec::Vec<ArenaTree<String>> = Vec::new();
let mut global_roots: std::vec::Vec<usize> = 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");
}
3 changes: 3 additions & 0 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
}
impl Options {
pub fn new() -> Self {
Expand Down Expand Up @@ -472,6 +474,7 @@ impl Options {
trans_start:None,
trans_end:None,
mid_dist:false,
gene_colors: Vec::new(),
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down

0 comments on commit 7852b58

Please sign in to comment.