bpp-phyl3  3.0.0
CodonSameAARateSubstitutionModel.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_CODON_CODONSAMEAARATESUBSTITUTIONMODEL_H
6 #define BPP_PHYL_MODEL_CODON_CODONSAMEAARATESUBSTITUTIONMODEL_H
7 
8 
9 #include "../FrequencySet/CodonFrequencySet.h"
10 #include "../Protein/ProteinSubstitutionModel.h"
11 #include "CodonSubstitutionModel.h"
12 
13 // From bpp-seq:
16 
17 namespace bpp
18 {
44  public virtual CodonSubstitutionModelInterface,
46 {
47 private:
52  std::unique_ptr<ProteinSubstitutionModelInterface> pAAmodel_;
53 
59  std::unique_ptr<CodonSubstitutionModelInterface> pCodonModel_;
60 
67  std::unique_ptr<CodonFrequencySetInterface> pFreq_;
68 
69  std::shared_ptr<const GeneticCode> pgencode_;
70 
75 
80 
81 public:
95  std::unique_ptr<ProteinSubstitutionModelInterface> pAAmodel,
96  std::unique_ptr<CodonSubstitutionModelInterface> pCodonModel,
97  std::unique_ptr<CodonFrequencySetInterface> pFreq,
98  std::shared_ptr<const GeneticCode> pgencode);
99 
101  const CodonSameAARateSubstitutionModel& model) :
104  pAAmodel_ (model.pAAmodel_->clone()),
105  pCodonModel_ (model.pCodonModel_->clone()),
106  pFreq_ (model.pFreq_ ? model.pFreq_->clone() : nullptr),
107  pgencode_ (model.pgencode_),
108  X_ (model.X_),
109  phi_ (model.phi_)
110  {
111  compute_();
112  updateMatrices_();
113  }
114 
117  {
119 
120  pAAmodel_.reset(model.pAAmodel_->clone());
121  pCodonModel_.reset(model.pCodonModel_->clone());
122  pFreq_.reset(model.pFreq_ ? model.pFreq_->clone() : nullptr);
123 
124  pgencode_ = model.pgencode_;
125 
126  X_ = model.X_;
127  phi_ = model.phi_;
128 
129  return *this;
130  }
131 
133  {
134  return new CodonSameAARateSubstitutionModel(*this);
135  }
136 
138 
139 public:
140  std::string getName() const override
141  {
142  return "SameAARate";
143  }
144 
146  {
147  return *pAAmodel_;
148  }
149 
151  {
152  return *pCodonModel_;
153  }
154 
155  void fireParameterChanged(const ParameterList& parameters) override;
156 
157  void setNamespace(const std::string& prefix) override
158  {
160 
161  pAAmodel_->setNamespace(prefix + pAAmodel_->getNamespace());
162  pCodonModel_->setNamespace(prefix + pCodonModel_->getNamespace());
163 
164  if (pFreq_)
165  pFreq_->setNamespace(prefix + pFreq_->getNamespace());
166  }
167 
169  {
170  return pCodonModel_->codonFrequencySet();
171  }
172 
173  bool hasCodonFrequencySet() const override
174  {
175  return pCodonModel_->hasCodonFrequencySet();
176  }
177 
178  std::shared_ptr<const GeneticCode> getGeneticCode() const override
179  {
180  return pCodonModel_->getGeneticCode();
181  }
182 
183  void setFreq(std::map<int, double>& frequencies) override
184  {
185  dynamic_cast<CoreCodonSubstitutionModelInterface&>(*pCodonModel_).setFreq(frequencies);
186  matchParametersValues(pCodonModel_->getParameters());
187  }
188 
189  double getCodonsMulRate(size_t i, size_t j) const override
190  {
191  return 1.;
192  }
193 
194 private:
195  void compute_();
196 };
197 } // end of namespace bpp.
198 #endif // BPP_PHYL_MODEL_CODON_CODONSAMEAARATESUBSTITUTIONMODEL_H
void setNamespace(const std::string &prefix)
bool matchParametersValues(const ParameterList &parameters) override
AbstractSubstitutionModel & operator=(const AbstractSubstitutionModel &model)
virtual void updateMatrices_()
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
Parametrize a set of state frequencies for codons.
Class for modelling of non-synonymous rates in codon models, such that the substitution rates between...
std::shared_ptr< const GeneticCode > getGeneticCode() const override
const CodonFrequencySetInterface & codonFrequencySet() const override
void setNamespace(const std::string &prefix) override
CodonSameAARateSubstitutionModel(std::unique_ptr< ProteinSubstitutionModelInterface > pAAmodel, std::unique_ptr< CodonSubstitutionModelInterface > pCodonModel, std::unique_ptr< CodonFrequencySetInterface > pFreq, std::shared_ptr< const GeneticCode > pgencode)
Build a new CodonSameAARateSubstitutionModel object from a pointer to NucleotideSubstitutionModel.
std::unique_ptr< CodonFrequencySetInterface > pFreq_
Protein Model which will be used to get similar AA rates. Its possible parameters are not copied in t...
CodonSameAARateSubstitutionModel(const CodonSameAARateSubstitutionModel &model)
CodonSameAARateSubstitutionModel & operator=(const CodonSameAARateSubstitutionModel &model)
std::unique_ptr< CodonSubstitutionModelInterface > pCodonModel_
Codon Model which will be copied. Its possible parameters are not copied in this object.
std::shared_ptr< const GeneticCode > pgencode_
void setFreq(std::map< int, double > &frequencies) override
Set equilibrium frequencies.
const ProteinSubstitutionModelInterface & proteinModel() const
const CodonSubstitutionModelInterface & codonModel() const
std::string getName() const override
Get the name of the model.
RowMatrix< double > X_
20 x 20 Matrix of the denominator of the multiplicators
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...
std::unique_ptr< ProteinSubstitutionModelInterface > pAAmodel_
Protein Model which will be used to get similar AA rates.
CodonSameAARateSubstitutionModel * clone() const override
void fireParameterChanged(const ParameterList &parameters) override
Tells the model that a parameter value has changed.
virtual void setFreq(std::map< int, double > &frequencies)=0
Specialized interface for protein substitution model.
Defines the basic types of data flow nodes.
std::vector< double > Vdouble