read_recphyloxml_thirdlevel_1/
read_recphyloxml_thirdlevel_1.rs

1// Visualisation  of  3 levels reconciliation
2//  Case there are several gene trees
3
4use light_phylogeny::{
5    get_gtransfer, map_gene_host, map_parasite_g2s, map_parasite_s2g, map_transfer,
6    map_transfer_mul, phyloxml_processing, read_recphyloxml_multi, recphyloxml_processing,
7    reset_pos, ArenaTree, Config, Options,
8};
9use log::info;
10
11fn main() {
12    let mut options: Options = Options::new();
13    options.gene_internal = true;
14    options.species_internal = true;
15    let mut config: Config = Config::new();
16    config.species_opacity = "0.7".to_string();
17    config.gene_opacity = "0.9".to_string();
18    let transfers = vec![];
19    // let infile_gs = "examples/recgs_mult_host_dtl.recphyloxml".to_string();
20    let infile_gs = "examples/test1/recgs_dtl.recphyloxml".to_string();
21    let infile_sh = "examples/test1/rechp_dtl.recphyloxml".to_string();
22    // Traitement de 2 fichier fichiers recPhyloXML
23    println!("Two reconciled files => displaying 3-levels reconciliations. ");
24    let outfile_gene_para = String::from("gene_para.svg");
25    let outfile_para_host = String::from("para_host.svg");
26    let outfile_mapped_1 = String::from("mapped_1.svg");
27    let outfile_mapped_2 = String::from("mapped_2.svg");
28
29    // ---------------------------------------------------------
30    // Create a structure Arena for the global parasite pipe
31    // tree and a vector of structures Arena for gene path trees
32    // ---------------------------------------------------------
33    let mut global_pipe_parasite: ArenaTree<String> = ArenaTree::default();
34    let mut global_roots: std::vec::Vec<usize> = Vec::new();
35    let mut path_genes: std::vec::Vec<ArenaTree<String>> = Vec::new();
36    // ---------------------------------------------------------
37    // Fill global parasite pipe tree and is roots and path
38    // genes trees
39    // ---------------------------------------------------------
40    read_recphyloxml_multi(
41        infile_gs,
42        &mut global_pipe_parasite,
43        &mut path_genes,
44        &mut global_roots,
45    );
46    let nb_gntree = path_genes.len().clone();
47    println!("Number of gene trees : {}", nb_gntree);
48    info!("List of gene trees : {:?}", path_genes);
49    let nb_parasite_pipe = global_roots.len().clone();
50    println!("Number of parasite trees : {}", nb_parasite_pipe);
51    println!("List of species trees roots : {:?}", global_roots);
52    info!("Global parasite pipe tree : {:?}", global_pipe_parasite);
53    // ---------------------------------------------------------
54    // Generate svg of the lobal parasite pipe tree and  path
55    // genes trees
56    // ---------------------------------------------------------
57    recphyloxml_processing(
58        &mut global_pipe_parasite,
59        &mut path_genes,
60        &mut options,
61        &config,
62        true,
63        &transfers,
64        outfile_gene_para,
65    );
66    // ---------------------------------------------------------
67    // Create a structure Arena for the host pipe tree and a
68    // vector of structures Arena for parasite path trees
69    // ---------------------------------------------------------
70    let mut tree_host_pipe: ArenaTree<String> = ArenaTree::default();
71    let mut path_para_trees: std::vec::Vec<ArenaTree<String>> = Vec::new();
72    // ---------------------------------------------------------
73    // Fill  host pipe tree and is roots and path parasite trees
74    // ---------------------------------------------------------
75    let mut global_roots: std::vec::Vec<usize> = Vec::new();
76    read_recphyloxml_multi(
77        infile_sh,
78        &mut tree_host_pipe,
79        &mut path_para_trees,
80        &mut global_roots,
81    );
82    let nb_parasite_path = path_para_trees.len().clone();
83    println!(
84        "Number of pipe parasite trees in gene-parasite file : {}",
85        nb_parasite_pipe
86    );
87    println!(
88        "Number of path parasite trees in parasite-host file : {}",
89        nb_parasite_path
90    );
91    if nb_parasite_path != nb_parasite_pipe {
92        println!();
93        println!("==============================================");
94        println!("Error! Different number of parasite trees in the 2 files!");
95        println!("       Resulting svg will be incomplete.");
96        println!("==============================================");
97        println!();
98    }
99    // ---------------------------------------------------------
100    // Generate svg of the host pipe tree and path parasite trees
101    // ---------------------------------------------------------
102    recphyloxml_processing(
103        &mut tree_host_pipe,
104        &mut path_para_trees,
105        &mut options,
106        &config,
107        true,
108        &transfers,
109        outfile_para_host,
110    );
111    // ---------------------------------------------------------
112    // Generation of first 3 levels svg
113    // ---------------------------------------------------------
114    info!("Parasite trees as a 'path tree' : {:?}", path_para_trees);
115    info!(
116        "Parasite tree as a 'pipe tree' : {:?}",
117        global_pipe_parasite
118    );
119    println!("==============================================");
120    println!("Map parasite as 'path' to parasite as 'pipe'");
121    println!("==============================================");
122    let mut i = 0;
123    while i < nb_parasite_pipe {
124        map_parasite_g2s(&mut global_pipe_parasite, &mut path_para_trees[i]);
125        i = i + 1;
126    }
127    info!(
128        "Global parasite tree wih events : {:?}",
129        global_pipe_parasite
130    );
131    reset_pos(&mut global_pipe_parasite);
132    let mut i = 0;
133    while i < nb_gntree {
134        reset_pos(&mut path_genes[i]);
135        i = i + 1;
136    }
137    println!("==============================================");
138    println!("Map parasite as 'species' to parasite as 'gene'");
139    println!("==============================================");
140    let mut i = 0;
141    while i < nb_parasite_pipe {
142        map_parasite_s2g(
143            &mut global_pipe_parasite,
144            &mut path_para_trees[i],
145            &mut path_genes,
146        );
147        i = i + 1;
148    }
149    info!(
150        "Global pipe parasite after mapping s2g : {:?}",
151        global_pipe_parasite
152    );
153    println!("==============================================");
154    println!("Map parasite as 'gene' to parasite as 'species' again");
155    println!("==============================================");
156    let mut i = 0;
157    while i < nb_parasite_pipe {
158        map_parasite_g2s(&mut global_pipe_parasite, &mut path_para_trees[i]);
159        i = i + 1;
160    }
161    reset_pos(&mut global_pipe_parasite);
162    let mut i = 0;
163    while i < nb_gntree {
164        reset_pos(&mut path_genes[i]);
165        i = i + 1;
166    }
167    // attention on ne remape pas
168    recphyloxml_processing(
169        &mut global_pipe_parasite,
170        &mut path_genes,
171        &mut options,
172        &config,
173        false,
174        &transfers,
175        outfile_mapped_1,
176    );
177    // ---------------------------------------------------------
178    // Generation of second 3 levels svg
179    // ---------------------------------------------------------
180    let mut i = 0;
181    let gene_transfers = get_gtransfer(&mut path_genes[i]);
182    info!("Transfers = {:?}", gene_transfers);
183    let mut mapped_gene_transfers = map_transfer_mul(gene_transfers, &mut path_para_trees);
184    info!("Mapped transfers = {:?}", mapped_gene_transfers);
185    i = i + 1;
186    while i < nb_gntree {
187        let gene_transfers = get_gtransfer(&mut path_genes[i]);
188        info!("Transfers = {:?}", gene_transfers);
189        let mapped = map_transfer(gene_transfers, &mut path_para_trees[0]);
190        info!("Mapped transfers = {:?}", mapped);
191        for val in mapped {
192            mapped_gene_transfers.push(val);
193        }
194        i = i + 1;
195    }
196    reset_pos(&mut tree_host_pipe);
197    let mut i = 0;
198    while i < nb_parasite_pipe {
199        reset_pos(&mut path_para_trees[i]);
200        i = i + 1;
201    }
202    println!(
203        "Building svg 2:  parasite tree within host pipe tree and mapped tarnsfers {}",
204        outfile_mapped_2
205    );
206    // attention on ne remape pas
207    recphyloxml_processing(
208        &mut tree_host_pipe,
209        &mut path_para_trees,
210        &mut options,
211        &config,
212        false,
213        &mapped_gene_transfers,
214        outfile_mapped_2,
215    );
216
217    reset_pos(&mut global_pipe_parasite);
218    phyloxml_processing(
219        &mut global_pipe_parasite,
220        &mut options,
221        &config,
222        "para_simple.svg".to_string(),
223    );
224    reset_pos(&mut tree_host_pipe);
225    phyloxml_processing(
226        &mut tree_host_pipe,
227        &mut options,
228        &config,
229        "host_simple.svg".to_string(),
230    );
231    let mut i = 0;
232    while i < nb_parasite_pipe {
233        reset_pos(&mut path_para_trees[i]);
234        phyloxml_processing(
235            &mut path_para_trees[i],
236            &mut options,
237            &config,
238            ("gene_simple_".to_owned() + &i.to_string() + ".svg").to_string(),
239        );
240        i = i + 1;
241    }
242
243    //llmlmlmlmlmlm
244    // mapping des gene sur les hotes via les parasites
245    println!("Building svg 3: gene  tree within host pipe tree");
246    map_gene_host(&mut path_genes, &mut path_para_trees, &mut tree_host_pipe);
247
248    // map_gene_host(&mut path_genes, &mut path_para_trees[1], &mut tree_host_pipe);
249    reset_pos(&mut tree_host_pipe);
250    let mut i = 0;
251    while i < nb_gntree {
252        reset_pos(&mut path_genes[i]);
253        i = i + 1;
254    }
255
256    recphyloxml_processing(
257        &mut tree_host_pipe,
258        &mut path_genes,
259        &mut options,
260        &config,
261        true,
262        &vec![],
263        "mapped_3.svg".to_string(),
264    );
265    // println!("DEBUG  FINAL HOST = {:?}",tree_host_pipe);
266    // lmlmlmlm
267
268    println!("Output files:");
269
270    println!(" - host_simple.svg ...... 1 level: host tree");
271    let mut i = 0;
272    while i < nb_parasite_pipe {
273        println!(" - para_simple.svg ...... 2 levels: gene_simple_{}.svg", &i);
274        i = i + 1;
275    }
276    println!(" - para_simple.svg ...... 2 levels: parasite tree(s)");
277    println!(" - gene_para.svg ........ 2 levels: pipe parasite tree(s) with gene tree(s) inside");
278    println!(" - para_host.svg ........ 2 levels: pipe host tree with parasite tree(s) inside");
279    println!(
280        " - mapped_1.svg ........  3 levels: reconciled pipe parasite tree(s) with gene tree(s)"
281    );
282    println!(
283        " - mapped_2.svg ........  3 levels: parasite-host reconciliation plus gene transfers"
284    );
285    println!(" - mapped_3.svg ........  3 levels: pipe host tree with gene tree(s) inside");
286
287    if nb_parasite_path != nb_parasite_pipe {
288        println!();
289        println!("==============================================");
290        println!("Error! Different number of parasite trees in the 2 files!");
291        println!("       Resulting svg will be incomplete.");
292        println!("==============================================");
293        println!();
294    }
295}