Function light_phylogeny::lca
source · pub fn lca(tree: &mut ArenaTree<String>, index1: usize, index2: usize) -> usize
Expand description
Send the index of the last common ancestor of 2 nodes.
Examples found in repository?
examples/lca_2.rs (line 19)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
let mut options: Options = Options::new();
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/gene_parasite_page4.recphylo".to_string(),
&mut sp_tree, &mut gene_trees, &mut global_roots);
options.verbose = true;
env::set_var("RUST_LOG", "info");
env_logger::init();
let j = sp_tree.get_index("big_host0".to_string()).expect("Error : unable to find big_host0");
println!("Index of leaf big_host0 is {}",j);
let l = sp_tree.get_index("p4d".to_string()).expect("Error : unable to find p4d");
println!("Index of leaf p4d is {}",l);
let lca_jl = lca(&mut sp_tree,j,l);
println!("Index of lca is {} ({})",lca_jl,sp_tree.arena[lca_jl].name);
assert_eq!(sp_tree.arena[lca_jl].name,"big_host0".to_string());
}
More examples
examples/lca.rs (line 20)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
fn main() {
let mut tree: ArenaTree<String> = ArenaTree::default();
let mut options: Options = Options::new();
let config: Config = Config::new();
println!("Reading newick file examples/newick.A4.txt...");
let contents = fs::read_to_string("examples/newick.A4.txt")
.expect("Something went wrong reading the newick file");
println!("Create a first node which will be the root...");
let root = tree.new_node("Root".to_string());
println!("Build the tree from the file contents...");
newick2tree(contents, &mut tree, root, &mut 0);
let j = tree.get_index("J".to_string()).expect("Error : unable to find J");
println!("Index of leaf J is {}",j);
let l = tree.get_index("L".to_string()).expect("Error : unable to find L");
println!("Index of leaf L is {}",l);
let n = tree.get_index("N".to_string()).expect("Error : unable to find N");
println!("Index of leaf N is {}",n);
let lca_jl = lca(&mut tree,j,l);
println!("Index of lca betwen J and L is {}",lca_jl);
tree.arena[lca_jl].name = "LCA of J and L".to_string();
let lca_jn = lca(&mut tree,j,n);
println!("Index of lca betwen J and N is {}",lca_jn);
tree.arena[lca_jn].name = "LCA of J and N".to_string();
// Display internal nodes
options.gene_internal = true ;
phyloxml_processing(&mut tree, &options, &config,"lca.svg".to_string());
println!("Please open output file 'lca.svg' with your browser");
println!("OK.");
}