Debian Codegraph @

src/arbreplus.cpp

raw
1 /***************************************************************************
2 arbreplus.cpp - description
3 -------------------
4 begin : Mon Jun 4 2001
5 copyright : (C) 2001 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 "arbreplus.h"
19
20 namespace biolib {
21 namespace arbres {
22
23 ArbrePlGroupes::ArbrePlGroupes(const ArbrePlus * Parbre): _Parbre(Parbre) {
24 }
25 ArbrePlGroupes::~ArbrePlGroupes(){
26 // while (size() > 0) delete back();
27 }
28
29 ArbrePlus::ArbrePlus(): _tabGroupes(this), _couleur_neutre(0,0,0){
30 }
31 ArbrePlus::~ArbrePlus(){
32 }
33
34
35 void ArbrePlGroupes::push_back_groupe(const string & nom, const string & couleur) {
36 // push_back(new ArbreVectUINT());
37 ArbreVectUINT nouveau;
38
39 push_back(nouveau);
40
41 _tabNom.push_back(nom);
42 _tabCouleur.push_back(Couleur(couleur));
43
44 }
45
46 int ArbrePlGroupes::RechercheGroupeOTU(unsigned int id) const {
47
48 unsigned int i;
49
50 for (i=0 ; i < size(); i++) {
51 if (operator[](i).Existe(id)) return(i);
52 }
53 return (-1);
54 }
55
56
57 void ArbrePlus::define_outgroup(const ChaineCar & outgroup){
58 unsigned int nbmots,i;
59 int pos(-1);
60 string mot;
61
62 if (outgroup == "") return;
63 nbmots = outgroup.GetNbMots();
64 _Vind_outgroup.resize(0);
65 for (i = 0; i < nbmots; i++) {
66 outgroup.GetMot(i+1, mot);
67 pos = PositionInd(mot.c_str());
68 if (pos == -1) {
69 cerr << "Erreur TreePlotter::define_outgroup" << endl;
70 cerr << mot << _(" was not found") << endl ;
71 return;
72 }
73 //cerr << "TreePlotter::define_outgroup pos" << pos << endl;
74 _Vind_outgroup.push_back(_tabPind[pos]->get_id());
75 }
76
77 //Recherche du noeud contenant une branche avec _Vind_outgroup
78 // => charger les "vecteurs d'individus" de l'arbre
79 //cerr << "TreePlotter::define_outgroup" << endl;
80 _Vind_outgroup.f_tri();
81 f_load_vect_id_ind();
82 //cerr << RechercheNoeud(_Vind_outgroup) << endl;
83 set_Pracine(RechercheNoeud(_Vind_outgroup));
84 //cerr << "TreePlotter::define_outgroup fin"<< endl;
85 }
86
87 void ArbrePlus::ajouter_groupe(const ChaineCar & groupe, const string & couleur, const string & nom){
88 unsigned int nbmots,i;
89 signed int pos(-1);
90 ChaineCar mot;
91 //cerr << "ArbrePlus::ajouter_groupe " << groupe << endl;
92 // Couleur bidon("");
93
94 // if (lacouleur == "") lacouleur.assign(bidon.get_couleur_diff());
95
96 _tabGroupes.push_back_groupe(nom, couleur);
97 //cerr << "TreePlotter::define_outgroup groupes " << groupe << endl;
98
99 if (groupe == "") return;
100 nbmots = groupe.GetNbMots();
101 _tabGroupes.back().resize(0);
102 for (i = 0; i < nbmots; i++) {
103 groupe.GetMot(i+1, mot);
104 pos = (int) mot;
105 if (((mot.EstUnChiffre()) && (pos > 0) && ((unsigned int) pos < _tabPind.size())) || (mot == "0")){
106 //cerr << "ArbrePlus::ajouter_groupe [" << mot << endl;
107 if ((mot == "0") && (_tabPind.size() == 1)) _tabGroupes.back().push_back(0);
108 else _tabGroupes.back().push_back(pos);
109 }
110 else {
111 pos = PositionInd(mot.c_str());
112 //cerr << "TreePlotter::define_outgroup pos" << pos << endl;
113 if (pos == -1) {
114 cerr << "Erreur" << endl;
115 cerr << mot << _(" was not found") << endl ;
116 }
117 else if ((unsigned int) pos < _tabPind.size()) _tabGroupes.back().push_back(_tabPind[pos]->get_id());
118 }
119 }
120
121 //Recherche du noeud contenant une branche avec _Vind_outgroup
122 // => charger les "vecteurs d'individus" de l'arbre
123 //cerr << "TreePlotter::define_outgroup" << endl;
124 _tabGroupes.back().f_tri();
125 }
126
127 const Couleur & ArbrePlus::get_couleur_otu (unsigned int id) const {
128 int numgroupe(_tabGroupes.RechercheGroupeOTU(id));
129
130 if (numgroupe == -1) return(get_couleur_neutre());
131 else return(_tabGroupes.get_couleur((unsigned int)numgroupe));
132 }
133
134 void ArbrePlus::iPhylipDefGroupe(const string & ligne) {
135 //définition d'un groupe (lecture de fichier Phylip
136 //#G nom couleur 'groupe'
137 Titre tabArguments;
138 cerr << "ArbrePlus::iPhylipDefGroupe(const string & ligne)" << ligne << endl;
139 tabArguments.GetArguments(ligne);
140 cerr << tabArguments[1] << endl;
141 cerr << tabArguments[2] << endl;
142 cerr << tabArguments[3] << endl;
143
144 if (tabArguments.size() == 4) ajouter_groupe(tabArguments[3], tabArguments[2], tabArguments[1]);
145 else if (tabArguments.size() == 3) ajouter_groupe(tabArguments[2], tabArguments[1], "");
146
147 }
148
149 void ArbrePlus::oPhylipEcritGroupes(ostream & fichier) const {
150 //ecrit les groupes au format phylip traffiqué Olivier:
151 // #G Couleur 'pop1 pop2 ...popn'
152 // dans le fichier
153 unsigned int i,j;
154 if (_tabGroupes.size() == 0) return;
155
156 if (_titre.size() == 0) fichier << "[";
157 else fichier << "\\";
158
159 for (i = 0; i < _tabGroupes.size(); i++) {
160 fichier << "#G '" << _tabGroupes.get_nom(i) << "' '" << _tabGroupes.get_couleur(i).get_nom() << "' '";
161
162 for (j=0; j < _tabGroupes[i].size(); j++) {
163 fichier << _tabGroupes[i][j];
164
165 if (j != (_tabGroupes[i].size()-1)) fichier << " ";
166 }
167 fichier << "'";
168 if (i != (_tabGroupes.size()-1)) fichier << "\\";
169 }
170 if (_titre.size() == 0) fichier << "]" << endl;
171 }
172
173 } //namespace biolib {
174 } //namespace arbres {
175