modify_tree/
modify_tree.rs1use light_phylogeny::{
2 add_child, move_child, phyloxml_processing, reset_pos, summary, ArenaTree, Config, Event,
3 Options,
4};
5fn main() {
6 let mut tree: ArenaTree<String> = ArenaTree::default();
7 let mut options: Options = Options::new();
8 let config: Config = Config::new();
9
10 let root = tree.new_node("root".to_string());
12 let a1 = tree.new_node("a1".to_string());
14 let a2 = tree.new_node("a2".to_string());
15 let a = tree.new_node("a".to_string());
16 let b1 = tree.new_node("b1".to_string());
17 let b2 = tree.new_node("b2".to_string());
18 let b = tree.new_node("b".to_string());
19 let c = tree.new_node("c".to_string());
20 let d = tree.new_node("d".to_string());
21 println!("Initial tree :");
22 summary(&mut tree);
23
24 tree.arena[root].name = "MyRoot".to_string();
26 tree.arena[a].name = "Gene A".to_string();
27 tree.arena[a1].name = "Gene A1".to_string();
28 tree.arena[a2].name = "Gene A2".to_string();
29 tree.arena[b].name = "Gene B".to_string();
30 tree.arena[b1].name = "Gene B1".to_string();
31 tree.arena[b2].name = "Gene B2".to_string();
32 tree.arena[c].name = "Gene C".to_string();
33 tree.arena[d].name = "Gene D".to_string();
34 println!("");
35 println!("Tree after name attribution:");
36 summary(&mut tree);
37 add_child(&mut tree, a, a1);
40 add_child(&mut tree, a, a2);
41 add_child(&mut tree, b, b1);
43 add_child(&mut tree, b, b2);
44 add_child(&mut tree, c, a);
46 add_child(&mut tree, c, b);
47 add_child(&mut tree, root, c);
49 add_child(&mut tree, root, d);
50
51 println!("");
52 println!("Tree after hierarchy attribution:");
53 summary(&mut tree);
54 options.gene_internal = true;
56
57 phyloxml_processing(
58 &mut tree,
59 &options,
60 &config,
61 "modify_tree_ini.svg".to_string(),
62 );
63 println!("Add a loss to C");
71 let loss = tree.new_node("loss".to_string());
72 tree.arena[loss].name = "Loss".to_string();
73 tree.arena[loss].e = Event::Loss;
74 add_child(&mut tree, c, loss);
75
76 println!("Add a node up to B");
77 let add = tree.new_node("add".to_string());
78 tree.arena[add].name = "Added up to B".to_string();
79 println!("Move A to new node ");
80 move_child(&mut tree, a, add);
81 println!("Move B to new node ");
82 move_child(&mut tree, b, add);
83 println!("Move new node to C ");
84 add_child(&mut tree, c, add);
85
86 println!("Tree after hierarchy modification:");
87 summary(&mut tree);
88 reset_pos(&mut tree);
89 phyloxml_processing(
90 &mut tree,
91 &options,
92 &config,
93 "modify_tree_mod.svg".to_string(),
94 );
95
96 println!("Please open output files 'modify_tree_ini.svg' and 'modify_tree_mod.svg' with your browser");
103 println!("OK.");
104}