bpp-phyl3  3.0.0
AbstractWordSubstitutionModel.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_ABSTRACTWORDSUBSTITUTIONMODEL_H
6 #define BPP_PHYL_MODEL_ABSTRACTWORDSUBSTITUTIONMODEL_H
7 
8 
10 
11 // From bpp-seq:
13 
14 // From the STL:
15 #include <vector>
16 
17 namespace bpp
18 {
24 class ModelList
25 {
26 protected:
30  std::vector<std::shared_ptr<SubstitutionModelInterface>> models_;
31  std::shared_ptr<WordAlphabet> wordAlphabet_;
32 
33 public:
42  ModelList(std::vector<std::unique_ptr<SubstitutionModelInterface>>& models) :
43  models_(models.size()), wordAlphabet_(nullptr)
44  {
45  std::vector<std::shared_ptr<const Alphabet>> alphabets(models.size());
46  for (size_t i = 0; i < models.size(); ++i)
47  {
48  alphabets[i] = models[i]->getAlphabet();
49  models_[i] = std::move(models[i]);
50  }
51  wordAlphabet_ = std::make_shared<WordAlphabet>(alphabets);
52  }
53 
54 private:
55  ModelList(const ModelList& ml) {}
56 
57  ModelList& operator=(const ModelList& ml) { return *this; }
58 
59 public:
60  size_t size() const { return models_.size(); }
61 
62  std::shared_ptr<SubstitutionModelInterface> getModel(size_t i)
63  {
64  return models_[i];
65  }
66 
67  std::shared_ptr<const WordAlphabet> getWordAlphabet()
68  {
69  return wordAlphabet_;
70  }
71 };
72 
73 
104 {
105 private:
110 
111 protected:
115  std::vector<std::shared_ptr<SubstitutionModelInterface>> VSubMod_;
116 
117  std::vector<std::string> VnestedPrefix_;
118 
119  std::vector<double> Vrate_;
120 
121 protected:
122  void updateMatrices_();
123 
128  virtual void completeMatrices_() = 0;
129 
133  virtual void fillBasicGenerator_();
134 
135 public:
148  ModelList& modelList,
149  const std::string& prefix);
150 
163  std::unique_ptr<SubstitutionModelInterface> model,
164  unsigned int num,
165  const std::string& prefix);
166 
168 
170 
172 
173  void setNamespace(const std::string& prefix);
174 
175 protected:
180  std::shared_ptr<const Alphabet> alph,
181  std::shared_ptr<const StateMapInterface> stateMap,
182  const std::string& prefix);
183 
184 public:
188  const SubstitutionModelInterface& nModel(size_t i) const
189  {
190  if (i < VSubMod_.size())
191  return *VSubMod_[i];
192  else
193  throw NullPointerException("AbstractWordSubstitutionModel::nModel. Invalid model requested.");
194  }
195 
196  size_t getNumberOfModels() const
197  {
198  return VSubMod_.size();
199  }
200 
212  virtual void setFreq(std::map<int, double>& freqs);
213 };
214 } // end of namespace bpp.
215 #endif // BPP_PHYL_MODEL_ABSTRACTWORDSUBSTITUTIONMODEL_H
const StateMapInterface & stateMap() const override
Abstract Basal class for words of substitution models.
virtual void completeMatrices_()=0
Called by updateMatrices to handle specific modifications for inheriting classes.
virtual void setFreq(std::map< int, double > &freqs)
Estimation of the parameters of the models so that the equilibrium frequencies match the given ones.
virtual void fillBasicGenerator_()
First fill of the generator, from the position model.
void updateMatrices_()
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
bool newAlphabet_
boolean flag to check if a specific WordAlphabet has been built
AbstractWordSubstitutionModel(ModelList &modelList, const std::string &prefix)
Build a new AbstractWordSubstitutionModel object from a vector of pointers to SubstitutionModels.
std::vector< std::shared_ptr< SubstitutionModelInterface > > VSubMod_
const SubstitutionModelInterface & nModel(size_t i) const
returns the ith model, or throw an exception if i is not a valid number.
AbstractWordSubstitutionModel & operator=(const AbstractWordSubstitutionModel &)
A list of models, for building a WordSubstitutionModel.
std::shared_ptr< SubstitutionModelInterface > getModel(size_t i)
ModelList & operator=(const ModelList &ml)
std::vector< std::shared_ptr< SubstitutionModelInterface > > models_
Position-specific models are stored as shared_ptr to allow several positions to share the same model....
ModelList(std::vector< std::unique_ptr< SubstitutionModelInterface >> &models)
Create a ModelList from one template substitution model.
std::shared_ptr< const WordAlphabet > getWordAlphabet()
std::shared_ptr< WordAlphabet > wordAlphabet_
ModelList(const ModelList &ml)
Interface for all substitution models.
Defines the basic types of data flow nodes.