bpp-phyl3 3.0.0
SimpleSubstitutionProcessSiteSimulator.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_SIMULATION_SIMPLESUBSTITUTIONPROCESSSITESIMULATOR_H
6#define BPP_PHYL_SIMULATION_SIMPLESUBSTITUTIONPROCESSSITESIMULATOR_H
7
11
12#include "../Likelihood/ParametrizablePhyloTree.h"
13#include "../Model/SubstitutionModel.h"
15
16// From SeqLib:
17#include <Bpp/Seq/Site.h>
18
19// From the STL:
20#include <map>
21#include <vector>
22
23#include "../Likelihood/SubstitutionProcess.h"
24
25namespace bpp
26{
29{
30private:
31 // states during simulation
32 size_t state_;
33
34 // probabilities to choose, in case of mixture node or root, for all rates
36
37 // Sons in case of mixture node
38 std::vector<std::shared_ptr<SimProcessNode>> sons_;
39
40public:
43
46};
47
50{
51private:
52 // Cumulative pxy for all rates
54
55public:
58
61};
62
64
65
71{
72protected:
73 std::shared_ptr<const SubstitutionProcessInterface> process_;
74 std::shared_ptr<const ParametrizablePhyloTree> phyloTree_;
75
76
81
86
87 /*
88 * @brief cumsum probas of the root frequencies, one per rate class
89 * (this "per class" is useful for GivenDataSubstitutionProcessSiteSimulator)
90 */
92
96 std::vector<size_t> seqIndexes_;
97
101 std::vector<std::string> seqNames_;
102
107 mutable std::map<size_t, std::shared_ptr<SimProcessNode>> speciesNodes_;
108
109 size_t nbNodes_;
111 size_t nbStates_;
112
114
115 // Should we output internal sequences as well?
117
124public:
126 std::shared_ptr<const SubstitutionProcessInterface> process);
127
129
131 process_ (nhss.process_),
132 phyloTree_ (nhss.phyloTree_),
133 tree_ (nhss.tree_),
134 qRates_ (nhss.qRates_),
135 qRoots_ (nhss.qRoots_),
137 seqNames_ (nhss.seqNames_),
139 nbNodes_ (nhss.nbNodes_),
140 nbClasses_ (nhss.nbClasses_),
141 nbStates_ (nhss.nbStates_),
144 {}
145
147 {
148 process_ = nhss.process_;
149 phyloTree_ = nhss.phyloTree_;
150 tree_ = nhss.tree_;
151 qRates_ = nhss.qRates_;
152 qRoots_ = nhss.qRoots_;
154 seqNames_ = nhss.seqNames_;
156 nbNodes_ = nhss.nbNodes_;
157 nbClasses_ = nhss.nbClasses_;
158 nbStates_ = nhss.nbStates_;
161
162 return *this;
163 }
164
166 {
168 }
169
170private:
176 virtual void init();
177
178public:
185 std::unique_ptr<Site> simulateSite() const override;
186
187 std::unique_ptr<Site> simulateSite(size_t rateClass) const override;
188
189 std::unique_ptr<Site> simulateSite(double rate) const override;
190
191 std::unique_ptr<Site> simulateSite(size_t ancestralStateIndex, double rate) const override;
192
193 std::vector<std::string> getSequenceNames() const override
194 {
195 return seqNames_;
196 }
197
205 std::shared_ptr<const Alphabet> getAlphabet() const override { return process_->stateMap().getAlphabet(); }
206
207 const Alphabet& alphabet() const override { return process_->stateMap().alphabet(); }
216 std::unique_ptr<SiteSimulationResult> dSimulateSite() const override;
217
218 std::unique_ptr<SiteSimulationResult> dSimulateSite(size_t rateClass) const override;
219
220 std::unique_ptr<SiteSimulationResult> dSimulateSite(double rate) const override;
221
222 std::unique_ptr<SiteSimulationResult> dSimulateSite(size_t ancestralStateIndex, double rate) const override;
223
231 std::shared_ptr<const SubstitutionProcessInterface> getSubstitutionProcess() const
232 {
233 return process_;
234 }
235
241 std::shared_ptr<const ParametrizablePhyloTree> getTree() const
242 {
243 return phyloTree_;
244 }
245
258
265 void outputInternalSites(bool yn) override;
266
267protected:
277 void evolveInternal(
278 std::shared_ptr<SimProcessNode> node,
279 size_t rateClass, SiteSimulationResult* ssr = nullptr) const;
280
284 void evolveInternal(
285 std::shared_ptr<SimProcessNode> node,
286 double rate,
287 SiteSimulationResult* ssr = nullptr) const;
288
290};
291} // end of namespace bpp.
292#endif // BPP_PHYL_SIMULATION_SIMPLESUBSTITUTIONPROCESSSITESIMULATOR_H
This interface adds the dSimulate method to the SiteSimulator interface.
Site simulation under a unique substitution process, given data.
Tree Organization of Computing Nodes.
SimProcessEdge(const ProcessComputationEdge &pce)
std::vector< std::shared_ptr< SimProcessNode > > sons_
SimProcessNode(const ProcessComputationNode &pcn)
Site simulation under a unique substitution process.
std::shared_ptr< const ParametrizablePhyloTree > phyloTree_
std::shared_ptr< const SubstitutionProcessInterface > process_
void evolveInternal(std::shared_ptr< SimProcessNode > node, size_t rateClass, SiteSimulationResult *ssr=nullptr) const
SPTree tree_
To store states & transition probabilities of the simulator.
SimpleSubstitutionProcessSiteSimulator(std::shared_ptr< const SubstitutionProcessInterface > process)
SimpleSubstitutionProcessSiteSimulator & operator=(const SimpleSubstitutionProcessSiteSimulator &nhss)
std::shared_ptr< const SubstitutionProcessInterface > getSubstitutionProcess() const
Get the substitution process associated to this instance.
std::map< size_t, std::shared_ptr< SimProcessNode > > speciesNodes_
Map between species Indexes & used nodes, may change at each simulation.
std::shared_ptr< const ParametrizablePhyloTree > getTree() const
Get the tree associated to this instance.
std::vector< size_t > seqIndexes_
Vector of indexes of sequenced output species.
SimpleSubstitutionProcessSiteSimulator * clone() const override
void outputInternalSites(bool yn) override
Sets whether we will output the internal sequences or not.
std::vector< std::string > getSequenceNames() const override
std::vector< std::string > seqNames_
Vector of names of sequenced output species.
void enableContinuousRates(bool yn)
Enable the use of continuous rates instead of discrete rates.
SimpleSubstitutionProcessSiteSimulator(const SimpleSubstitutionProcessSiteSimulator &nhss)
std::unique_ptr< SiteSimulationResult > dSimulateSite() const override
Get a detailed simulation result for one site.
Vdouble qRates_
cumsum probas of the substitution rates
std::shared_ptr< const Alphabet > getAlphabet() const override
Data structure to store the result of a DetailedSiteSimulator.
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
std::vector< VVdouble > VVVdouble
std::vector< Vdouble > VVdouble
AssociationTreeGlobalGraphObserver< SimProcessNode, SimProcessEdge > SPTree