Debian Codegraph @

src/applpop.cpp

raw
1 /***************************************************************************
2 applpop.cpp - Application dérivée de l'objet ApplPop
3 spécifique aux populations
4 -------------------
5 begin : ven aug 14 10:25:55 CEST 2000
6 copyright : (C) 2000 by Olivier Langella CNRS UPR9034
7 email : [email protected]
8 ***************************************************************************/
9
10 /***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19
20
21
22 //#include "entetepop.h"
23
24 #include "applpop.h"
25
26 ApplPop::ApplPop ():Application(){
27 //cerr << _formatMatrice;
28 _Pjeupop = 0;
29 _niveau = 100; // niveau de structuration des populations (100 => dernier ensemble avant les individus)
30 }
31
32 ApplPop::~ApplPop() {
33 if (_Pjeupop != 0) delete _Pjeupop;
34 }
35
36
37 /*
38 void ApplPop::fconcatenationpop() {
39 // concatenation de jeux de populations
40 Jeupop * PjeupopOriginal(_Pjeupop);
41
42 cout << endl << "Lecture des populations a concatener :" <<endl;
43
44 _Pjeupop = 0;
45 //cerr << "coucou" <<endl;
46 if (!litGenepop()) {
47 //cerr << "coucou" <<endl;
48 _Pjeupop = PjeupopOriginal;
49 //cerr << "coucou" <<endl;
50 return;
51 }
52
53 try {
54 //cerr << PjeupopOriginal->_commentaires[0];
55 //cerr << _Pjeupop->_commentaires[0];
56 //cerr << "concat avant" <<endl;
57 *_Pjeupop = *PjeupopOriginal + *_Pjeupop;
58 //cerr << "concat apres" <<endl;
59 //cerr << _Pjeupop->_commentaires.size(); //<< _Pjeupop->_commentaires[1];
60 }
61 catch (Jeupop::Anomalie pb) {
62 cout << endl << "il y a eu une erreur de type: " << pb.le_pb << endl;
63
64 _Pjeupop = PjeupopOriginal;
65 }
66 }
67 */
68
69
70
71 bool ApplPop::litGenepop() {
72 Jeupop * Poldjeupop;
73 bool ok(false);
74
75 while (_fichier.is_open() == 0) {
76 cout << _("Name of input file (Populations or Genepop format) ?") << endl;
77 cin >> _nomFichier;
78
79 _fichier.open(_nomFichier.c_str(), ios::in);
80 _fichier.clear();
81 }
82
83 try {
84 Poldjeupop = _Pjeupop;
85 //cerr << "ApplPop::litgenepop " <<endl;
86 _Pjeupop = new Jeupop();
87 //cerr << "ApplPop::litgenepop " <<endl;
88 _fichier >> *(_Pjeupop);
89 //cerr << "ApplPop::litgenepop fin >>" <<endl;
90 _fichier.close();
91 _fichier.clear();
92 ok = true;
93 }
94 catch (Jeupop::Anomalie pb){
95 _fichier.close();
96 _fichier.clear();
97 delete _Pjeupop;
98 _Pjeupop = Poldjeupop;
99 Poldjeupop = 0;
100 ok = false;
101
102 switch (pb.le_pb) {
103 case 4:
104 cout << _("The file format seems incorrect...") << endl;
105 break;
106 }
107 }
108
109 if (Poldjeupop != 0) delete Poldjeupop;
110 return(ok);
111 }
112
113
114
115 bool ApplPop::iPopulations() {
116
117 if (_Pjeupop == 0) {
118 if(litGenepop()) return(true);
119 else return(false);
120 }
121 return(true);
122 }
123
124
125 void ApplPop::affPubEntree() const {
126
127 cout << endl << endl;
128 cout << "**************************************" << endl;
129 cout << "* *" << endl;
130 cout << "* [email protected] *" << endl;
131 cout << "* http://www.cnrs-gif.fr/pge/bioinfo *" << endl;
132 cout << "**************************************" << endl;
133 cout << endl << endl;
134 }
135
136
137
138 /** Demande à l'utilisateur de choisir une population.
139 retourne le numéro dans _tabPpop */
140 unsigned long ApplPop::DemandePopulation(char laquestion[]) const{
141 signed long numpop(-1);
142 unsigned long i;
143 string rep;
144
145 while ((numpop < 0) || ((unsigned long) numpop > _Pjeupop->get_nbpop())) {
146 cout << _("Please, choose a population among these ones:") << endl;
147 for (i=0; i < _Pjeupop->get_nbpop(); i++) cout << _Pjeupop->get_nompop(i) << " ";
148 cout << endl;
149
150 cout << endl << laquestion << endl;
151 cin >> rep;
152 try {
153 numpop = _Pjeupop->get_numpop(_Pjeupop->get_Ppop(rep));
154 }
155 catch (Jeupop::Anomalie le_pb) {
156 cout << _("the population ") << rep << _(" has not been found.") << endl;
157 numpop = -1;
158 }
159 }
160 return ((unsigned long) numpop);
161
162 }
163
164 void ApplPop::set_groupes_individus() {
165 // crée des groupes d'individus par Populations
166 if (_Pjeupop == 0) return;
167 unsigned int nbpop, nbind, i, j;
168
169 //cerr << "ApplPop::set_groupes_individus() debut" << endl;
170 Titre noms_niveaux;
171
172 try {
173 //cerr << "ApplPop::set_groupes_individus() rempli" << endl;
174 _Pjeupop->f_rempliVcalcStrucPop(_niveau);
175 //cerr << "ApplPop::set_groupes_individus() noms" << endl;
176 //_Pjeupop->get_nomniveauxstruc(noms_niveaux);
177 }
178 catch (Jeupop::Anomalie pb) {
179 cerr << "ApplPop::set_groupes_individus() anomalie Jeupop " << pb.le_pb << endl;
180 }
181
182 nbpop = _Pjeupop->get_nbstrucpopVcalc();
183
184 _tab_groupes.resize(nbpop);
185 _tab_noms_groupes.resize(nbpop);
186 _tab_couleurs_groupes.resize(nbpop);
187
188 for (i = 0; i < nbpop; i++) {
189 _tab_noms_groupes[i] = _Pjeupop->get_PstrucpopVcalc(i)->get_nom();
190 _tab_couleurs_groupes[i] = _Pjeupop->get_PstrucpopVcalc(i)->get_couleur();
191
192 nbind = _Pjeupop->get_PstrucpopVcalc(i)->get_nbind();
193 _tab_groupes[i] = "";
194 for (j = 0; j < nbind; j++) {
195 _tab_groupes[i] += "'";
196 _tab_groupes[i] += _Pjeupop->get_PstrucpopVcalc(i)->get_nomind(j);
197 //cerr << "ApplPop::set_groupes_individus() get_nomind" << endl;
198 _tab_groupes[i] += "'";
199 //cerr << _tab_groupes[i] << endl;
200 //_tab_couleurs_groupes[i] = Couleur::get_couleur_diff();
201 if (j != (nbind -1)) _tab_groupes[i] += " ";
202
203 }
204 }
205 //cerr << "ApplPop::set_groupes_individus() fin";
206
207 }
208
209 void ApplPop::set_groupes_populations() {
210 // crée des groupes d'individus par Populations
211 if (_Pjeupop == 0) return;
212
213 unsigned int nbstrucpop, i,j;
214 reset_groupes();
215 MetaPop * Pmetapop;
216 Vecteur<MetaPop *> tabPmetapop;
217
218 _Pjeupop->f_rempliVcalcStrucPop(_niveau);
219
220 nbstrucpop = _Pjeupop->get_nbstrucpopVcalc();
221
222 //balayage des strucpop pour voir si il n'existe pas une métastructure
223 // => groupe de strucpop
224 for (i = 0; i < nbstrucpop; i++) {
225 if (_Pjeupop->get_PstrucpopVcalc(i)->get_niveau() < 2) {
226 //pas de metastructure
227 }
228 else {
229
230 Pmetapop = _Pjeupop->get_PstrucpopVcalc(i)->get_Pmetapop();
231
232 if (!(tabPmetapop.Existe(Pmetapop))) tabPmetapop.push_back(Pmetapop);
233 }
234 }
235
236 _tab_groupes.resize(tabPmetapop.size());
237 _tab_noms_groupes.resize(tabPmetapop.size());
238 _tab_couleurs_groupes.resize(tabPmetapop.size());
239
240 for (i = 0; i < tabPmetapop.size(); i++) {
241 _tab_noms_groupes[i] = tabPmetapop[i]->get_nom();
242 _tab_couleurs_groupes[i] = tabPmetapop[i]->get_couleur();
243
244 nbstrucpop = tabPmetapop[i]->get_nbpop();
245 _tab_groupes[i] = "";
246 for (j = 0; j < nbstrucpop; j++) {
247 _tab_groupes[i] += "'";
248 _tab_groupes[i] += tabPmetapop[i]->get_nompop(j);
249 //cerr << "ApplPop::set_groupes_individus() get_nomind" << endl;
250 _tab_groupes[i] += "'";
251 //cerr << _tab_groupes[i] << endl;
252 //_tab_couleurs_groupes[i] = Couleur::get_couleur_diff();
253 if (j != (nbstrucpop -1)) _tab_groupes[i] += " ";
254
255 }
256
257 }
258
259
260 }
261
262 void ApplPop::set_groupes_arbre(ArbrePlus & larbre) const {
263 // larbre._titre = _temp;
264 if (_tab_groupes.size() == 0) return;
265
266 unsigned int i, nbgroupes(_tab_groupes.size());
267
268 larbre.f_tri_ind_alpha();
269
270 for (i = 0; i < nbgroupes; i ++) {
271 larbre.ajouter_groupe(_tab_groupes[i], _tab_couleurs_groupes[i], _tab_noms_groupes[i]);
272 }
273 }