bpp-phyl3 3.0.0
RateAcrossSitesSubstitutionProcess.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_LIKELIHOOD_RATEACROSSSITESSUBSTITUTIONPROCESS_H
6#define BPP_PHYL_LIKELIHOOD_RATEACROSSSITESSUBSTITUTIONPROCESS_H
7
8
10
11// From bpp-core:
13
14// From the stl:
15#include <memory>
16
17namespace bpp
18{
21{
22private:
23 std::shared_ptr<BranchModelInterface> model_;
24 std::shared_ptr<DiscreteDistributionInterface> rDist_;
25
26public:
28 std::shared_ptr<BranchModelInterface> model,
29 std::shared_ptr<DiscreteDistributionInterface> rdist,
30 std::shared_ptr<const PhyloTree> tree = nullptr,
31 std::shared_ptr<FrequencySetInterface> rootFrequencies = nullptr);
32
34 std::shared_ptr<BranchModelInterface> model,
35 std::shared_ptr<DiscreteDistributionInterface> rdist,
36 std::shared_ptr<ParametrizablePhyloTree> tree,
37 std::shared_ptr<FrequencySetInterface> rootFrequencies = nullptr);
38
40
42
43public:
45 {
46 return new RateAcrossSitesSubstitutionProcess(*this);
47 }
48
49 size_t getNumberOfModels() const override { return 1; }
50
51 std::vector<size_t> getModelNumbers() const override
52 {
53 return std::vector<size_t>(1, 1);
54 }
55
56 const StateMapInterface& stateMap() const override
57 {
58 return model_->stateMap();
59 }
60
61 std::shared_ptr<const StateMapInterface> getStateMap() const override
62 {
63 return model_->getStateMap();
64 }
65
66 const BranchModelInterface& model(size_t n) const override
67 {
68 return *model_;
69 }
70
71 std::shared_ptr<const BranchModelInterface> getModel(size_t n) const override
72 {
73 return model_;
74 }
75
76 const BranchModelInterface& model(unsigned int nodeId, size_t classIndex) const override
77 {
78 return *model_;
79 }
80
81 std::shared_ptr<const BranchModelInterface> getModel(unsigned int nodeId, size_t classIndex) const override
82 {
83 return model_;
84 }
85
86 const std::vector<unsigned int> getNodesWithModel(size_t i) const override
87 {
88 throw Exception("RateAcrossSitesSubstitutionProcess::getNodesWithModel not finished. Ask developers.");
89 return Vuint(0);
90 }
91
92 size_t getModelNumberForNode(unsigned int nodeId) const override
93 {
94 return 1;
95 }
96
97 std::shared_ptr<const BranchModelInterface> getModelForNode(unsigned int nodeId) const override
98 {
99 return model_;
100 }
101
103 {
104 if (!rDist_)
105 throw NullPointerException("RateAcrossSitesSubstitutionProcess::rateDistribution. No associated rate distribution.");
106 return *rDist_;
107 }
108
110 {
111 if (!rDist_)
112 throw NullPointerException("RateAcrossSitesSubstitutionProcess::rateDistribution. No associated rate distribution.");
113 return *rDist_;
114 }
115
116 std::shared_ptr<const DiscreteDistributionInterface> getRateDistribution() const override
117 {
118 return rDist_;
119 }
120
121 std::shared_ptr<DiscreteDistributionInterface> getRateDistribution() override
122 {
123 return rDist_;
124 }
125
126 ParameterList getSubstitutionModelParameters(bool independent) const override
127 {
128 return independent ? model_->getIndependentParameters() : model_->getParameters();
129 }
130
131 ParameterList getRateDistributionParameters(bool independent) const override
132 {
133 return independent ? rDist_->getIndependentParameters() : rDist_->getParameters();
134 }
135
136 ParameterList getBranchLengthParameters(bool independent) const override
137 {
139 return getParametrizablePhyloTree()->getParameters();
140 else
141 return ParameterList();
142 }
143
144 const std::vector<double>& getRootFrequencies() const override
145 {
146 if (!hasRootFrequencySet())
147 {
148 if (std::dynamic_pointer_cast<const TransitionModelInterface>(model_))
149 return std::dynamic_pointer_cast<const TransitionModelInterface>(model_)->getFrequencies();
150 else
151 throw Exception("SimpleSubstitutionProcess::getRootFrequencies not possible with a non Transition Model.");
152 }
153 else
154 return getRootFrequencySet()->getFrequencies();
155 }
156
163 void setModelScenario(std::shared_ptr<ModelScenario> modelpath) override;
164
165 double getProbabilityForModel(size_t classIndex) const override
166 {
167 if (classIndex >= rDist_->getNumberOfCategories())
168 throw IndexOutOfBoundsException("RateAcrossSitesSubstitutionProcess::getProbabilityForModel.", classIndex, 0, rDist_->getNumberOfCategories());
169 return rDist_->getProbability(classIndex);
170 }
171
173 {
174 Vdouble vProb;
175
176 for (size_t i = 0; i < rDist_->getNumberOfCategories(); ++i)
177 {
178 vProb.push_back(rDist_->getProbability(i));
179 }
180
181 return vProb;
182 }
183
184 double getRateForModel(size_t classIndex) const override
185 {
186 if (classIndex >= rDist_->getNumberOfCategories())
187 throw IndexOutOfBoundsException("RateAcrossSitesSubstitutionProcess::getRateForModel.", classIndex, 0, rDist_->getNumberOfCategories());
188 return rDist_->getCategory(classIndex);
189 }
190
191protected:
192 void fireParameterChanged(const ParameterList& pl) override; // Forward parameters and updates probabilities if needed.
193};
194} // end namespace bpp
195#endif // BPP_PHYL_LIKELIHOOD_RATEACROSSSITESSUBSTITUTIONPROCESS_H
A partial implementation of the SubstitutionProcess interface.
std::shared_ptr< const ParametrizablePhyloTree > getParametrizablePhyloTree() const
std::shared_ptr< const FrequencySetInterface > getRootFrequencySet() const
Interface for all Branch models.
std::shared_ptr< const DiscreteDistributionInterface > getRateDistribution() const override
Get a pointer to the rate distribution (or null if there is no rate distribution).
void setModelScenario(std::shared_ptr< ModelScenario > modelpath) override
Set the modelPath, after checking it is valid (ie modelpath has only the model of the process).
const BranchModelInterface & model(size_t n) const override
RateAcrossSitesSubstitutionProcess & operator=(const RateAcrossSitesSubstitutionProcess &rassp)
const DiscreteDistributionInterface & rateDistribution() const override
Get the rate distribution.
void fireParameterChanged(const ParameterList &pl) override
AbsractParametrizable interface.
std::shared_ptr< const BranchModelInterface > getModel(unsigned int nodeId, size_t classIndex) const override
Get the substitution model corresponding to a certain branch, site pattern, and model class.
std::vector< size_t > getModelNumbers() const override
DiscreteDistributionInterface & rateDistribution() override
Get the rate distribution.
std::shared_ptr< DiscreteDistributionInterface > getRateDistribution() override
Get a pointer to the rate distribution (or null if there is no rate distribution).
std::shared_ptr< DiscreteDistributionInterface > rDist_
double getProbabilityForModel(size_t classIndex) const override
std::shared_ptr< BranchModelInterface > model_
ParameterList getBranchLengthParameters(bool independent) const override
std::shared_ptr< const BranchModelInterface > getModelForNode(unsigned int nodeId) const override
Get the model associated to a particular node id.
RateAcrossSitesSubstitutionProcess * clone() const override
std::shared_ptr< const StateMapInterface > getStateMap() const override
const BranchModelInterface & model(unsigned int nodeId, size_t classIndex) const override
Get the substitution model corresponding to a certain branch, site pattern, and model class.
std::shared_ptr< const BranchModelInterface > getModel(size_t n) const override
ParameterList getSubstitutionModelParameters(bool independent) const override
Methods to retrieve the parameters of specific objects.
const std::vector< unsigned int > getNodesWithModel(size_t i) const override
Get a list of nodes id for which the given model is associated.
const std::vector< double > & getRootFrequencies() const override
Get the values of the frequencies for each state in the alphabet at the root node.
RateAcrossSitesSubstitutionProcess(std::shared_ptr< BranchModelInterface > model, std::shared_ptr< DiscreteDistributionInterface > rdist, std::shared_ptr< const PhyloTree > tree=nullptr, std::shared_ptr< FrequencySetInterface > rootFrequencies=nullptr)
size_t getModelNumberForNode(unsigned int nodeId) const override
Get the number of the model associated to a particular node id.
const StateMapInterface & stateMap() const override
double getRateForModel(size_t classIndex) const override
ParameterList getRateDistributionParameters(bool independent) const override
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:25
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
std::vector< unsigned int > Vuint