Debian Codegraph @

src/applpopulations.cpp

raw
1 /***************************************************************************
2 applpopulations.cpp - description
3 -------------------
4 begin : Mon Oct 30 2000
5 copyright : (C) 2000 by Olivier Langella
6 email : [email protected]
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include "applpopulations.h"
19
20 ApplPopulations::ApplPopulations() :
21 ApplPop() {
22 _square_distance = false;
23 }
24
25 ApplPopulations::~ApplPopulations() {
26 }
27
28 int ApplPopulations::menu_principal() {
29 // calcul de distance entre tous les individus de n pop
30 int choix;
31 _choix = 0;
32
33 cout << endl << endl;
34 cout << _("Main menu") << endl << endl;
35 cout << "0) " << _("Exit") << endl;
36 cout << "1) " << _("Compute individuals distances + tree") << endl;
37 cout << "2) " << _("Compute populations distances + tree") << endl;
38 cout << "3) " << _("Allelic frequencies, Fstats") << endl;
39 cout << "4) " << _("Build phylogenetic tree with a distance matrix")
40 << endl;
41 cout << "5) " << _("Formated output for other softwares") << endl;
42 cout << "6) " << _("Choose the output format of matrix") << endl;
43 cout << "7) " << _("Structured populations") << endl;
44 cout << "8) " << _("microsatellites number of repeats corrections") << endl;
45 // cout << "8) Concatenation de populations" << endl;
46
47 choix = DemandeChoix(0, 8);
48
49 switch (choix) {
50 case 0:
51 return (0);
52 break;
53 case 1:
54 if (!iPopulations())
55 return (1);
56 menu_arbreind();
57 return (1);
58 break;
59
60 case 2:
61 if (!iPopulations())
62 return (1);
63 menu_arbrepop();
64 return (2);
65 break;
66
67 case 3:
68 if (!iPopulations())
69 return (1);
70 menu_calculs();
71 return (3);
72 break;
73
74 case 4:
75 cout << endl << endl;
76 cout << _("Build phylogenetic tree with a distance matrix") << endl;
77 // cout << " a partir d'une matrice de distance" << endl;
78 fmat2arbre();
79 return (4);
80 break;
81
82 case 5:
83 if (!iPopulations())
84 return (1);
85 menu_formats();
86 return (5);
87 break;
88
89 case 6:
90 menu_formatMatrice();
91 return (6);
92 break;
93
94 case 7:
95 if (!iPopulations())
96 return (7);
97 menu_popstructurees();
98 return (7);
99 break;
100
101 case 8:
102 if (!iPopulations())
103 return (8);
104 fmicrosatcorrections();
105 return (7);
106 break;
107
108 /* case 8:
109 if (!iPopulations()) return(8);
110 cout << endl << endl;
111 // cout << "Format de sortie des matrices:" << endl;
112 fconcatenationpop();
113 return(8);
114 break;
115 */
116 default:
117 return (0);
118 break;
119 }
120 }
121
122 void ApplPopulations::fdistind() {
123 MatriceLD distances;
124 string nomFichier;
125
126 nomFichier = DemandeFichier("Individuals distance matrix filename :");
127
128 if (fcompdistind(distances) == false)
129 return;
130
131 ecritMatriceLD(distances, nomFichier);
132 }
133
134 void ApplPopulations::ftreeind() {
135 MatriceLD distances;
136 string nomFichier;
137 int metdist;
138 int metconstruct;
139 // unsigned int i;
140
141 metdist = menu_metdistpop();
142 if (_choix == -1)
143 return;
144
145 metconstruct = menu_metconstructarbre();
146 if (_choix == -1)
147 return;
148
149 nomFichier = DemandeFichier("Individuals tree filename (Phylip format):");
150
151 if (fcompdistind(distances, metdist) == false)
152 return;
153
154 fconstructarbre(distances, nomFichier, metconstruct);
155
156 cout << _("Phylogenetic tree saved in : ") << nomFichier << endl;
157 }
158
159 void ApplPopulations::ftreeindBootLocus() {
160 MatriceLD distances;
161 int metdist;
162 int metconstructarbre;
163 ArbrePlus larbre;
164
165 larbre._titre.resize(2);
166 larbre._titre[0].assign(""); // individus, populations
167 larbre._titre[1].assign(""); // m�thode de distance, nb bootstrap
168
169 metdist = menu_metdistpop();
170 if (_choix == -1)
171 return;
172
173 cout << _("Computing distances between individuals...") << endl;
174 larbre._titre[0].AjEntier(_Pjeupop->get_nbind());
175 larbre._titre[0] += " inidividuals, ";
176 larbre._titre[0].AjEntier(_Pjeupop->get_nbpop());
177 larbre._titre[0] += " populations";
178
179 larbre._titre[1] += DistancesGnt::get_nom_methode(metdist);
180
181 int nbtirages;
182
183 metconstructarbre = menu_metconstructarbre();
184 nbtirages = DemandeEntier(
185 _("How many times do you want to perform bootstraps ?"), 1,
186 30000);
187
188 larbre._titre[1] += ", ";
189 larbre._titre[1].AjEntier(nbtirages);
190 larbre._titre[1] += " bootstraps on locus";
191
192 // cout << _("Output file name (Phylip tree format) ?") << endl;
193 // cin >> _nomFichier;
194 _nomFichier = DemandeFichier("Output file name (Phylip tree format) ?");
195
196 if (_VcalcLocus.size() == 0)
197 _Pjeupop->f_BootstrapLocus(larbre, metconstructarbre, metdist,
198 _square_distance, nbtirages, true);
199 else
200 _Pjeupop->f_BootstrapLocus(larbre, metconstructarbre, metdist,
201 _square_distance, nbtirages, true, &_VcalcLocus);
202 // _Pjeupop->f_BootstrapLocus(larbre, metconstructarbre, metdist, nbtirages, true);
203
204 // larbre.fElimineTrifurcation();
205 ecritArbre(larbre, _nomFichier);
206 }
207
208 void ApplPopulations::fsetniveau() {
209 // r�glage du niveau de structure pour calculs sur des m�tapops
210
211 _niveau = DemandeEntier(_("Which level ?"), 1, 100);
212
213 _Pjeupop->f_rempliVcalcStrucPop(_niveau);
214
215 cerr << "ApplPopulations::fsetniveau() 1" << _VcalcLocus.size() << endl;
216 cout << _("level has been set to: ") << _niveau << endl;
217 cout << _("any compute using metapopulation will use this") << endl;
218 cout << _("(ex: computing distances or making trees") << endl;
219
220 }
221
222 void ApplPopulations::fmat2arbre() {
223 // calcul de distance entre tous les individus de n pop
224 MatriceLD distances;
225 string nomficarbre("");
226
227 cout << _("Reading distance matrix: ") << endl;
228 while (litMatriceLD(distances) == false) {
229 // cout << "Lecture en cours..."<< endl;
230 }
231
232 //cerr << "ApplPopulations::fmat2arbre " << distances.GetNC() << " " << distances.GetNL() << endl;
233
234 try {
235
236 /*
237 if (distances.GetType() != 2) {
238 long i, j;
239 for (i = 0; i < distances.GetNC(); i++) {
240 for (j = 0; j < i; j++) {
241 distances.GetCase(j, i) = distances.GetCase(i, j);
242 }
243 }
244 distances.SetType(2);
245 }
246 */
247 if (distances.SetType(2) == false) {
248 throw biolib::vecteurs::MatriceLD::Anomalie(5);
249 }
250
251 //cerr << "ApplPopulations::fmat2arbre" << endl;
252 //distances.oExcel(cout);
253 fconstructarbre(distances, nomficarbre, menu_metconstructarbre());
254 } catch (MatriceLD::Anomalie pb) {
255 _fichier.close();
256 switch (pb.le_pb) {
257 case 1:
258 _fichier.close();
259 cout << _("Error while reading the matrix file");
260 break;
261
262 case 5:
263 cerr
264 << _("Failure reading matrix file : the matrix is not symetric\n");
265 cerr
266 << _("Populations only works with euclidian distance matrix\n");
267 cerr << _("Please check your file and retry\n\n");
268 break;
269 case 7:
270 cout << _("Out of range access in the matrix");
271 break;
272 }
273 }
274
275 }
276
277 void ApplPopulations::frarefaction() {
278 MatriceLD distances;
279 int taille;
280
281 //cerr << _Pjeupop->get_nbpop();
282 taille = DemandeEntier(_("Sample size ?"), 2, 1000);
283
284 cout << _("Computing...") << endl;
285 _Pjeupop->f_rarefaction(distances, taille);
286
287 cout << _("Results matrix output :") << endl;
288
289 // cerr << distances.GetCase (1,1);
290 ecritMatriceLD(distances);
291 }
292
293 bool ApplPopulations::fcompdistind(MatriceLD & distances, int metdist) {
294 _temp.resize(2);
295 _temp[0].assign(""); // individus, populations
296 _temp[1].assign(""); // m�thode de distance, nb bootstrap
297
298 if (metdist == 0) {
299 metdist = menu_metdistpop();
300 if (_choix == -1)
301 return (false);
302 }
303
304 cout << _("Computing distances between individuals...") << endl;
305 _temp[0].AjEntier(_Pjeupop->get_nbind());
306 _temp[0] += " inidividuals, ";
307 _temp[0].AjEntier(_Pjeupop->get_nbpop());
308 _temp[0] += " populations";
309
310 _temp[1] += DistancesGnt::get_nom_methode(metdist);
311
312 if (_VcalcLocus.size() == 0)
313 _Pjeupop->f_distgnt(distances, metdist, _square_distance);
314 else
315 _Pjeupop->f_distgnt(distances, metdist, _square_distance, &_VcalcLocus);
316
317 return (true);
318 }
319
320 bool ApplPopulations::fcompdistpop(MatriceLD & distances, int metdist) {
321 // calcul de distance entre toutes les populations
322 _temp.resize(2);
323 _temp[0].assign(""); // individus, populations
324 _temp[1].assign(""); // m�thode de distance, nb bootstrap
325
326 if (metdist == 0) {
327 metdist = menu_metdistpop();
328 if (_choix == -1)
329 return (false);
330 }
331
332 cout << _("Computing distances between populations...") << endl;
333 _temp[0].AjEntier(_Pjeupop->get_nbpop());
334 _temp[0] += " populations";
335
336 _temp[1] += DistancesGnt::get_nom_methode(metdist);
337
338 try {
339 //cerr << "ApplPopulations::fcompdistpop(MatriceLD & distances, int metdist) 1" << _VcalcLocus.size() << endl;
340 if (_VcalcLocus.size() == 0) {
341 //cerr << "ApplPopulations::fcompdistpop(MatriceLD & distances, int metdist) niveau " << _niveau << endl;
342 _Pjeupop->f_distgntpop(distances, metdist, _square_distance,
343 _niveau);
344 } else {
345 _Pjeupop->f_distgntpop(distances, metdist, _square_distance,
346 _niveau, &_VcalcLocus);
347 }
348 } catch (Jeupop::Anomalie lepb) {
349 // cerr << endl << lepb.fmessage() << endl;
350 return (false);
351 }
352
353 return (true);
354 }
355
356 void ApplPopulations::fdistpop() {
357 // sortie des distance entre toutes les populations
358 MatriceLD distances;
359 string nomFichier;
360
361 nomFichier = DemandeFichier(_("Populations distance matrix filename :"));
362
363 if (fcompdistpop(distances) == false)
364 return;
365
366 ecritMatriceLD(distances, nomFichier);
367 }
368
369 void ApplPopulations::ftreepop() {
370 // sortie de l'arbre phylogenetic des pops
371 MatriceLD distances;
372 string nomFichier;
373 int metdist;
374 int metconstruct;
375
376 metdist = menu_metdistpop();
377 if (_choix == -1)
378 return;
379
380 metconstruct = menu_metconstructarbre();
381 if (_choix == -1)
382 return;
383
384 nomFichier
385 = DemandeFichier(_("Populations tree filename (Phylip format):"));
386
387 if (fcompdistpop(distances, metdist)) {
388 fconstructarbre(distances, nomFichier, metconstruct);
389
390 cout << _("Phylogenetic tree saved in : ") << nomFichier << endl;
391 } else {
392 cout
393 << _("Phylogenetic tree reconstruction aborted, tree file was not written")
394 << endl;
395 }
396 }
397
398 void ApplPopulations::ftreepopBootLocus() {
399 // calcul de distance entre toutes les populations
400 // avec bootstrap sur les locus
401 MatriceLD distances;
402 int metdist;
403 int metconstructarbre;
404
405 ArbrePlus larbre;
406 int nbtirages;
407
408 metdist = menu_metdistpop();
409 if (_choix == -1) {
410 _choix = 1;
411 return;
412 }
413
414 metconstructarbre = menu_metconstructarbre();
415 nbtirages = DemandeEntier("Combien de tirages voulez-vous effectuer ?", 1,
416 10000);
417
418 larbre._titre.resize(2);
419 larbre._titre[0].assign(""); // individus, populations
420 larbre._titre[1].assign(""); // m�thode de distance, nb bootstrap
421
422 larbre._titre[0].AjEntier(_Pjeupop->get_nbpop());
423 larbre._titre[0] += " populations";
424
425 larbre._titre[1] += DistancesGnt::get_nom_methode(metdist);
426 larbre._titre[1] += ", ";
427 larbre._titre[1].AjEntier(nbtirages);
428 larbre._titre[1] += " bootstraps on locus";
429
430 _nomFichier = DemandeFichier(
431 _("Populations tree filename (Phylip format):"));
432
433 try {
434 if (_VcalcLocus.size() == 0)
435 _Pjeupop->f_BootstrapLocus(larbre, metconstructarbre, metdist,
436 _square_distance, nbtirages, false);
437 else
438 _Pjeupop->f_BootstrapLocus(larbre, metconstructarbre, metdist,
439 _square_distance, nbtirages, false, &_VcalcLocus);
440 } catch (Jeupop::Anomalie lepb) {
441 cout
442 << _("Phylogenetic tree reconstruction aborted, tree file was not written")
443 << endl;
444 return;
445 }
446
447 // larbre.fElimineTrifurcation();
448 ecritArbre(larbre, _nomFichier);
449 }
450
451 void ApplPopulations::ftreepopBootInd() {
452 // calcul de distance entre toutes les populations
453 // avec bootstrap sur les individus
454 MatriceLD distances;
455 int metdist;
456 int metconstructarbre;
457
458 ArbrePlus larbre;
459 int nbtirages;
460
461 metdist = menu_metdistpop();
462 if (_choix == -1) {
463 _choix = 1;
464 return;
465 }
466
467 metconstructarbre = menu_metconstructarbre();
468 nbtirages = DemandeEntier(
469 _("How many times do you want to perform bootstraps ?"), 1,
470 30000);
471
472 larbre._titre.resize(2);
473 larbre._titre[0].assign(""); // individus, populations
474 larbre._titre[1].assign(""); // m�thode de distance, nb bootstrap
475
476 larbre._titre[0].AjEntier(_Pjeupop->get_nbpop());
477 larbre._titre[0] += " populations";
478
479 larbre._titre[1] += DistancesGnt::get_nom_methode(metdist);
480 larbre._titre[1] += ", ";
481 larbre._titre[1].AjEntier(nbtirages);
482 larbre._titre[1] += " bootstraps on individuals";
483
484 _nomFichier = DemandeFichier(
485 _("Populations tree filename (Phylip format):"));
486
487 try {
488 if (_VcalcLocus.size() == 0)
489 _Pjeupop->f_BootstrapIndividus(larbre, metconstructarbre, metdist,
490 _square_distance, nbtirages);
491 else
492 _Pjeupop->f_BootstrapIndividus(larbre, metconstructarbre, metdist,
493 _square_distance, nbtirages, &_VcalcLocus);
494 } catch (Jeupop::Anomalie lepb) {
495 cout
496 << _("Phylogenetic tree reconstruction aborted, tree file was not written")
497 << endl;
498 return;
499 }
500
501 // larbre.fElimineTrifurcation();
502 ecritArbre(larbre, _nomFichier);
503 }
504
505 void ApplPopulations::ecritGenepop() {
506 // cout << _("Output file name (Genepop modified format) ?") << endl;
507 // cin >> _nomFichier;
508 _nomFichier = DemandeFichier(
509 _("Output file name (Genepop modified format) ?"));
510
511 try {
512 _sortie.open(_nomFichier.c_str(), ios::out);
513 _Pjeupop->oGenepop(_sortie);
514 _sortie.close();
515 } catch (Jeupop::Anomalie pb) {
516 _sortie.close();
517 switch (pb.le_pb) {
518 case 1:
519 cerr << endl
520 << _("Genepop format allows only diploid genetic datasets")
521 << endl;
522 break;
523 case 2:
524 //la numerotation est a refaire, avec une table de conversion
525 //cerr << "ApplPop::ecritGenepop() impossible" << endl;
526 Jeupop traduction(*_Pjeupop);
527
528 _sortie.open("correspondances.txt", ios::out);
529 traduction.f_trad2Gpop(_sortie);
530 // _sortie << ends;
531 _sortie.close();
532
533 _sortie.open(_nomFichier.c_str(), ios::out);
534 traduction.oGenepopCano(_sortie);
535 _sortie.close();
536
537 break;
538 }
539 }
540 }
541
542 void ApplPopulations::ecritGenepopCano() {
543 // cout << _("Output file name (canonical Genepop format) ?") << endl;
544 // cin >> _nomFichier;
545 _nomFichier = DemandeFichier(
546 _("Output file name (canonical Genepop format) ?"));
547
548 try {
549 _sortie.open(_nomFichier.c_str(), ios::out);
550 _Pjeupop->oGenepopCano(_sortie);
551 _sortie.close();
552 } catch (Jeupop::Anomalie pb) {
553 _sortie.close();
554 switch (pb.le_pb) {
555 case 1:
556 cerr << endl
557 <<_("Genepop format allows only diploid genetic datasets")
558 << endl;
559 break;
560 case 2:
561 //la numerotation est a refaire, avec une table de conversion
562 Jeupop traduction(*_Pjeupop);
563
564 _sortie.open("correspondances.txt", ios::out);
565 traduction.f_trad2Gpop(_sortie);
566 // _sortie << ends;
567 _sortie.close();
568
569 _sortie.open(_nomFichier.c_str(), ios::out);
570 traduction.oGenepop(_sortie);
571 _sortie.close();
572
573 break;
574 }
575 }
576 }
577
578 void ApplPopulations::ecritPopulations() {
579 // cout << _("Output file name (Populations format) ?") << endl;
580 // cin >> _nomFichier;
581 _nomFichier = DemandeFichier(_("Output file name (Populations format) ?"));
582
583 try {
584 _sortie.open(_nomFichier.c_str(), ios::out);
585 _Pjeupop->oPopulations(_sortie);
586 _sortie.close();
587 } catch (Jeupop::Anomalie pb) {
588 _sortie.close();
589 switch (pb.le_pb) {
590 default:
591 cerr << _("Error writing Populations file...") << endl;
592 }
593 }
594 }
595
596 void ApplPopulations::menu_formats() {
597
598 Vecteur<unsigned int> Vlocus;
599 Jeupop * Pjeupopsvg(0);
600
601 int choix(1);
602 while (choix != 0) {
603 cout << endl << endl;
604 cout << _("Output format:") << endl;
605 cout << "0) " << _("Back") << endl;
606 cout << "1) " << _("Choose locus to export (default: all)") << endl;
607 cout << "2) " << _("Populations format") << endl;
608 cout << "3) " << _("Populations XML format") << endl;
609 cout << "4) " << _("Genepop format") << endl;
610 cout << "5) " << _("Genepop modified format") << endl;
611 cout << "6) " << _("Immanc format") << endl;
612 cout << "7) " << _("microsat individuals format") << endl;
613 cout << "8) " << _("microsat populations + frequencies format") << endl;
614 cout << "9) " << _("LEA Likelihood Estimation of Admixture") << endl;
615 cout << "10) " << _("Admix (G. Bertorelle)") << endl;
616 cout << "11) " << _("Genetix") << endl;
617 cout << "12) " << _("Fstat (Jerome Goudet)") << endl;
618
619 choix = DemandeChoix(0, 12);
620
621 switch (choix) {
622 case 0:
623 if (Pjeupopsvg != 0) {
624 delete _Pjeupop;
625 _Pjeupop = Pjeupopsvg;
626 }
627 break;
628 case 1:
629 //choix des locus
630 Vlocus = menu_choixlocus();
631 if (Vlocus.size() != 0) {
632 Pjeupopsvg = _Pjeupop;
633 _Pjeupop = new Jeupop(*Pjeupopsvg);
634 _Pjeupop->GarderVlocus(Vlocus);
635 }
636 break;
637 case 2:
638 ecritPopulations();
639 break;
640 case 3:
641 ecritPopulationsXML();
642 break;
643 case 4:
644 ecritGenepopCano();
645 break;
646 case 5:
647 ecritGenepop();
648 break;
649 case 6:
650 ecritImmanc();
651 break;
652 case 7:
653 ecritMsat(1);
654 break;
655 case 8:
656 ecritMsat(2);
657 break;
658 case 9:
659 ecritLea();
660 break;
661 case 10:
662 ecritAdmix();
663 break;
664 case 11:
665 ecritGenetix();
666 break;
667 case 12:
668 ecritFstat();
669 break;
670 }
671 }
672
673 }
674
675 void ApplPopulations::menu_popstructurees() {
676
677 int choix(0);
678 _choix = 1;
679 while (_choix > 0) {
680 cout << endl << endl;
681 cout << _("Structured Populations") << endl;
682 cout << endl << endl;
683 cout << "0) " << _("back") << endl;
684 cout << "1) " << _("Show structure level") << endl;
685 cout << "2) " << _("Set level") << endl;
686 cout << "3) " << _("Display Wright indices per loci") << endl;
687
688 choix = DemandeChoix(0, 3);
689
690 switch (choix) {
691 case 0:
692 _choix = -1;
693 return;
694 break;
695 case 1:
696 AffNiveauxPopStruc(cout);
697 break;
698 case 2:
699 fsetniveau();
700 case 3:
701 Fstat lesfstats(_Pjeupop->get_Pracinepop());
702 lesfstats.f_affparlocus(cout);
703 break;
704 }
705 }
706 }
707
708 void ApplPopulations::menu_calculs() {
709
710 int choix(0);
711 _choix = 1;
712 while (_choix > 0) {
713 cout << endl << endl;
714 cout << _("Allelic frequencies, Fstats") << endl;
715 cout << endl << endl;
716 cout << "0) " << _("back") << endl;
717 cout << "1) " << _("Allelic diversity for reduced sample") << endl;
718 cout << "2) " << _("Fst, Fis, Fit per populations") << endl;
719
720 choix = DemandeChoix(0, 3);
721
722 switch (choix) {
723 case 0:
724 _choix = -1;
725 return;
726 break;
727 case 1:
728 cout << endl << endl;
729 cout << _("Compute allelic diversity") << endl;
730 cout << _(" for reduced sample") << endl;
731 frarefaction();
732 break;
733 case 2:
734 ecritRapportFst();
735 break;
736 }
737 }
738 }
739
740 void ApplPopulations::menu_arbrepop() {
741
742 int choix(0);
743
744 set_groupes_populations();
745
746 _choix = 1;
747 while (_choix > 0) {
748 cout << endl << endl;
749 cout << _("Reconstructing phylogenetic trees with populations") << endl;
750 cout << endl << endl;
751 cout << "0) " << _("back") << endl;
752 cout << "1) " << _("Get distance matrix between populations") << endl;
753 cout << "2) " << _("Phylogenetic tree of populations") << endl;
754 cout << "3) "
755 << _("Phylogenetic tree of populations with bootstraps on locus")
756 << endl;
757 cout << "4) "
758 << _("Phylogenetic tree of populations with bootstraps on individuals")
759 << endl;
760 cout << "5) " << _("Choose locus to compute distances (default: all)")
761 << endl;
762
763 choix = DemandeChoix(0, 5);
764
765 switch (choix) {
766 case 0:
767 _choix = -1;
768 return;
769 break;
770 case 1:
771 fdistpop();
772 break;
773 case 2:
774 ftreepop();
775 break;
776 case 3:
777 ftreepopBootLocus();
778 break;
779 case 4:
780 ftreepopBootInd();
781 break;
782 case 5:
783 _VcalcLocus = menu_choixlocus();
784 affVlocus(_VcalcLocus);
785 break;
786 }
787 }
788 reset_groupes();
789 }
790
791 void ApplPopulations::menu_arbreind() {
792
793 int choix(0);
794
795 set_groupes_individus();
796
797 _choix = 1;
798 while (_choix > 0) {
799 cout << endl << endl;
800 cout << _("Reconstructing phylogenetic trees with individuals") << endl;
801 cout << endl << endl;
802 cout << "0) " << _("back") << endl;
803 cout << "1) " << _("Get distance matrix between individuals") << endl;
804 cout << "2) " << _("Phylogenetic tree of individuals") << endl;
805 cout << "3) "
806 << _("Phylogenetic tree of individuals with bootstraps on locus")
807 << endl;
808 cout << "4) " << _("Choose locus to compute distances (default: all)")
809 << endl;
810
811 choix = DemandeChoix(0, 4);
812
813 switch (choix) {
814 case 0:
815 _choix = -1;
816 return;
817 break;
818 case 1:
819 fdistind();
820 break;
821 case 2:
822 ftreeind();
823 break;
824 case 3:
825 ftreeindBootLocus();
826 break;
827 case 4:
828 _VcalcLocus = menu_choixlocus();
829 affVlocus(_VcalcLocus);
830 break;
831 }
832 }
833
834 reset_groupes();
835 }
836
837 void ApplPopulations::AffNiveauxPopStruc(ostream &) {
838
839 //Affichage des niveaux de structuration des populations
840 Titre nom_niveaux;
841 unsigned long i;
842
843 _Pjeupop->get_nomniveauxstruc(nom_niveaux);
844
845 cout << endl << endl;
846 cout << _("Structured Population") << endl;
847 cout << endl;
848
849 for (i = 0; i < nom_niveaux.size(); i++) {
850 cout << _("Level ") << i << ":" << endl;
851 cout << nom_niveaux[i] << endl;
852 }
853
854 }
855
856 void ApplPopulations::ecritImmanc() {
857 // cout << _("Output file format (Immanc format) ?") << endl;
858 // cin >> _nomFichier;
859 _nomFichier = DemandeFichier(_("Output file format (Immanc format) ?"));
860
861 try {
862 _sortie.open(_nomFichier.c_str(), ios::out);
863 _Pjeupop->oImmanc(_sortie);
864 _sortie.close();
865 } catch (Jeupop::Anomalie pb) {
866 _sortie.close();
867 switch (pb.le_pb) {
868 case 1:
869 cerr << endl
870 << _("Immanc format allows only diploid genetic datasets")
871 << endl;
872 break;
873 case 2:
874 //la numerotation est a refaire, avec une table de conversion
875 Jeupop traduction(*_Pjeupop);
876
877 _sortie.open("correspondances.txt", ios::out);
878 traduction.f_trad2Gpop(_sortie);
879 _sortie << ends;
880 _sortie.close();
881
882 _sortie.open(_nomFichier.c_str(), ios::out);
883 traduction.oImmanc(_sortie);
884 _sortie.close();
885
886 break;
887 }
888 }
889 }
890
891 void ApplPopulations::ecritLea() {
892 // format LEA Likelihood Estimation of Admixture
893 unsigned long P1, P2, H;
894
895 P1
896 = DemandePopulation(
897 _("What is the name of the population P1 (parental population) ?"));
898 P2
899 = DemandePopulation(
900 _("What is the name of the population P2 (parental population) ?"));
901 H
902 = DemandePopulation(
903 _("What is the name of the population H (hybrid population)?"));
904
905 // cout << _("Output file name (LEA format, M.A. Beaumont, L. Chikhi) ?") << endl;
906 // cin >> _nomFichier;
907 _nomFichier
908 = DemandeFichier(
909 _("Output file name (LEA format, M.A. Beaumont, L. Chikhi) ?"));
910
911 try {
912 _sortie.open(_nomFichier.c_str(), ios::out);
913
914 JeuPopExp exportation(_Pjeupop);
915
916 exportation.oLea(P1, P2, H, _sortie, cout);
917
918 _sortie.close();
919 } catch (JeuPopExp::Anomalie pb) {
920 _sortie.close();
921 switch (pb.le_pb) {
922 case 1:
923 break;
924 case 2:
925 break;
926 default:
927 cerr << _("Error number: ") << pb.le_pb << _(" in the object: ")
928 << "JeuPopExp" << endl;
929 break;
930 }
931 }
932 }
933
934 void ApplPopulations::ecritAdmix() {
935 // format Admix http://www.unife.it/genetica/Giorgio/giorgio.html
936 unsigned long P1, P2, H;
937 string fichier_mtx;
938
939 P1
940 = DemandePopulation(
941 _("What is the name of the population P1 (parental population) ?"));
942 P2
943 = DemandePopulation(
944 _("What is the name of the population P2 (parental population) ?"));
945 H
946 = DemandePopulation(
947 _("What is the name of the population H (hybrid population)?"));
948
949 cout << _("Output file name (Admix .dat format, G. Bertorelle) ?") << endl;
950 cin >> _nomFichier;
951
952 cout << _("Output file name (Admix .mtx format, G. Bertorelle) ?") << endl;
953 cin >> fichier_mtx;
954
955 try {
956 _sortie.open(_nomFichier.c_str(), ios::out);
957 JeuPopExp exportation(_Pjeupop);
958 exportation.oAdmix_dat(P1, P2, H, _sortie, cout);
959 _sortie.close();
960
961 _sortie.open(fichier_mtx.c_str(), ios::out);
962 exportation.oAdmix_mtx(_sortie, cout);
963 _sortie.close();
964 } catch (JeuPopExp::Anomalie pb) {
965 _sortie.close();
966 switch (pb.le_pb) {
967 case 1:
968 break;
969 case 2:
970 break;
971 default:
972 cerr << _("Error number: ") << pb.le_pb << _(" in the object: ")
973 << "JeuPopExp" << endl;
974 break;
975 }
976 }
977 }
978
979 void ApplPopulations::ecritMsat(int choix) {
980 // cout << _("Output file (Microsat format) ?") << endl;
981 // cin >> _nomFichier;
982 _nomFichier = DemandeFichier(_("Output file (Microsat format) ?"));
983
984 try {
985 _sortie.open(_nomFichier.c_str(), ios::out);
986 switch (choix) {
987 case 1:
988 _Pjeupop->oMsat(_sortie);
989 break;
990 default:
991 _Pjeupop->oMsatFreq(_sortie);
992 break;
993 }
994 _sortie.close();
995 } catch (Jeupop::Anomalie pb) {
996 _sortie.close();
997 switch (pb.le_pb) {
998 // case 1:
999 // cerr << endl << "le format Immanc ne permet que le stockage de pop diploides" << endl;
1000 // break;
1001 case 2:
1002 //les noms d'alleles ne sont pas des tailles de msat
1003 cout << _("Populations is not able to export dataset:") << endl;
1004 // cout << _("Les noms d'alleles doivent correspondre a des tailles de microsatellites (ou au nombre de repetitions).") << endl;
1005 cout
1006 << _("Alleles names should be numeric, corresponding to allele size (or number of repetition).")
1007 << endl;
1008
1009 break;
1010 }
1011 }
1012 }
1013
1014 int ApplPopulations::menu_metconstructarbre() {
1015
1016 int choix;
1017 _choix = 0;
1018
1019 // while (_choix != 0) {
1020 cout << endl << endl;
1021 // cout << "0) Menu principal" << endl;
1022 cout << "1) " << _("UPGMA") << endl;
1023 cout << "2) " << _("Neighbor Joining") << endl;
1024 cout << endl << _("Your choice: ");
1025 cin >> choix;
1026
1027 switch (choix) {
1028 // case 0:
1029 // _choix = -1;
1030 // return;
1031 // break;
1032 case 1:
1033 return (1);
1034 break;
1035 case 2:
1036 return (2);
1037 break;
1038 default:
1039 return (2);
1040 break;
1041 }
1042 // }
1043
1044 }
1045
1046 int ApplPopulations::menu_metdistpop() {
1047
1048 int choix;
1049 unsigned int i, nb_methods(DistancesGnt::get_nb_methodes());
1050 _choix = 0;
1051
1052 // while (_choix != 0) {
1053 cout << endl << _("Distance methods") << endl;
1054 cout << "0) " << _("Back") << endl;
1055 for (i = 1; i < nb_methods; i++) {
1056 cout << (i) << ") " << DistancesGnt::get_nom_methode(i) << endl;
1057 }
1058 if (_square_distance)
1059 cout << nb_methods << ") " << _("Squared distance: yes") << endl;
1060 else
1061 cout << nb_methods << ") " << _("Squared distance: no") << endl;
1062 /*
1063 cout << "1) " << _("DAS, Allelic Shared Distance (Chakraborty et Jin., 1993)") << endl;
1064 cout << "2) " << _("Nei, minimum genetic distance, Dm (Nei,1987)") << endl;
1065 cout << "3) " << _("Nei, standard genetic distance, Ds (Nei, 1987)") << endl;
1066 cout << "4) " << _("Cavalli-Sforza and Edwards, Dc (1967)") << endl;
1067 cout << "5) " << _("Nei et al's, Da (1983)") << endl;
1068 cout << "6) " << _("Goldstein et al., dmu2 (1995a)") << endl;
1069 cout << "7) " << _("Latter, Fst (1972)") << endl;
1070 cout << "8) " << _("Prevosti et al.'s, Cp (1975)") << endl;
1071 cout << "9) " << _("Rogers', Dr (1972)") << endl;
1072 cout << "10) " << _("Average Square Distance (ASD, Goldstein, Slatkin 1995)") << endl;
1073 cout << "11) " << _("Shriver et al's, Dsw (1995)") << endl;
1074 cout << "12) " << _("Lev A. Zhivotovsky, DR (1999)") << endl;
1075 */
1076
1077 choix = DemandeChoix(0, nb_methods + 1);
1078
1079 switch (choix) {
1080 case 0:
1081 _choix = -1;
1082 return (-1);
1083 break;
1084 case 1:
1085 return (101); //Das sur les individus
1086 break;
1087 case 2:
1088 return (102); //Nei sur les populations
1089 break;
1090 case 3:
1091 return (103); //Nei sur les populations
1092 break;
1093 case 4:
1094 return (104); //Cavalli-Sforza and Edwards' (1967)sur les populations
1095 break;
1096 case 5:
1097 return (5); // Nei et al's, Da (1983) sur les populations
1098 break;
1099 case 6:
1100 return (106); // Goldstein et al., Mu (1995a) sur les populations
1101 break;
1102 case 7:
1103 return (107); // Latter's Fst (1972) sur les populations
1104 break;
1105 case 8:
1106 return (108); // Prevosti et al.'s, Cp (1975) sur les populations
1107 break;
1108 case 9:
1109 return (109); // Rogers', Dr (1972) sur les populations
1110 break;
1111 case 10:
1112 return (110); // Goldstein et al. (1995b) Slatkin 1995
1113 break;
1114 case 11:
1115 return (111); // Shriver et al's, Dsw (1995)
1116 break;
1117 case 12:
1118 return (112); // Lev A. Zhivotovsky, DR (1999)
1119 break;
1120 case 13:
1121 return (113); // Reynolds unweighted (1983)
1122 break;
1123 case 14:
1124 return (114); // Reynolds weighted (1983)
1125 break;
1126 case 15:
1127 return (115); // Reynolds least squares (1983)
1128 break;
1129
1130 case 16:
1131 _square_distance = !_square_distance;
1132 return (menu_metdistpop());
1133 break;
1134
1135 default:
1136 return (5);
1137 break;
1138 }
1139 }
1140
1141 void ApplPopulations::fconstructarbre(MatriceLD &distances,
1142 string & nomficarbre, int methodearbre) {
1143 ArbrePlus larbre;
1144 bool continuer(true);
1145
1146 if (_temp.size() != 0)
1147 larbre._titre = _temp;
1148 switch (methodearbre) {
1149 case 1:
1150 cerr << _("Building phylogenetic tree with UPGMA...") << endl;
1151 larbre._titre.push_back("UPGMA");
1152 break;
1153 case 2:
1154 cerr << _("Building phylogenetic tree with Neighbor-Joining...")
1155 << endl;
1156 larbre._titre.push_back("Neighbor-Joining");
1157 break;
1158 case 101:
1159 cerr << _("Building phylogenetic tree with UPGMA...") << endl;
1160 larbre._titre.push_back("UPGMA");
1161 break;
1162 case 102:
1163 cerr << _("Building phylogenetic tree with Neighbor-Joining...")
1164 << endl;
1165 larbre._titre.push_back("Neighbor-Joining");
1166 break;
1167 default:
1168 cerr
1169 << _("Error missing construction method to build phylogenetic tree")
1170 << endl;
1171 // larbre._titre.push_back("UPGMA");
1172 return;
1173 }
1174
1175 while (continuer) {
1176 continuer = false;
1177 try {
1178 // _sortie.open("debug.txt", ios::out);
1179 // distances.oExcel(_sortie);
1180 // _sortie.close();
1181 //cerr << "ApplPopulations::fconstructarbre debut iDistances" << endl;
1182 larbre.iDistances(distances, methodearbre);
1183 // larbre.fElimineTrifurcation();
1184 //cerr << "ApplPopulations::fconstructarbre fin iDistances" << endl;
1185
1186 ecritArbre(larbre, nomficarbre);
1187 } catch (Arbre::Anomalie pb) {
1188 switch (pb.le_pb) {
1189 case 4:
1190 cout << _("Inconsistant matrix file format") << endl;
1191 break;
1192 case 5:
1193 cout << _("the matrix is too small") << endl;
1194 break;
1195 case 6:
1196 cout << _("Negative distances in the matrix...") << endl;
1197 cout << _("the smallest value is: ")
1198 << distances.get_ppvaleur() << endl;
1199 cout
1200 << _("to build a tree, you must set negative values to zero.")
1201 << endl;
1202 if (DemandeOuiNon(
1203 _("Do you want to set negative values to zero (Y/N) ?"))) {
1204 distances.f_neg2zero();
1205 continuer = true;
1206 }
1207 break;
1208 }
1209 if (continuer == false)
1210 cout << _("The tree file was not written.") << endl;
1211
1212 }
1213 }// continuer
1214 _temp.resize(0);
1215 }
1216
1217 void ApplPopulations::ecritArbre(ArbrePlus & larbre, string nomFichier) {
1218 //cerr << "ApplPopulations::ecritArbre(ArbrePlus & larbre, string nomFichier) debut" << endl;
1219 set_groupes_arbre(larbre);
1220
1221 if (nomFichier == "") {
1222 cout << _("Output tree file:") << endl;
1223 nomFichier = DemandeFichier(
1224 _("Name of output file (Phylip tree file) ?"));
1225 }
1226
1227 _sortie.open(nomFichier.c_str(), ios::out);
1228 larbre.oFichier(_sortie, 1);
1229 // _sortie << larbre;
1230 // _sortie << endl << ends;
1231 _sortie.close();
1232 //cerr << "ApplPopulations::ecritArbre(ArbrePlus & larbre, string nomFichier) fin" << endl;
1233 }
1234
1235 void ApplPopulations::fLigneCommande(char ** commandes, int nbcommandes) {
1236 Titre tab_commandes(commandes, nbcommandes);
1237
1238 if (tab_commandes.Position("-phylogeny") > 0)
1239 fLiPhylogeny(tab_commandes);
1240 else if (tab_commandes.Position("--test") >= 0)
1241 fLiTest(tab_commandes);
1242 else
1243 fLiHelp();
1244 }
1245
1246 void ApplPopulations::fLiPhylogeny(Titre & tab_commandes) {
1247 // demande d'arbre phylog�n�tique
1248 int pos;
1249 // unsigned int niveau(100); //niveau pour populations structur�es
1250 ArbrePlus larbre;
1251
1252 istream * Pentree(&cin);
1253 ostream * Psortie(&cout);
1254
1255 tab_commandes.Suppr(0);
1256
1257 //fichiers d'entree ou entree standard (par d�faut)
1258 _fichier.open(tab_commandes[0].c_str(), ios::in);
1259
1260 if (_fichier.is_open())
1261 Pentree = &_fichier;
1262 try {
1263 _Pjeupop = new Jeupop();
1264 *Pentree >> *(_Pjeupop);
1265 _fichier.close();
1266 _fichier.clear();
1267 } catch (Jeupop::Anomalie pb) {
1268 _fichier.close();
1269 _fichier.clear();
1270 delete _Pjeupop;
1271
1272 switch (pb.le_pb) {
1273 case 4:
1274 cerr << _("Input file format seems incorrect...") << endl;
1275 return;
1276 break;
1277 }
1278 }
1279
1280 //fichiers de sortie ou sortie standard (sortie standard par d�faut)
1281 pos = tab_commandes.Position("-output");
1282 if ((pos > 0) && (pos + 1 != (long) tab_commandes.size())) {
1283 _sortie.open(tab_commandes[pos + 1].c_str(), ios::out);
1284 cerr
1285 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) debug output : "
1286 << tab_commandes[pos + 1].c_str() << endl;
1287 if (_sortie.is_open() != 0)
1288 Psortie = &_sortie;
1289 tab_commandes.Suppr(pos + 1);
1290 tab_commandes.Suppr(pos);
1291 }
1292
1293 // Individus ou Populations ? (populations par d�faut)
1294 bool sur_pop(true);
1295
1296 //tab_commandes.Suppr(tab_commandes.Position("-phylogeny"));
1297 pos = tab_commandes.Position("-phylogeny");
1298
1299 if ((pos + 1 != (long) tab_commandes.size()) && (tab_commandes[pos + 1]
1300 == "ind")) {
1301 sur_pop = false;
1302 tab_commandes.Suppr(pos + 1);
1303 cerr
1304 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) debug phylogeny : ind"
1305 << endl;
1306 } else if ((pos + 1 != (long) tab_commandes.size()) && (tab_commandes[pos
1307 + 1] == "pop")) {
1308 tab_commandes.Suppr(pos + 1);
1309 cerr
1310 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) debug phylogeny : pop"
1311 << endl;
1312 }
1313 tab_commandes.Suppr(pos);
1314
1315 // Methode de distance ? (Nei standard par d�faut)
1316 int metdist(102);
1317 pos = tab_commandes.Position("-dist");
1318 if ((pos > 0) && (pos + 1 != (long) tab_commandes.size())) {
1319 if (tab_commandes[pos + 1] == "DAS") {
1320 metdist = 5;
1321 tab_commandes.Suppr(pos + 1);
1322 } else if (tab_commandes[pos + 1] == "Dm") {
1323 metdist = 101;
1324 tab_commandes.Suppr(pos + 1);
1325 } else if ((tab_commandes[pos + 1] == "Ds") || (tab_commandes[pos + 1]
1326 == "nei")) {
1327 metdist = 102;
1328 tab_commandes.Suppr(pos + 1);
1329 } else if ((tab_commandes[pos + 1] == "Dc") || (tab_commandes[pos + 1]
1330 == "cav")) {
1331 metdist = 103;
1332 tab_commandes.Suppr(pos + 1);
1333 } else if (tab_commandes[pos + 1] == "Da") {
1334 metdist = 104;
1335 tab_commandes.Suppr(pos + 1);
1336 } else if ((tab_commandes[pos + 1] == "dmu2")
1337 || (tab_commandes[pos + 1] == "goldstein")) {
1338 metdist = 106;
1339 tab_commandes.Suppr(pos + 1);
1340 } else if ((tab_commandes[pos + 1] == "Fst") || (tab_commandes[pos + 1]
1341 == "latter")) {
1342 metdist = 107;
1343 tab_commandes.Suppr(pos + 1);
1344 } else if ((tab_commandes[pos + 1] == "Cp") || (tab_commandes[pos + 1]
1345 == "prevosti")) {
1346 metdist = 108;
1347 tab_commandes.Suppr(pos + 1);
1348 } else if ((tab_commandes[pos + 1] == "Dr") || (tab_commandes[pos + 1]
1349 == "roger")) {
1350 metdist = 109;
1351 tab_commandes.Suppr(pos + 1);
1352 } else if (tab_commandes[pos + 1] == "ASD") {
1353 metdist = 110;
1354 tab_commandes.Suppr(pos + 1);
1355 } else if ((tab_commandes[pos + 1] == "Dsw") || (tab_commandes[pos + 1]
1356 == "shriver")) {
1357 metdist = 111;
1358 tab_commandes.Suppr(pos + 1);
1359 } else if ((tab_commandes[pos + 1] == "DR") || (tab_commandes[pos + 1]
1360 == "zhiv")) {
1361 metdist = 112;
1362 tab_commandes.Suppr(pos + 1);
1363 } else if ((tab_commandes[pos + 1] == "Dru") || (tab_commandes[pos + 1]
1364 == "reynoldsu")) {
1365 metdist = 113;
1366 tab_commandes.Suppr(pos + 1);
1367 } else if ((tab_commandes[pos + 1] == "Drw") || (tab_commandes[pos + 1]
1368 == "reynoldsw")) {
1369 metdist = 114;
1370 tab_commandes.Suppr(pos + 1);
1371 } else if ((tab_commandes[pos + 1] == "Drl") || (tab_commandes[pos + 1]
1372 == "reynoldsl")) {
1373 metdist = 115;
1374 tab_commandes.Suppr(pos + 1);
1375 }
1376 /* return(5); //Das sur les individus
1377 return(101); //Nei sur les populations, Dm
1378 return(102); //Nei sur les populations, Ds
1379 return(103); //Cavalli-Sforza and Edwards' (1967), Dc
1380 return(104); // Nei et al's, Da (1983)
1381 return(106); // Goldstein et al., Mu (1995a), dmu2
1382 return(107); // Latter's Fst (1972)
1383 return(108); // Prevosti et al.'s, Cp (1975)
1384 return(109); // Rogers', Dr (1972)
1385 return(110); // Goldstein et al. (1995b) Slatkin 1995, ASD
1386 return(111); // Shriver et al's, Dsw (1995)
1387 return(112); // Lev A. Zhivotovsky, DR (1999)
1388 */
1389 tab_commandes.Suppr(pos);
1390 }
1391 cerr
1392 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) metdist : "
1393 << metdist << endl;
1394
1395 // Methode de construction d'arbre ? (Neigbhor Joining par d�faut)
1396 int metconstructarbre(2);
1397 pos = tab_commandes.Position("-construct");
1398 if ((pos > 0) && (pos + 1 != (long) tab_commandes.size())) {
1399 if (tab_commandes[pos + 1] == "upgma") {
1400 metconstructarbre = 1;
1401 tab_commandes.Suppr(pos + 1);
1402 tab_commandes.Suppr(pos);
1403 } else if (tab_commandes[pos + 1] == "nj") {
1404 metconstructarbre = 2;
1405 tab_commandes.Suppr(pos + 1);
1406 tab_commandes.Suppr(pos);
1407 }
1408 }
1409 cerr
1410 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) metconstructarbre : "
1411 << metconstructarbre << endl;
1412
1413 //nombre d'it�rations pour le bootstrap
1414 int nb_iterations(0);
1415
1416 // bootstrap locus ou bootstrap individus ? (bootstrap locus par d�faut)
1417 bool bootstrap_locus(true);
1418
1419 if (sur_pop) {
1420
1421 pos = tab_commandes.Position("-bootstrap_ind");
1422 if (pos > 0) {
1423 nb_iterations = 100;
1424 bootstrap_locus = false;
1425 if ((pos + 1 != (long) tab_commandes.size()) && (tab_commandes[pos
1426 + 1].EstUnChiffre())) {
1427 nb_iterations = tab_commandes[pos + 1];
1428 tab_commandes.Suppr(pos + 1);
1429 }
1430 tab_commandes.Suppr(pos);
1431 }
1432
1433 pos = tab_commandes.Position("-level");
1434 if (pos > 0) {
1435 _niveau = 100;
1436 if ((pos + 1 != (long) tab_commandes.size()) && (tab_commandes[pos
1437 + 1].EstUnChiffre())) {
1438 _niveau = tab_commandes[pos + 1];
1439 tab_commandes.Suppr(pos + 1);
1440 }
1441 tab_commandes.Suppr(pos);
1442 }
1443 } else {
1444 pos = tab_commandes.Position("-bootstrap_ind");
1445 if (pos > 0) {
1446 cerr
1447 << "ERROR: Populations is unable to bootstrap on individuals to make a phylogenetic tree of individuals"
1448 << endl;
1449 return;
1450 }
1451 }
1452
1453 pos = tab_commandes.Position("-bootstrap_locus");
1454 if (pos > 0) {
1455 nb_iterations = 100;
1456 if ((pos + 1 != (long) tab_commandes.size())
1457 && (tab_commandes[pos + 1].EstUnChiffre())) {
1458 nb_iterations = tab_commandes[pos + 1];
1459 tab_commandes.Suppr(pos + 1);
1460 }
1461 tab_commandes.Suppr(pos);
1462 }
1463 cerr
1464 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) bootstrap_locus : "
1465 << bootstrap_locus << endl;
1466 cerr
1467 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) nb_iterations : "
1468 << nb_iterations << endl;
1469
1470 //---------------------------------------------
1471 // Décryptage de la ligne de commande terminé
1472 // ----------------------------------------------
1473
1474 if (sur_pop) {
1475 //phylogenie sur les populations
1476 set_groupes_populations();
1477 larbre._titre.resize(2);
1478 larbre._titre[0].assign(""); // individus, populations
1479 larbre._titre[1].assign(""); // méthode de distance, nb bootstrap
1480
1481 larbre._titre[0].AjEntier(_Pjeupop->get_nbpop());
1482 larbre._titre[0] += " populations";
1483
1484 larbre._titre[1] += DistancesGnt::get_nom_methode(metdist);
1485
1486 if (nb_iterations == 0) {
1487 //pas de bootstrap
1488 // calcul de distance entre toutes les populations
1489 MatriceLD distances;
1490
1491 try {
1492 _Pjeupop->f_distgntpop(distances, metdist, _niveau);
1493 } catch (Jeupop::Anomalie pb) {
1494 cerr
1495 << "ApplPopulations::fLiPhylogeny(Titre & tab_commandes) ERROR: "
1496 << pb.le_pb << endl;
1497 return;
1498 }
1499 try {
1500 larbre.iDistances(distances, metconstructarbre);
1501 // larbre.fElimineTrifurcation();
1502 } catch (Arbre::Anomalie pb) {
1503 switch (pb.le_pb) {
1504 case 4:
1505 cout << _("Inconsistant matrix file format");
1506 break;
1507 case 5:
1508 cout << _("the matrix is too small");
1509 break;
1510 case 6:
1511 cout << _("Negative distances in the matrix");
1512 break;
1513 }
1514 return;
1515 }
1516 } else {
1517 larbre._titre[1] += ", ";
1518 larbre._titre[1].AjEntier(nb_iterations);
1519
1520 if (bootstrap_locus) {
1521 larbre._titre[1] += " bootstraps on locus";
1522 _Pjeupop->f_BootstrapLocus(larbre, metconstructarbre, metdist,
1523 _square_distance, nb_iterations, false);
1524 } else {
1525 larbre._titre[1] += " bootstraps on individuals";
1526 _Pjeupop->f_BootstrapIndividus(larbre, metconstructarbre,
1527 metdist, _square_distance, nb_iterations);
1528 }
1529
1530 // larbre.fElimineTrifurcation();
1531 }
1532 } else {
1533 //phylogenie sur les individus
1534 set_groupes_individus();
1535 larbre._titre.resize(2);
1536 larbre._titre[0].assign(""); // individus, populations
1537 larbre._titre[1].assign(""); // m�thode de distance, nb bootstrap
1538
1539 larbre._titre[0].AjEntier(_Pjeupop->get_nbind());
1540 larbre._titre[0] += " individuals";
1541
1542 cerr
1543 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) phylogeny on individuals "
1544 << endl;
1545
1546 larbre._titre[1] += DistancesGnt::get_nom_methode(metdist);
1547
1548 if (nb_iterations == 0) {
1549 //pas de bootstrap
1550 // calcul de distance entre tous les individus
1551 MatriceLD distances;
1552
1553 try {
1554
1555 cerr
1556 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) Pjeupop->f_distgnt(distances, metdist, _square_distance); "
1557 << endl;
1558 _Pjeupop->f_distgnt(distances, metdist, _square_distance);
1559 } catch (Jeupop::Anomalie pb) {
1560 cerr
1561 << "ApplPopulations::fLiPhylogeny(Titre & tab_commandes) ERROR: "
1562 << pb.le_pb << endl;
1563 return;
1564 }
1565
1566 try {
1567 cerr
1568 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) larbre.iDistances "
1569 << endl;
1570 larbre.iDistances(distances, metconstructarbre);
1571 // larbre.fElimineTrifurcation();
1572 cerr
1573 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) end larbre.iDistances "
1574 << endl;
1575 } catch (Arbre::Anomalie pb) {
1576 switch (pb.le_pb) {
1577 case 4:
1578 cout << _("Inconsistant matrix file format");
1579 break;
1580 case 5:
1581 cout << _("the matrix is too small");
1582 break;
1583 case 6:
1584 cout << _("Negative distances in the matrix");
1585 }
1586 }
1587 //return;
1588 } else {
1589 //bootstrap sur les locus
1590 larbre._titre[1] += ", ";
1591 larbre._titre[1].AjEntier(nb_iterations);
1592 larbre._titre[1] += " bootstraps on locus";
1593 _Pjeupop->f_BootstrapLocus(larbre, metconstructarbre, metdist,
1594 nb_iterations, true);
1595
1596 // larbre.fElimineTrifurcation();
1597 }
1598 }
1599
1600 cerr
1601 << "DEBUG ApplPopulations::fLiPhylogeny(Titre & tab_commandes) set_groupes_arbre(larbre); "
1602 << endl;
1603 set_groupes_arbre(larbre);
1604 larbre.oFichier(*Psortie);
1605 reset_groupes();
1606
1607 // *Psortie << larbre;
1608 // larbre.oFichier(*Psortie);
1609
1610 if (_sortie.is_open() != 0)
1611 _sortie.close();
1612
1613 }
1614
1615 void ApplPopulations::fLiHelp() const {
1616 cout << _("Online help missing") << endl;
1617 cout << _("Please visit our website :") << endl;
1618 cout << "http://www.bioinformatics.org/~tryphon/populations/" << endl;
1619 }
1620
1621 void ApplPopulations::fLiTest(Titre & tab_commandes) {
1622 cout << "test du jour" << endl;
1623 cout << "Copie d'objet Jeupop" << endl;
1624
1625 istream * Pentree(&cin);
1626 // ostream * Psortie(&cout);
1627
1628 // tab_commandes.Suppr(0);
1629
1630 //fichiers d'entree ou entree standard (par d�faut)
1631 _fichier.open("toutc2.txt", ios::in);
1632
1633 if (_fichier.is_open())
1634 Pentree = &_fichier;
1635 try {
1636 _Pjeupop = new Jeupop();
1637 *Pentree >> *(_Pjeupop);
1638 _fichier.close();
1639 _fichier.clear();
1640 } catch (Jeupop::Anomalie pb) {
1641 _fichier.close();
1642 _fichier.clear();
1643 delete _Pjeupop;
1644
1645 switch (pb.le_pb) {
1646 case 4:
1647 cerr << "Erreur de lecture..." << endl;
1648 return;
1649 break;
1650 }
1651 }
1652
1653 // _Pjeupop->oGenepop(cout);
1654 Jeupop copie(*_Pjeupop);
1655
1656 // copie.oGenepopCano(cout);
1657
1658 }
1659
1660 void ApplPopulations::affPubEntree() const {
1661
1662 cout << endl << endl;
1663 cout << "**********************************************************"
1664 << endl;
1665 cout << "* Populations " << version_populations
1666 << " *" << endl;
1667 cout << "* [email protected] *"
1668 << endl;
1669 cout << "* http://bioinformatics.org/project/?group_id=84 *"
1670 << endl;
1671 cout << "**********************************************************"
1672 << endl;
1673 cout << endl << endl;
1674
1675 // cout << log (10) << endl; //log n�perien
1676 }
1677
1678 /** Choix de locus */
1679 Vecteur<unsigned int> ApplPopulations::menu_choixlocus() const {
1680
1681 Vecteur<unsigned int> Vlocus;
1682 _Pjeupop->f_selectlocustous(Vlocus);
1683 signed int pos;
1684
1685 int choix(1);
1686 while (choix > 0) {
1687 cout << endl << endl;
1688 cout << _("Locus selection:") << endl;
1689 cout << "0) " << _("back") << endl;
1690 cout << "1) " << _("Select all loci (default)") << endl;
1691 cout << "2) " << _("Remove all loci") << endl;
1692 cout << "3) " << _("Add a particular locus") << endl;
1693 cout << "4) " << _("Remove a particular locus") << endl;
1694 cout << "5) " << _("Display selected loci") << endl;
1695
1696 choix = DemandeChoix(0, 5);
1697
1698 switch (choix) {
1699 case 0:
1700 return (Vlocus);
1701 break;
1702 case 1: // ajouter tous les locus
1703 _Pjeupop->f_selectlocustous(Vlocus);
1704 break;
1705 case 2: //enlever tous les locus
1706 Vlocus.resize(0);
1707 break;
1708 case 3: //ajouter un locus
1709 pos = DemandeLocus();
1710 if (pos != -1)
1711 Vlocus.push_back((unsigned int) pos);
1712 break;
1713 case 4: //enlever un locus
1714 pos = DemandeLocus();
1715 if (pos != -1) {
1716 pos = Vlocus.Position((unsigned int) pos);
1717 if (pos >= 0)
1718 Vlocus.Suppr(pos);
1719 }
1720 break;
1721 case 5: //affichage des locus selectionnes
1722 affVlocus(Vlocus);
1723 break;
1724 }
1725 }
1726 return (Vlocus);
1727 }
1728 /** */
1729 void ApplPopulations::affVlocus(const Vecteur<unsigned int> & Vlocus) const {
1730 unsigned int i;
1731
1732 cout << endl;
1733 for (i = 0; i < Vlocus.size(); i++)
1734 cout << _Pjeupop->get_nomlocus(Vlocus[i]) << " ";
1735 cout << endl;
1736 }
1737 /** Demande le nom ou le numero d'un locus */
1738 int ApplPopulations::DemandeLocus(const char laquestion[]) const {
1739 // float Application::DemandeReel(char laquestion[], float inf, float sup) const{
1740 biolib::vecteurs::ChaineCar rep;
1741 int nblocus(_Pjeupop->get_nbloc());
1742 int numlocus(-1);
1743
1744 if (laquestion == 0)
1745 cout << _("Name or number of the locus: ") << endl;
1746 else
1747 cout << laquestion << endl;
1748 cin >> rep;
1749
1750 numlocus = _Pjeupop->get_numloc(rep);
1751 if (numlocus == -1) {
1752 numlocus = rep;
1753 numlocus--;
1754 }
1755
1756 if ((numlocus < 0) || (numlocus >= nblocus)) {
1757 cerr << _("The locus ") << rep << _(" was not found") << endl;
1758 numlocus = -1;
1759 }
1760 return (numlocus);
1761 }
1762
1763 void ApplPopulations::ecritGenetix() {
1764 _nomFichier = DemandeFichier(_("Output file name (Genetix format) ?"));
1765
1766 try {
1767 _sortie.open(_nomFichier.c_str(), ios::out);
1768 JeuPopExp jeuaexporter(_Pjeupop);
1769
1770 jeuaexporter.oGenetix(_sortie, cerr);
1771
1772 _sortie.close();
1773 } catch (JeuPopExp::Anomalie pb) {
1774 _sortie.close();
1775 cerr << pb.fmessage(pb.le_pb) << endl;
1776 }
1777 }
1778
1779 void ApplPopulations::ecritFstat() {
1780 _nomFichier = DemandeFichier(_("Output file name (Fstat format) ?"));
1781
1782 try {
1783 _sortie.open(_nomFichier.c_str(), ios::out);
1784 JeuPopExp jeuaexporter(_Pjeupop);
1785
1786 jeuaexporter.oFstat(_sortie, cerr);
1787
1788 _sortie.close();
1789 } catch (JeuPopExp::Anomalie pb) {
1790 _sortie.close();
1791 cerr << pb.fmessage(pb.le_pb) << endl;
1792 }
1793 }
1794
1795 void ApplPopulations::ecritRapportFst() {
1796 cout << endl;
1797 cout << _("Fst, Fis and Fit computation") << endl;
1798 cout << "" << endl;
1799 JeuMatriceLD mat_resultat;
1800 _nomFichier = DemandeFichier(_("Output file name ?"));
1801
1802 cout << endl;
1803 cout << _("computing...") << endl;
1804 cout << "" << endl;
1805 Fstat lesfstats(_Pjeupop->get_Pracinepop());
1806 // lesfstats.f_affparlocus(cout);
1807 lesfstats.f_calcFstFisFit(mat_resultat);
1808
1809 ecritJeuMatriceLD(mat_resultat, _nomFichier);
1810
1811 }
1812
1813 void ApplPopulations::fmicrosatcorrections() {
1814 #ifdef XMLREADMICROSATCORRECTION_H
1815 while (_fichier.is_open() == 0) {
1816 cout << _("Name of the XML file containing corrections ?") << endl;
1817 cin >> _nomFichier;
1818
1819 _fichier.open(_nomFichier.c_str(), ios::in);
1820 _fichier.clear();
1821 }
1822
1823 try {
1824 XMLreadMicrosatCorrection parser(*_Pjeupop);
1825 parser.iParseFlux(_fichier);
1826 _fichier.close();
1827 }
1828 catch (XMLreadMicrosatCorrection::Anomalie pb) {
1829 _fichier.close();
1830 //throw Anomalie(1);
1831 }
1832
1833 #else
1834 cout << endl;
1835 cout << _("Sorry this version of Populations is unable to read XML files.")
1836 << endl;
1837 cout << _("Try the linux version.") << endl;
1838 cout << "" << endl;
1839 #endif
1840 }
1841
1842 void ApplPopulations::ecritPopulationsXML() {
1843 // cout << _("Output file name (Populations format) ?") << endl;
1844 // cin >> _nomFichier;
1845 _nomFichier = DemandeFichier(
1846 _("Output file name (XML Populations format) ?"));
1847
1848 try {
1849 _sortie.open(_nomFichier.c_str(), ios::out);
1850 JeuPopExp jeuaexporter(_Pjeupop);
1851
1852 jeuaexporter.oPopulationsXML(_sortie, cerr);
1853
1854 _sortie.close();
1855 } catch (JeuPopExp::Anomalie pb) {
1856 _sortie.close();
1857 cerr << pb.fmessage(pb.le_pb) << endl;
1858 }
1859 }