bpp-phyl3  3.0.0
RE08.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_RE08_H
6 #define BPP_PHYL_MODEL_RE08_H
7 
8 
13 #include "SubstitutionModel.h"
14 
15 namespace bpp
16 {
64 class RE08 :
66 {
67 private:
68  std::unique_ptr<ReversibleSubstitutionModelInterface> simpleModel_;
71  mutable double exp_;
73  double lambda_;
74  double mu_;
75  std::string nestedPrefix_;
76 
77 public:
89  RE08(
90  std::unique_ptr<ReversibleSubstitutionModelInterface> simpleModel,
91  double lambda = 0.1,
92  double mu = 0.1);
93 
94  RE08(const RE08& model) :
100  exp_(model.exp_),
101  p_(model.p_),
102  lambda_(model.lambda_),
103  mu_(model.mu_),
105  {}
106 
107  RE08& operator=(const RE08& model)
108  {
111  simpleModel_.reset(model.simpleModel_->clone());
114  exp_ = model.exp_;
115  p_ = model.p_;
116  lambda_ = model.lambda_;
117  mu_ = model.mu_;
119  return *this;
120  }
121 
122  virtual ~RE08() {}
123 
124  RE08* clone() const override { return new RE08(*this); }
125 
126 public:
127  double Pij_t (size_t i, size_t j, double d) const override;
128  double dPij_dt (size_t i, size_t j, double d) const override;
129  double d2Pij_dt2(size_t i, size_t j, double d) const override;
130  const Matrix<double>& getPij_t (double d) const override;
131  const Matrix<double>& getdPij_dt (double d) const override;
132  const Matrix<double>& getd2Pij_dt2(double d) const override;
133 
134  std::string getName() const override { return "RE08"; }
135 
142  void setFreqFromData(const SequenceDataInterface& data, double pseudoCount = 0) override
143  {
144  simpleModel_->setFreqFromData(data, pseudoCount);
145  }
146 
147  void setFreq(std::map<int, double>& frequencies) override
148  {
149  simpleModel_->setFreq(frequencies);
150  }
151 
152  void fireParameterChanged(const ParameterList& parameters) override
153  {
154  simpleModel_->matchParametersValues(parameters);
156  mu_ = getParameter_(1).getValue();
157  updateMatrices_();
158  }
159 
160  double getInitValue(size_t i, int state) const override;
161 
162  void setNamespace(const std::string& prefix) override;
163 
165  {
166  return *simpleModel_;
167  }
168 
169 protected:
170  void updateMatrices_() override;
171 
173 };
174 
175 
180  public RE08,
182 {
183 public:
201  std::unique_ptr<NucleotideReversibleSubstitutionModelInterface> nucleotideModel,
202  double lambda = 0.1,
203  double mu = 0.1) :
205  RE08(std::move(nucleotideModel), lambda, mu) {}
206 
207  virtual ~RE08Nucleotide() {}
208 
209  RE08Nucleotide* clone() const override { return new RE08Nucleotide(*this); }
210 
211 public:
212  std::shared_ptr<const NucleicAlphabet> getNucleicAlphabet() const override
213  {
214  return std::dynamic_pointer_cast<const NucleicAlphabet>(alphabet_);
215  }
216 
218  {
220  }
221 
222  size_t getNumberOfStates() const override { return RE08::getNumberOfStates(); }
223 };
224 
228 class RE08Protein :
229  public RE08,
230  public virtual ProteinSubstitutionModelInterface
231 {
232 public:
245  std::unique_ptr<ProteinReversibleSubstitutionModelInterface> proteinModel,
246  double lambda = 0.1,
247  double mu = 0.1) :
249  RE08(std::move(proteinModel), lambda, mu) {}
250 
251  virtual ~RE08Protein() {}
252 
253  RE08Protein* clone() const override { return new RE08Protein(*this); }
254 
255 public:
256  std::shared_ptr<const ProteicAlphabet> getProteicAlphabet() const override
257  {
258  return std::dynamic_pointer_cast<const ProteicAlphabet>(alphabet_);
259  }
260 
262  {
263  return dynamic_cast<const ProteinReversibleSubstitutionModelInterface&>(RE08::nestedModel());
264  }
265 
266  size_t getNumberOfStates() const override { return RE08::getNumberOfStates(); }
267 };
268 
269 
273 class RE08Codon :
274  public RE08,
275  public virtual CodonSubstitutionModelInterface
276 {
277 public:
290  std::unique_ptr<CodonReversibleSubstitutionModelInterface> codonModel,
291  double lambda = 0.1,
292  double mu = 0.1) :
294  RE08(std::move(codonModel), lambda, mu) {}
295 
296  virtual ~RE08Codon() {}
297 
298  RE08Codon* clone() const override { return new RE08Codon(*this); }
299 
300 public:
302  {
303  return dynamic_cast<const CodonReversibleSubstitutionModelInterface&>(RE08::nestedModel());
304  }
305 
306  std::shared_ptr<const GeneticCode> getGeneticCode () const override
307  {
308  return nestedModel().getGeneticCode();
309  }
310 
311  double getCodonsMulRate(size_t i, size_t j) const override
312  {
313  return nestedModel().getCodonsMulRate(i, j);
314  }
315 
316  size_t getNumberOfStates() const override { return RE08::getNumberOfStates(); }
317 
319  {
320  return dynamic_cast<const CodonFrequencySetInterface&>(RE08::nestedModel().frequencySet());
321  }
322 
323  bool hasCodonFrequencySet() const override
324  {
325  return true;
326  }
327 
328  void setFreq(std::map<int, double>& frequencies) override
329  {
330  RE08::nestedModel_().setFreq(frequencies);
331  }
332 };
333 } // end of namespace bpp.
334 #endif // BPP_PHYL_MODEL_RE08_H
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
Parameter & getParameter_(const std::string &name)
Partial implementation of the ReversibleSubstitutionModel interface.
AbstractSubstitutionModel & operator=(const AbstractSubstitutionModel &model)
std::shared_ptr< const Alphabet > alphabet_
The alphabet relevant to this model.
size_t getNumberOfStates() const override
Get the number of states.
virtual const FrequencySetInterface & frequencySet() const =0
Parametrize a set of state frequencies for codons.
Interface for reversible codon models.
virtual std::shared_ptr< const GeneticCode > getGeneticCode() const =0
virtual double getCodonsMulRate(size_t, size_t) const =0
Returns the multiplicative rate specific to two codons specified by their number. The respective gene...
Specialisation interface for rversible nucleotide substitution model.
Specialisation interface for nucleotide substitution model.
virtual double getValue() const
Specialized interface for protein reversible substitution model.
Specialized interface for protein substitution model.
This is a wrapper class of RE08 for codon substitution models.
Definition: RE08.h:276
RE08Codon * clone() const override
Definition: RE08.h:298
double getCodonsMulRate(size_t i, size_t j) const override
Returns the multiplicative rate specific to two codons specified by their number. The respective gene...
Definition: RE08.h:311
std::shared_ptr< const GeneticCode > getGeneticCode() const override
Definition: RE08.h:306
void setFreq(std::map< int, double > &frequencies) override
Set equilibrium frequencies.
Definition: RE08.h:328
const CodonReversibleSubstitutionModelInterface & nestedModel() const
Definition: RE08.h:301
virtual ~RE08Codon()
Definition: RE08.h:296
const CodonFrequencySetInterface & codonFrequencySet() const override
Definition: RE08.h:318
size_t getNumberOfStates() const override
Get the number of states.
Definition: RE08.h:316
RE08Codon(std::unique_ptr< CodonReversibleSubstitutionModelInterface > codonModel, double lambda=0.1, double mu=0.1)
Build a new Rivas & Eddy model from a codon substitution model.
Definition: RE08.h:289
bool hasCodonFrequencySet() const override
Definition: RE08.h:323
This is a wrapper class of RE08 for nucleotide substitution models.
Definition: RE08.h:182
RE08Nucleotide * clone() const override
Definition: RE08.h:209
const NucleotideReversibleSubstitutionModelInterface & nestedModel() const
Definition: RE08.h:217
std::shared_ptr< const NucleicAlphabet > getNucleicAlphabet() const override
Definition: RE08.h:212
RE08Nucleotide(std::unique_ptr< NucleotideReversibleSubstitutionModelInterface > nucleotideModel, double lambda=0.1, double mu=0.1)
Build a new Rivas & Eddy model from a nucleotide substitution model.
Definition: RE08.h:200
size_t getNumberOfStates() const override
Get the number of states.
Definition: RE08.h:222
virtual ~RE08Nucleotide()
Definition: RE08.h:207
This is a wrapper class of RE08 for protein substitution models.
Definition: RE08.h:231
virtual ~RE08Protein()
Definition: RE08.h:251
size_t getNumberOfStates() const override
Get the number of states.
Definition: RE08.h:266
std::shared_ptr< const ProteicAlphabet > getProteicAlphabet() const override
Definition: RE08.h:256
const ProteinReversibleSubstitutionModelInterface & nestedModel() const
Definition: RE08.h:261
RE08Protein(std::unique_ptr< ProteinReversibleSubstitutionModelInterface > proteinModel, double lambda=0.1, double mu=0.1)
Build a new Rivas & Eddy model from a protein substitution model.
Definition: RE08.h:244
RE08Protein * clone() const override
Definition: RE08.h:253
The Rivas-Eddy substitution model with gap characters.
Definition: RE08.h:66
std::unique_ptr< ReversibleSubstitutionModelInterface > simpleModel_
Definition: RE08.h:68
RE08 * clone() const override
Definition: RE08.h:124
const Matrix< double > & getdPij_dt(double d) const override
Definition: RE08.cpp:209
RE08 & operator=(const RE08 &model)
Definition: RE08.h:107
double exp_
Definition: RE08.h:71
RowMatrix< double > simpleExchangeabilities_
Definition: RE08.h:70
double getInitValue(size_t i, int state) const override
Definition: RE08.cpp:267
double Pij_t(size_t i, size_t j, double d) const override
Definition: RE08.cpp:90
void setNamespace(const std::string &prefix) override
Definition: RE08.cpp:286
RowMatrix< double > p_
Definition: RE08.h:72
RE08(const RE08 &model)
Definition: RE08.h:94
double d2Pij_dt2(size_t i, size_t j, double d) const override
Definition: RE08.cpp:151
std::string nestedPrefix_
Definition: RE08.h:75
const ReversibleSubstitutionModelInterface & nestedModel() const
Definition: RE08.h:164
void setFreqFromData(const SequenceDataInterface &data, double pseudoCount=0) override
This method is forwarded to the simple model.
Definition: RE08.h:142
double lambda_
Definition: RE08.h:73
const Matrix< double > & getPij_t(double d) const override
Definition: RE08.cpp:183
std::string getName() const override
Get the name of the model.
Definition: RE08.h:134
void updateMatrices_() override
Compute and diagonalize the matrix, and fill the eigenValues_, leftEigenVectors_ and rightEigenVecto...
Definition: RE08.cpp:46
const Matrix< double > & getd2Pij_dt2(double d) const override
Definition: RE08.cpp:237
RowMatrix< double > simpleGenerator_
Definition: RE08.h:69
ReversibleSubstitutionModelInterface & nestedModel_()
Definition: RE08.h:172
double mu_
Definition: RE08.h:74
RE08(std::unique_ptr< ReversibleSubstitutionModelInterface > simpleModel, double lambda=0.1, double mu=0.1)
Build a new Rivas & Eddy model from a standard substitution model.
Definition: RE08.cpp:15
void fireParameterChanged(const ParameterList &parameters) override
Tells the model that a parameter value has changed.
Definition: RE08.h:152
void setFreq(std::map< int, double > &frequencies) override
Set equilibrium frequencies.
Definition: RE08.h:147
virtual ~RE08()
Definition: RE08.h:122
double dPij_dt(size_t i, size_t j, double d) const override
Definition: RE08.cpp:120
Interface for reversible substitution models.
virtual void setFreq(std::map< int, double > &frequencies)=0
Set equilibrium frequencies.
Defines the basic types of data flow nodes.