bpp-phyl3 3.0.0
AbstractSinglePhyloSubstitutionMapping.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_MAPPING_PHYLOMAPPINGS_ABSTRACTSINGLEPHYLOSUBSTITUTIONMAPPING_H
6#define BPP_PHYL_MAPPING_PHYLOMAPPINGS_ABSTRACTSINGLEPHYLOSUBSTITUTIONMAPPING_H
7
11
12#include "../../Tree/PhyloTree.h"
13#include "../BranchedModelSet.h"
14#include "../ProbabilisticSubstitutionMapping.h"
16
17namespace bpp
18{
20{
21 std::shared_ptr<TransitionModelInterface> pMod_;
22};
23
24
30 virtual public BranchedModelSet,
31 virtual public PhyloSubstitutionMapping,
32 public AssociationTreeGlobalGraphObserver<uint, ModelBranch>
33{
34public:
36
37private:
38 std::shared_ptr<const SubstitutionRegisterInterface> pReg_;
39
44 std::shared_ptr<const AlphabetIndex2> weights_;
45
50 std::shared_ptr<const AlphabetIndex2> distances_;
51
52protected:
53 std::unique_ptr<ProbabilisticSubstitutionMapping> counts_;
54 std::unique_ptr<ProbabilisticSubstitutionMapping> factors_;
55
56private:
61
67 std::map<size_t, std::vector<uint>> mModBrid_;
68
69public:
71 std::shared_ptr<TreeGlobalGraph> graph,
72 std::shared_ptr<const SubstitutionRegisterInterface> reg,
73 std::shared_ptr<const AlphabetIndex2> weights,
74 std::shared_ptr<const AlphabetIndex2> distances) :
75 modelTree(graph), pReg_(reg), weights_(weights), distances_(distances), counts_(), factors_(), modelColl_(), mModBrid_()
76 {}
77
79
81
83
89 std::shared_ptr<TransitionModelInterface> getModelForBranch(uint branchId) override
90 {
91 return (*getEdge(branchId)).pMod_;
92 }
93
94 std::shared_ptr<const TransitionModelInterface> getModelForBranch(uint branchId) const override
95 {
96 return (*getEdge(branchId)).pMod_;
97 }
98
99 std::shared_ptr<const TransitionModelInterface> getModel(unsigned int branchId, size_t classIndex) const override
100 {
101 return (*getEdge(branchId)).pMod_;
102 }
103
104 std::shared_ptr<TransitionModelInterface> getModel(size_t index)
105 {
106 return modelColl_[index];
107 }
108
109 std::shared_ptr<const TransitionModelInterface> getModel(size_t index) const override
110 {
111 return modelColl_[index];
112 }
113
114 std::vector<uint> getBranchesWithModel(size_t index) const override
115 {
116 return mModBrid_.at(index);
117 }
118
132 bool normalizationsPerformed() const override
133 {
134 return factors_ != 0;
135 }
136
138 {
139 return *factors_;
140 }
141
143 {
144 return *factors_;
145 }
146
147 bool countsPerformed() const override
148 {
149 return counts_ != 0;
150 }
151
153 {
154 return *counts_;
155 }
156
158 {
159 return *counts_;
160 }
161
162
166 void setSubstitutionRegister(std::shared_ptr<const SubstitutionRegisterInterface> reg)
167 {
168 pReg_ = reg;
169 }
170
172 {
173 return *pReg_;
174 }
175
176 std::shared_ptr<const SubstitutionRegisterInterface> getSubstitutionRegister() const
177 {
178 return pReg_;
179 }
180
181 bool matchParametersValues(const ParameterList& nullParams) override
182 {
183 return modelColl_.matchParametersValues(nullParams);
184 }
185
186 const ParameterList& getParameters() const override
187 {
188 return modelColl_.getParameters();
189 }
190
191 std::shared_ptr<const AlphabetIndex2> getWeights() const
192 {
193 return weights_;
194 }
195
196 std::shared_ptr<const AlphabetIndex2> getDistances() const
197 {
198 return distances_;
199 }
200
209 void addModel(size_t index, const TransitionModelInterface& model, Vuint brIds);
210
211 /*
212 * @brief change Distances
213 *
214 * BEWARE: counts are not updated automatically
215 */
216 void setDistances(const AlphabetIndex2& ndist) override
217 {
218 distances_.reset(ndist.clone());
219 }
220};
221} // end of namespace bpp.
222#endif // BPP_PHYL_MAPPING_PHYLOMAPPINGS_ABSTRACTSINGLEPHYLOSUBSTITUTIONMAPPING_H
The AbstractSinglePhyloSubstitutionMapping class: substitution mapping linked with a Single Process P...
std::shared_ptr< const TransitionModelInterface > getModel(unsigned int branchId, size_t classIndex) const override
Get the substitution model corresponding to a certain branch and model class.
std::shared_ptr< TransitionModelInterface > getModelForBranch(uint branchId) override
From BranchedModelSet.
void setDistances(const AlphabetIndex2 &ndist) override
change Distances
std::shared_ptr< const SubstitutionRegisterInterface > pReg_
std::shared_ptr< TransitionModelInterface > getModel(size_t index)
AbstractSinglePhyloSubstitutionMapping(std::shared_ptr< TreeGlobalGraph > graph, std::shared_ptr< const SubstitutionRegisterInterface > reg, std::shared_ptr< const AlphabetIndex2 > weights, std::shared_ptr< const AlphabetIndex2 > distances)
ProbabilisticSubstitutionMapping & counts() override
Return the tree of counts.
AbstractSinglePhyloSubstitutionMapping & operator=(const AbstractSinglePhyloSubstitutionMapping &sppm)
std::vector< uint > getBranchesWithModel(size_t index) const override
Get a list of branches id for which the given model is associated.
std::shared_ptr< const AlphabetIndex2 > distances_
distances of the substitutions. If null, no distances are used.
std::shared_ptr< const TransitionModelInterface > getModel(size_t index) const override
Get the model with a ginev index.
const SubstitutionRegisterInterface & substitutionRegister() const
std::shared_ptr< const SubstitutionRegisterInterface > getSubstitutionRegister() const
bool matchParametersValues(const ParameterList &nullParams) override
Checks and sets the models with given parameters.
std::shared_ptr< const AlphabetIndex2 > getWeights() const
const ProbabilisticSubstitutionMapping & normalizations() const override
AssociationTreeGlobalGraphObserver< uint, ModelBranch > modelTree
bool normalizationsPerformed() const override
From PhyloSubstitutionMapping.
const ParameterList & getParameters() const override
Gets the parameters.
const ProbabilisticSubstitutionMapping & counts() const override
std::shared_ptr< const AlphabetIndex2 > weights_
weights of the substitutions. If null, no weights are used.
void addModel(size_t index, const TransitionModelInterface &model, Vuint brIds)
add a Substitution Model in the map, and on all branches with given Ids.
void setSubstitutionRegister(std::shared_ptr< const SubstitutionRegisterInterface > reg)
For registers.
std::shared_ptr< const TransitionModelInterface > getModelForBranch(uint branchId) const override
ParametrizableCollection< TransitionModelInterface > modelColl_
A collection of Transition Models.
bool countsPerformed() const override
return if counts have been performed.
std::map< size_t, std::vector< uint > > mModBrid_
a map <model index, vector of branch ids>
std::unique_ptr< ProbabilisticSubstitutionMapping > counts_
ProbabilisticSubstitutionMapping & normalizations() override
Return the tree of factors.
std::unique_ptr< ProbabilisticSubstitutionMapping > factors_
std::shared_ptr< const AlphabetIndex2 > getDistances() const
virtual AlphabetIndex2 * clone() const=0
virtual std::shared_ptr< E > getEdge(EdgeIndex edgeIndex) const=0
Data storage class for probabilistic substitution mappings.
The SubstitutionRegister interface.
Interface for all transition models.
Defines the basic types of data flow nodes.
std::vector< unsigned int > Vuint
std::shared_ptr< TransitionModelInterface > pMod_