bpp-phyl3  3.0.0
MixtureOfSubstitutionModels.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_MODEL_MIXTUREOFSUBSTITUTIONMODELS_H
6 #define BPP_PHYL_MODEL_MIXTUREOFSUBSTITUTIONMODELS_H
7 
9 #include <cstring> // C lib for string copy
10 #include <map>
11 #include <string>
12 #include <vector>
13 
15 
16 namespace bpp
17 {
20 {
21 public:
32  std::shared_ptr<const Alphabet> alpha,
33  std::vector< std::unique_ptr<TransitionModelInterface>>& vpModel) :
34  AbstractParameterAliasable("Mixture."),
35  AbstractTransitionModel(alpha, vpModel.size() ? vpModel[0]->getStateMap() : 0, "Mixture."),
36  MixtureOfTransitionModels(alpha, vpModel)
37  {
38  // Check that all models are substitutionmodels
39  for (const auto& model : modelsContainer_)
40  {
41  if (!dynamic_cast<const SubstitutionModelInterface*>(model.get()))
42  throw Exception("MixtureOfSubstitutionModels can only be built with SubstitutionModels, not " + model->getName());
43  }
44  }
45 
60  std::shared_ptr<const Alphabet> alpha,
61  std::vector< std::unique_ptr<TransitionModelInterface>>& vpModel,
62  Vdouble& vproba, Vdouble& vrate) :
63  AbstractParameterAliasable("Mixture."),
64  AbstractTransitionModel(alpha, vpModel.size() ? vpModel[0]->getStateMap() : 0, "Mixture."),
65  MixtureOfTransitionModels(alpha, vpModel, vproba, vrate)
66  {
67  /*
68  * Check that all models are substitutionmodels
69  */
70 
71  for (const auto& model : modelsContainer_)
72  {
73  if (!dynamic_cast<const SubstitutionModelInterface*>(model.get()))
74  throw Exception("MixtureOfSubstitutionModels can only be built with SubstitutionModels, not " + model->getName());
75  }
76  }
77 
78 
83  {}
84 
85 
87  {
89  return *this;
90  }
91 
92  MixtureOfSubstitutionModels* clone() const override { return new MixtureOfSubstitutionModels(*this); }
93 
94 public:
98  const SubstitutionModelInterface& subModel(const std::string& name) const
99  {
100  return dynamic_cast<const SubstitutionModelInterface&>(model(name));
101  }
102 };
103 } // end of namespace bpp.
104 #endif // BPP_PHYL_MODEL_MIXTUREOFSUBSTITUTIONMODELS_H
std::vector< std::shared_ptr< TransitionModelInterface > > modelsContainer_
vector of pointers to TransitionModels.
Partial implementation of the TransitionModel interface.
std::shared_ptr< const StateMapInterface > getStateMap() const override
virtual std::string getName() const =0
Get the name of the model.
MixtureOfSubstitutionModels(std::shared_ptr< const Alphabet > alpha, std::vector< std::unique_ptr< TransitionModelInterface >> &vpModel)
Constructor of a MixtureOfSubstitutionModels, where all the models have rate 1 and equal probability.
MixtureOfSubstitutionModels(std::shared_ptr< const Alphabet > alpha, std::vector< std::unique_ptr< TransitionModelInterface >> &vpModel, Vdouble &vproba, Vdouble &vrate)
Constructor of a MixtureOfSubstitutionModels.
const SubstitutionModelInterface & subModel(const std::string &name) const
retrieve a pointer to the substitution model with the given name.
MixtureOfSubstitutionModels & operator=(const MixtureOfSubstitutionModels &model)
MixtureOfSubstitutionModels * clone() const override
MixtureOfSubstitutionModels(const MixtureOfSubstitutionModels &model)
Transition models defined as a mixture of several substitution models.
MixtureOfTransitionModels & operator=(const MixtureOfTransitionModels &)
const TransitionModelInterface & model(const std::string &name) const override
retrieve a pointer to the submodel with the given name.
Interface for all substitution models.
Defines the basic types of data flow nodes.
std::vector< double > Vdouble