38 for (
size_t i = 0; i < nProc.size(); ++i)
42 mProcess_[nProc[i]] = make_unique<SimpleSubstitutionProcessSiteSimulator>(sp);
44 vector<string> seqNames2;
46 vector<shared_ptr<PhyloNode>> vpn2 = sp->getParametrizablePhyloTree()->getAllLeaves();
47 for (
size_t i2 = 0; i2 < vpn2.size(); i2++)
49 seqNames2.push_back(vpn2[i2]->getName());
54 for (
size_t j = 0; j <
seqNames_.size(); j++)
57 throw Exception(
"SubstitutionProcessSequenceSimulator, unknown sequence name: " +
seqNames_[j]);
68 setMap(pse->getProcessNumbersPerSite());
71 throw Exception(
"SubstitutionProcessSequenceSimulator::SubstitutionProcessSequenceSimulator(SequenceEvolution) not set for this type of process. Ask developers.");
79 seqNames_(spss.seqNames_),
80 mvPosNames_(spss.mvPosNames_)
84 auto dit = std::dynamic_pointer_cast<SimpleSubstitutionProcessSiteSimulator>(it.second);
85 auto git = std::dynamic_pointer_cast<GivenDataSubstitutionProcessSiteSimulator>(it.second);
88 mProcess_[it.first] = std::make_shared<SimpleSubstitutionProcessSiteSimulator>(*dit);
90 mProcess_[it.first] = std::make_shared<GivenDataSubstitutionProcessSiteSimulator>(*git);
92 throw Exception(
"SubstitutionProcessSequenceSimulator::SubstitutionProcessSequenceSimulator: unknown type of site simulator.");
108 auto dit = std::dynamic_pointer_cast<SimpleSubstitutionProcessSiteSimulator>(it.second);
109 auto git = std::dynamic_pointer_cast<GivenDataSubstitutionProcessSiteSimulator>(it.second);
112 mProcess_[it.first] = std::make_shared<SimpleSubstitutionProcessSiteSimulator>(*dit);
114 mProcess_[it.first] = std::make_shared<GivenDataSubstitutionProcessSiteSimulator>(*git);
116 throw Exception(
"SubstitutionProcessSequenceSimulator::SubstitutionProcessSequenceSimulator: unknown type of site simulator.");
128 it.second->outputInternalSites(yn);
138 for (
size_t i = 0; i < vMap.size(); i++)
143 vMap_.push_back(vMap[i]);
150 size_t numberOfSites)
const
152 if (numberOfSites >
vMap_.size())
153 throw BadIntegerException(
"SubstitutionProcessSequenceSimulator::simulate. Too many sites to simulate.", (
int)numberOfSites);
156 sites->setSequenceNames(
seqNames_,
true);
160 for (
size_t j = 0; j < numberOfSites; ++j)
165 for (
size_t vn = 0; vn < vPosNames.size(); vn++)
167 vval[vn] = site->getValue(vPosNames[vn]);
170 auto site2 = make_unique<Site>(vval, sites->getAlphabet(),
static_cast<int>(j));
171 sites->addSite(site2);
179 const vector<double>& rates)
const
181 size_t numberOfSites = rates.size();
183 if (numberOfSites >
vMap_.size())
184 throw Exception(
"SubstitutionProcessSequenceSimulator::simulate : some sites do not have attributed process");
187 sites->setSequenceNames(
seqNames_,
true);
191 for (
size_t j = 0; j < numberOfSites; ++j)
193 auto site =
mProcess_.find(
vMap_[j])->second->simulateSite(rates[j]);
196 for (
size_t vn = 0; vn < vPosNames.size(); vn++)
198 vval[vn] = site->getValue(vPosNames[vn]);
201 auto site2 = make_unique<Site>(vval, sites->getAlphabet(),
static_cast<int>(j));
202 sites->addSite(site2);
210 const vector<size_t>& states)
const
212 size_t numberOfSites = states.size();
215 sites->setSequenceNames(
seqNames_,
true);
219 for (
size_t j = 0; j < numberOfSites; ++j)
221 auto site =
mProcess_.find(
vMap_[j])->second->simulateSite(states[j]);
224 for (
size_t vn = 0; vn < vPosNames.size(); vn++)
226 vval[vn] = site->getValue(vPosNames[vn]);
229 auto site2 = make_unique<Site>(vval, sites->getAlphabet(),
static_cast<int>(j));
230 sites->addSite(site2);
238 const vector<double>& rates,
239 const vector<size_t>& states)
const
241 size_t numberOfSites = rates.size();
242 if (states.size() != numberOfSites)
243 throw Exception(
"SubstitutionProcessSequenceSimulator::simulate, 'rates' and 'states' must have the same length.");
246 sites->setSequenceNames(
seqNames_,
true);
250 for (
size_t j = 0; j < numberOfSites; ++j)
252 auto site =
mProcess_.find(
vMap_[j])->second->simulateSite(states[j], rates[j]);
255 for (
size_t vn = 0; vn < vPosNames.size(); vn++)
257 vval[vn] = site->getValue(vPosNames[vn]);
260 auto site2 = make_unique<Site>(vval, sites->getAlphabet(),
static_cast<int>(j));
261 sites->addSite(site2);
273 return mProcess_.begin()->second->getAlphabet();
281 throw NullPointerException(
"SubstitutionProcessSequenceSimulator::alphabet(). No process attached.");
283 return mProcess_.begin()->second->alphabet();
Sequence evolution framework based on a mixture of substitution processes.
This interface describes the evolution process of a sequence.
virtual const std::vector< size_t > & getSubstitutionProcessNumbers() const =0
virtual const SubstitutionProcessInterface & substitutionProcess(size_t number) const =0
virtual std::shared_ptr< const SubstitutionProcessInterface > getSubstitutionProcess(size_t number) const =0
virtual std::shared_ptr< const ParametrizablePhyloTree > getParametrizablePhyloTree() const =0
Sequences simulation under position specific substitution process.
std::vector< std::string > seqNames_
all processes trees must have at least the same sequence names as the first process of the map.
void setMap(std::vector< size_t > vMap)
reset the set of processes.
std::shared_ptr< const Alphabet > getAlphabet() const override
SubstitutionProcessSequenceSimulator(const SequenceEvolution &evol)
const Alphabet & alphabet() const override
std::map< size_t, std::vector< size_t > > mvPosNames_
correspondence map of seqNames positions of the several trees. Reference is the tree of the first pro...
std::vector< size_t > vMap_
The vector of the site specific process in mProcess_; is mutable because can be changed for each simu...
SubstitutionProcessSequenceSimulator & operator=(const SubstitutionProcessSequenceSimulator &)
std::unique_ptr< SiteContainerInterface > simulate(size_t numberOfSites) const override
void outputInternalSequences(bool yn) override
Sets whether we will output the internal sequences or not.
std::map< size_t, std::shared_ptr< SiteSimulatorInterface > > mProcess_
the map of the process simulators.
std::string toString(T t)
Defines the basic types of data flow nodes.