43 #include "../Model/SubstitutionModelSetTools.h"
62 alphabet_(modelSet_->getAlphabet()),
67 leaves_(tree_.getLeaves()),
70 nbClasses_(rate_->getNumberOfCategories()),
71 nbStates_(modelSet_->getNumberOfStates()),
72 continuousRates_(
false)
74 if (!modelSet->isFullySetUpFor(*tree))
75 throw Exception(
"NonHomogeneousSequenceSimulator(constructor). Model set is not fully specified.");
86 alphabet_(model->getAlphabet()),
91 leaves_(tree_.getLeaves()),
94 nbClasses_(rate_->getNumberOfCategories()),
95 nbStates_(model->getNumberOfStates()),
96 continuousRates_(false)
108 for (
size_t i = 0; i <
seqNames_.size(); i++)
113 vector<SNode*> nodes =
tree_.getNodes();
117 for (
size_t i = 0; i < nodes.size(); i++)
119 SNode* node = nodes[i];
126 VVdouble* cumpxy_node_c_ = &(*cumpxy_node_)[c];
131 Vdouble* cumpxy_node_c_x_ = &(*cumpxy_node_c_)[x];
132 cumpxy_node_c_x_->resize(nbStates_);
133 (*cumpxy_node_c_x_)[0] = P(x, 0);
136 (*cumpxy_node_c_x_)[y] = (*cumpxy_node_c_x_)[y - 1] + P(x, y);
147 int initialState = 0;
156 initialState =
static_cast<int>(i);
171 return simulate(initialState, rate);
178 return simulate(initialState, rateClass);
187 root->
getInfos().state = initialState;
194 for (
size_t i = 0; i <
leaves_.size(); i++)
196 site[i] =
leaves_[i]->getInfos().model->getAlphabetChar(
leaves_[i]->getInfos().state);
206 root->
getInfos().state = initialState;
213 for (
size_t i = 0; i <
leaves_.size(); i++)
215 site[i] =
leaves_[i]->getInfos().model->getAlphabetChar(
leaves_[i]->getInfos().state);
224 int initialState = 0;
233 initialState = (int)i;
238 return simulate(initialState, rate);
244 Vint initialStates(numberOfSites, 0);
245 for (
size_t j = 0; j < numberOfSites; j++)
255 initialStates[j] = (int)i;
264 for (
size_t j = 0; j < numberOfSites; j++)
277 vector<size_t> rateClasses(numberOfSites);
279 for (
size_t j = 0; j < numberOfSites; j++)
293 int initialState = 0;
302 initialState =
static_cast<int>(i);
322 return dSimulate(initialState, rateClass);
332 dEvolve(initialState, rate, *hssr);
346 int initialState = 0;
355 initialState =
static_cast<int>(i);
365 const Vdouble* cumpxy_node_c_x_ = &node->
getInfos().cumpxy[rateClass][initialState];
367 for (
int y = 0; y < static_cast<int>(
nbStates_); y++)
369 if (rand < (*cumpxy_node_c_x_)[y])
return y;
371 cerr <<
"DEBUG: This message should never happen! (HomogeneousSequenceSimulator::evolve)" << endl;
372 cout <<
" rand = " << rand << endl;
383 for (
int y = 0; y < static_cast<int>(
nbStates_); y++)
385 cumpxy += model->
Pij_t(initialState, y, l);
386 if (rand < cumpxy)
return y;
388 cerr <<
"DEBUG: This message should never happen! (NonHomogeneousSequenceSimulator::evolve)" << endl;
389 cout <<
" rand = " << rand << endl;
390 cout <<
"cumpxy = " << cumpxy << endl;
399 for (
size_t i = 0; i < initialStates.size(); i++)
401 const Vdouble* cumpxy_node_c_x_ = &(*cumpxy_node_)[rateClasses[i]][initialStates[i]];
405 if (rand < (*cumpxy_node_c_x_)[y])
407 finalStates[i] = (int)y;
419 cerr <<
"DEBUG: NonHomogeneousSequenceSimulator::evolveInternal. Forbidden call of method on root node." << endl;
434 cerr <<
"DEBUG: NonHomogeneousSequenceSimulator::evolveInternal. Forbidden call of method on root node." << endl;
449 cerr <<
"DEBUG: NonHomogeneousSequenceSimulator::multipleEvolveInternal. Forbidden call of method on root node." << endl;
452 const vector<int>* initialStates = &node->
getFather()->getInfos().states;
453 size_t n = initialStates->size();
467 root->
getInfos().states = initialStates;
475 size_t nbSites = initialStates.size();
477 for (
size_t i = 0; i < n; i++)
479 vector<int> content(nbSites);
480 vector<int>* states = &
leaves_[i]->getInfos().states;
481 model =
leaves_[i]->getInfos().model;
482 for (
size_t j = 0; j < nbSites; j++)
496 root->
getInfos().state = initialState;
508 cerr <<
"DEBUG: NonHomogeneousSequenceSimulator::evolveInternal. Forbidden call of method on root node." << endl;
513 node->
getInfos().state = mp.getFinalState();