SiteContainer* SequenceSimulationTools::simulateSites(const SiteSimulator& simulator, const vector<double>& rates) { size_t numberOfSites = rates.size(); vector<const Site*> vs(numberOfSites); for (size_t i = 0; i < numberOfSites; i++) { Site* s = simulator.simulateSite(rates[i]); s->setPosition(static_cast<int>(i)); vs[i] = s; } SiteContainer* sites = new VectorSiteContainer(vs, simulator.getAlphabet()); sites->setSequencesNames(simulator.getSequencesNames(), false); // Freeing memory: for (size_t i = 0; i < numberOfSites; i++) { delete vs[i]; } return sites; }
SiteContainer* SequenceSimulationTools::simulateSites(const SiteSimulator& simulator, const vector<double>& rates, const vector<size_t>& states) throw (Exception) { size_t numberOfSites = rates.size(); if (states.size() != numberOfSites) throw Exception("SequenceSimulationTools::simulateSites., 'rates' and 'states' must have the same length."); vector<const Site*> vs(numberOfSites); for (size_t i = 0; i < numberOfSites; i++) { Site* s = simulator.simulateSite(states[i], rates[i]); s->setPosition(static_cast<int>(i)); vs[i] = s; } SiteContainer* sites = new VectorSiteContainer(vs, simulator.getAlphabet()); sites->setSequencesNames(simulator.getSequencesNames(), false); // Freeing memory: for (size_t i = 0; i < numberOfSites; i++) { delete vs[i]; } return sites; }