bpp-phyl3  3.0.0
JCprot.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_PROTEIN_JCPROT_H
6 #define BPP_PHYL_MODEL_PROTEIN_JCPROT_H
7 
9 
10 #include "../AbstractSubstitutionModel.h"
11 #include "../FrequencySet/ProteinFrequencySet.h"
13 
14 namespace bpp
15 {
99 class JCprot :
101 {
102 private:
103  mutable double exp_;
105  std::unique_ptr<ProteinFrequencySetInterface> freqSet_;
106  bool withFreq_;
107 
108 public:
114  JCprot(std::shared_ptr<const ProteicAlphabet> alpha);
115 
124  JCprot(
125  std::shared_ptr<const ProteicAlphabet> alpha,
126  std::unique_ptr<ProteinFrequencySetInterface> freqSet,
127  bool initFreqs = false);
128 
129  JCprot(const JCprot& model) :
132  exp_(model.exp_),
133  p_(model.p_),
134  freqSet_(model.freqSet_->clone()),
135  withFreq_(model.withFreq_)
136  {}
137 
138  JCprot& operator=(const JCprot& model)
139  {
142  exp_ = model.exp_;
143  p_ = model.p_;
144  freqSet_.reset(model.freqSet_->clone());
145  withFreq_ = model.withFreq_;
146  return *this;
147  }
148 
149  virtual ~JCprot() {}
150 
151  JCprot* clone() const override { return new JCprot(*this); }
152 
153 public:
154  double Pij_t (size_t i, size_t j, double d) const override;
155  double dPij_dt (size_t i, size_t j, double d) const override;
156  double d2Pij_dt2(size_t i, size_t j, double d) const override;
157  const Matrix<double>& getPij_t (double d) const override;
158  const Matrix<double>& getdPij_dt (double d) const override;
159  const Matrix<double>& getd2Pij_dt2(double d) const override;
160 
161  std::string getName() const override
162  {
163  return withFreq_ ? "JC69+F" : "JC69";
164  }
165 
166  void fireParameterChanged(const ParameterList& parameters) override
167  {
168  freqSet_->matchParametersValues(parameters);
169  freq_ = freqSet_->getFrequencies();
171  }
172 
174  {
175  freqSet_.reset(freqSet.clone());
177  addParameters_(freqSet_->getParameters());
178  }
179 
180  const FrequencySetInterface& frequencySet() const override
181  {
182  if (freqSet_)
183  return *freqSet_;
184  throw NullPointerException("JCprot::frequencySet(). No associated FrequencySet.");
185  }
186 
187  void setNamespace(const std::string& prefix) override
188  {
190  freqSet_->setNamespace(prefix + freqSet_->getName() + ".");
191  }
192 
193  void setFreqFromData(const SequenceDataInterface& data, double pseudoCount = 0) override;
194 
195 protected:
201  void updateMatrices_() override;
202 };
203 } // end of namespace bpp.
204 #endif // BPP_PHYL_MODEL_PROTEIN_JCPROT_H
void addParameters_(const ParameterList &parameters)
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
void setNamespace(const std::string &prefix)
Specialisation abstract class for reversible protein substitution model.
AbstractSubstitutionModel & operator=(const AbstractSubstitutionModel &model)
virtual void fireParameterChanged(const ParameterList &parameters) override
Tells the model that a parameter value has changed.
Vdouble freq_
The vector of equilibrium frequencies.
Parametrize a set of state frequencies.
Definition: FrequencySet.h:29
The Jukes-Cantor substitution model for proteins.
Definition: JCprot.h:101
RowMatrix< double > p_
Definition: JCprot.h:104
const Matrix< double > & getPij_t(double d) const override
Definition: JCprot.cpp:170
const FrequencySetInterface & frequencySet() const override
Definition: JCprot.h:180
double exp_
Definition: JCprot.h:103
void setNamespace(const std::string &prefix) override
Definition: JCprot.h:187
const Matrix< double > & getd2Pij_dt2(double d) const override
Definition: JCprot.cpp:206
double Pij_t(size_t i, size_t j, double d) const override
Definition: JCprot.cpp:125
double dPij_dt(size_t i, size_t j, double d) const override
Definition: JCprot.cpp:140
double d2Pij_dt2(size_t i, size_t j, double d) const override
Definition: JCprot.cpp:155
JCprot(std::shared_ptr< const ProteicAlphabet > alpha)
Build a simple JC69 model, with original equilibrium frequencies.
Definition: JCprot.cpp:19
void setFreqFromData(const SequenceDataInterface &data, double pseudoCount=0) override
Set equilibrium frequencies equal to the frequencies estimated from the data.
Definition: JCprot.cpp:226
std::unique_ptr< ProteinFrequencySetInterface > freqSet_
Definition: JCprot.h:105
virtual ~JCprot()
Definition: JCprot.h:149
JCprot(const JCprot &model)
Definition: JCprot.h:129
JCprot & operator=(const JCprot &model)
Definition: JCprot.h:138
void setFrequencySet(const ProteinFrequencySetInterface &freqSet)
Definition: JCprot.h:173
std::string getName() const override
Get the name of the model.
Definition: JCprot.h:161
void updateMatrices_() override
Definition: JCprot.cpp:48
const Matrix< double > & getdPij_dt(double d) const override
Definition: JCprot.cpp:188
JCprot * clone() const override
Definition: JCprot.h:151
bool withFreq_
Definition: JCprot.h:106
void fireParameterChanged(const ParameterList &parameters) override
Tells the model that a parameter value has changed.
Definition: JCprot.h:166
Parametrize a set of state frequencies for proteins.
ProteinFrequencySetInterface * clone() const override=0
Defines the basic types of data flow nodes.