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 
17 namespace 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 {
34 public:
36 
37 private:
38  std::shared_ptr<const SubstitutionRegisterInterface> pReg_;
39 
44  std::shared_ptr<const AlphabetIndex2> weights_;
45 
50  std::shared_ptr<const AlphabetIndex2> distances_;
51 
52 protected:
53  std::unique_ptr<ProbabilisticSubstitutionMapping> counts_;
54  std::unique_ptr<ProbabilisticSubstitutionMapping> factors_;
55 
56 private:
61 
67  std::map<size_t, std::vector<uint>> mModBrid_;
68 
69 public:
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 
157  const ProbabilisticSubstitutionMapping& counts() const override
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(size_t index) const override
Get the model with a ginev index.
void setDistances(const AlphabetIndex2 &ndist) override
change Distances
std::shared_ptr< const SubstitutionRegisterInterface > pReg_
AbstractSinglePhyloSubstitutionMapping(std::shared_ptr< TreeGlobalGraph > graph, std::shared_ptr< const SubstitutionRegisterInterface > reg, std::shared_ptr< const AlphabetIndex2 > weights, std::shared_ptr< const AlphabetIndex2 > distances)
const ParameterList & getParameters() const override
Gets the parameters.
const ProbabilisticSubstitutionMapping & normalizations() const override
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 AlphabetIndex2 > getWeights() const
std::shared_ptr< TransitionModelInterface > getModelForBranch(uint branchId) override
From BranchedModelSet.
bool matchParametersValues(const ParameterList &nullParams) override
Checks and sets the models with given parameters.
const ProbabilisticSubstitutionMapping & counts() const override
std::shared_ptr< const SubstitutionRegisterInterface > getSubstitutionRegister() const
ProbabilisticSubstitutionMapping & normalizations() override
Return the tree of factors.
std::shared_ptr< const TransitionModelInterface > getModelForBranch(uint branchId) const override
ProbabilisticSubstitutionMapping & counts() override
Return the tree of counts.
std::shared_ptr< const AlphabetIndex2 > getDistances() const
AssociationTreeGlobalGraphObserver< uint, ModelBranch > modelTree
bool normalizationsPerformed() const override
From PhyloSubstitutionMapping.
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.
std::shared_ptr< TransitionModelInterface > getModel(size_t index)
void setSubstitutionRegister(std::shared_ptr< const SubstitutionRegisterInterface > reg)
For registers.
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_
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.
const SubstitutionRegisterInterface & substitutionRegister() const
std::unique_ptr< ProbabilisticSubstitutionMapping > factors_
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_