bpp-phyl3  3.0.0
CodonFrequencySet.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_FREQUENCYSET_CODONFREQUENCYSET_H
6 #define BPP_PHYL_MODEL_FREQUENCYSET_CODONFREQUENCYSET_H
7 
11 
12 #include "FrequencySet.h"
13 #include "ProteinFrequencySet.h"
14 #include "WordFrequencySet.h"
15 
16 namespace bpp
17 {
22  public virtual FrequencySetInterface
23 {
24 public:
25  CodonFrequencySetInterface* clone() const override = 0;
26 
27  virtual std::shared_ptr<const CodonAlphabet> getCodonAlphabet() const = 0;
28 
29 public:
33  virtual std::shared_ptr<const GeneticCode> getGeneticCode() const = 0;
34 
56  static std::unique_ptr<CodonFrequencySetInterface> getFrequencySetForCodons(
57  short option,
58  std::shared_ptr<const GeneticCode> gCode,
59  const std::string& mgmtStopCodon = "quadratic",
60  unsigned short method = 1);
61 
62  static const short F0;
63  static const short F1X4;
64  static const short F3X4;
65  static const short F61;
66 };
67 
68 
76  public virtual CodonFrequencySetInterface,
78 {
79 protected:
80  std::shared_ptr<const GeneticCode> pgc_;
81 
82 private:
87 
88 public:
94  std::shared_ptr<const GeneticCode> gCode,
95  bool allowNullFreqs = false,
96  unsigned short method = 1,
97  const std::string& name = "Full");
98 
100  std::shared_ptr<const GeneticCode> gCode,
101  const std::vector<double>& initFreqs,
102  bool allowNullFreqs = false,
103  unsigned short method = 1,
104  const std::string& name = "Full");
105 
108 
109  FullCodonFrequencySet* clone() const override { return new FullCodonFrequencySet(*this); }
110 
111 public:
112  std::shared_ptr<const GeneticCode> getGeneticCode() const override { return pgc_; }
113 
118  void setFrequencies(const std::vector<double>& frequencies) override;
119 
120  std::shared_ptr<const CodonAlphabet> getCodonAlphabet() const override
121  {
122  return std::dynamic_pointer_cast<const CodonAlphabet>(getAlphabet());
123  }
124 
125  void setNamespace(const std::string& nameSpace) override;
126 
127  unsigned short getMethod() const
128  {
129  return sFreq_.getMethod();
130  }
131 
132 protected:
133  void fireParameterChanged(const ParameterList& parameters) override;
134 
135  void updateFreq_();
136 };
137 
138 
145  public virtual CodonFrequencySetInterface,
146  public AbstractFrequencySet
147 {
148 protected:
149  std::shared_ptr<const GeneticCode> pgc_;
150 
151 public:
153  std::shared_ptr<const GeneticCode> gCode,
154  const std::vector<double>& initFreqs,
155  const std::string& name = "Fixed");
156 
162  std::shared_ptr<const GeneticCode> gCode,
163  const std::string& name = "Fixed");
164 
166  AbstractFrequencySet(fcfs),
167  pgc_(fcfs.pgc_)
168  {}
169 
171  {
173  pgc_ = fcfs.pgc_;
174  return *this;
175  }
176 
177  FixedCodonFrequencySet* clone() const override { return new FixedCodonFrequencySet(*this); }
178 
179 public:
180  std::shared_ptr<const GeneticCode> getGeneticCode() const override { return pgc_; }
181 
182  std::shared_ptr<const CodonAlphabet> getCodonAlphabet() const override
183  {
184  return std::dynamic_pointer_cast<const CodonAlphabet>(getAlphabet());
185  }
186 
191  void setFrequencies(const std::vector<double>& frequencies) override;
192 
193 protected:
194  void fireParameterChanged(const ParameterList& parameters) override {}
195 };
196 
198  public virtual CodonFrequencySetInterface,
199  public UserFrequencySet
200 {
201 protected:
202  std::shared_ptr<const GeneticCode> pgc_;
203 
204 public:
206  std::shared_ptr<const GeneticCode> gCode,
207  const std::string& path,
208  size_t nCol = 1);
209 
211  UserFrequencySet(fcfs),
212  pgc_(fcfs.pgc_)
213  {}
214 
216  {
218  pgc_ = fcfs.pgc_;
219  return *this;
220  }
221 
222  UserCodonFrequencySet* clone() const override { return new UserCodonFrequencySet(*this); }
223 
224 public:
225  std::shared_ptr<const GeneticCode> getGeneticCode() const override { return pgc_; }
226 
227  std::shared_ptr<const CodonAlphabet> getCodonAlphabet() const override
228  {
229  return std::dynamic_pointer_cast<const CodonAlphabet>(getAlphabet());
230  }
231 
236  void setFrequencies(const std::vector<double>& frequencies) override;
237 
238 protected:
239  void fireParameterChanged(const ParameterList& parameters) override {}
240 };
241 
256  public virtual CodonFrequencySetInterface,
257  public AbstractFrequencySet
258 {
259 private:
260  std::shared_ptr<const GeneticCode> pgc_;
261  std::unique_ptr<ProteinFrequencySetInterface> ppfs_;
262 
266  std::vector<Simplex> vS_;
267 
268  void updateFrequencies_();
269 
270 public:
281  std::shared_ptr<const GeneticCode> gencode,
282  std::unique_ptr<ProteinFrequencySetInterface> ppfs,
283  unsigned short method = 1);
284 
292  std::shared_ptr<const GeneticCode> gencode,
293  unsigned short method = 1);
294 
296 
298 
300 
301  FullPerAACodonFrequencySet* clone() const override { return new FullPerAACodonFrequencySet(*this); }
302 
303 public:
304  std::shared_ptr<const CodonAlphabet> getCodonAlphabet() const override
305  {
306  return std::dynamic_pointer_cast<const CodonAlphabet>(getAlphabet());
307  }
308 
309  std::shared_ptr<const GeneticCode> getGeneticCode() const override { return pgc_; }
310 
315  void setFrequencies(const std::vector<double>& frequencies) override;
316 
317  void setNamespace(const std::string& prefix) override;
318 
320  {
321  return ppfs_ != nullptr;
322  }
323 
325  {
326  return *ppfs_;
327  }
328 
329  unsigned short getMethod() const
330  {
331  return vS_.size() > 0 ? vS_[0].getMethod() : static_cast<unsigned short>(1);
332  }
333 
334 protected:
335  void fireParameterChanged(const ParameterList& parameters) override;
336 };
337 
338 
347  public virtual CodonFrequencySetInterface,
349 {
350 private:
351  // a map associating stop codons numbers with numbers of neighbour non-stop codons
352  std::map<int, Vint> mStopNeigh_;
353 
354  unsigned short mgmtStopCodon_;
355 
356  std::shared_ptr<const GeneticCode> pgc_;
357 
358 public:
378  std::shared_ptr<const GeneticCode> gCode,
379  std::vector<std::unique_ptr<FrequencySetInterface>>& freqvector,
380  const std::string& name = "Codon",
381  const std::string& mgmtStopCodon = "quadratic");
382 
384 
386 
388 
390 
391  std::shared_ptr<const CodonAlphabet> getCodonAlphabet() const override;
392 
393  std::shared_ptr<const GeneticCode> getGeneticCode() const override { return pgc_; }
394 
398  void updateFrequencies() override;
399 
403  std::string getMgmtStopCodon() const
404  {
405  switch (mgmtStopCodon_)
406  {
407  case 0:
408  return "uniform";
409  case 1:
410  return "linear";
411  case 2:
412  return "quadratic";
413  }
414  return "";
415  }
416 };
417 
418 
428  public virtual CodonFrequencySetInterface,
430 {
431 private:
432  // a map associating stop codons numbers with numbers of neighbour non-stop codons
433  std::map<int, Vint> mStopNeigh_;
434 
435  unsigned short mgmtStopCodon_;
436 
437  std::shared_ptr<const GeneticCode> pgc_;
438 
439 public:
459  std::shared_ptr<const GeneticCode> gCode,
460  std::unique_ptr<FrequencySetInterface> pfreq,
461  const std::string& name = "Codon",
462  const std::string& mgmtStopCodon = "quadratic");
463 
465 
467 
469 
470  CodonFromUniqueFrequencySet* clone() const override { return new CodonFromUniqueFrequencySet(*this); }
471 
472  std::shared_ptr<const CodonAlphabet> getCodonAlphabet() const override;
473 
474  std::shared_ptr<const GeneticCode> getGeneticCode() const override { return pgc_; }
475 
479  void updateFrequencies() override;
480 
484  std::string getMgmtStopCodon() const
485  {
486  switch (mgmtStopCodon_)
487  {
488  case 0:
489  return "uniform";
490  case 1:
491  return "linear";
492  case 2:
493  return "quadratic";
494  }
495  return "";
496  }
497 };
498 } // end of namespace bpp.
499 #endif // BPP_PHYL_MODEL_FREQUENCYSET_CODONFREQUENCYSET_H
Basic implementation of the FrequencySet interface.
Definition: FrequencySet.h:102
std::shared_ptr< const Alphabet > getAlphabet() const override
Definition: FrequencySet.h:140
AbstractFrequencySet & operator=(const AbstractFrequencySet &af)
Definition: FrequencySet.h:129
Parametrize a set of state frequencies for codons.
static std::unique_ptr< CodonFrequencySetInterface > getFrequencySetForCodons(short option, std::shared_ptr< const GeneticCode > gCode, const std::string &mgmtStopCodon="quadratic", unsigned short method=1)
A helper function that provide frequencies set for codon models according to PAML option.
virtual std::shared_ptr< const GeneticCode > getGeneticCode() const =0
CodonFrequencySetInterface * clone() const override=0
virtual std::shared_ptr< const CodonAlphabet > getCodonAlphabet() const =0
the Frequencies in codons are the product of Independent Frequencies in letters with the frequencies ...
CodonFromIndependentFrequencySet * clone() const override
std::string getMgmtStopCodon() const
Retrieve the mgmt method for the stop codons.
std::shared_ptr< const CodonAlphabet > getCodonAlphabet() const override
std::shared_ptr< const GeneticCode > getGeneticCode() const override
void updateFrequencies() override
Update the frequencies given the parameters.
std::shared_ptr< const GeneticCode > pgc_
CodonFromIndependentFrequencySet(std::shared_ptr< const GeneticCode > gCode, std::vector< std::unique_ptr< FrequencySetInterface >> &freqvector, const std::string &name="Codon", const std::string &mgmtStopCodon="quadratic")
Constructor from a CodonAlphabet* and a vector of different std::shared_ptr<FrequencySet>....
CodonFromIndependentFrequencySet & operator=(const CodonFromIndependentFrequencySet &iwfs)
the Frequencies in codons are the product of the frequencies for a unique FrequencySet in letters,...
void updateFrequencies() override
Update the frequencies given the parameters.
CodonFromUniqueFrequencySet(std::shared_ptr< const GeneticCode > gCode, std::unique_ptr< FrequencySetInterface > pfreq, const std::string &name="Codon", const std::string &mgmtStopCodon="quadratic")
Constructor from a CodonAlphabet* and a std::shared_ptr<FrequencySet> repeated three times.
std::string getMgmtStopCodon() const
Retrieve the mgmt method for the stop codons.
std::shared_ptr< const GeneticCode > pgc_
std::shared_ptr< const GeneticCode > getGeneticCode() const override
CodonFromUniqueFrequencySet & operator=(const CodonFromUniqueFrequencySet &iwfs)
std::shared_ptr< const CodonAlphabet > getCodonAlphabet() const override
CodonFromUniqueFrequencySet * clone() const override
FrequencySet useful for homogeneous and stationary models, codon implementation.
void setFrequencies(const std::vector< double > &frequencies) override
the given frequencies are normalized such thaat the sum of the frequencies on the non-stop codons equ...
std::shared_ptr< const CodonAlphabet > getCodonAlphabet() const override
std::shared_ptr< const GeneticCode > pgc_
void fireParameterChanged(const ParameterList &parameters) override
FixedCodonFrequencySet & operator=(const FixedCodonFrequencySet &fcfs)
FixedCodonFrequencySet(std::shared_ptr< const GeneticCode > gCode, const std::vector< double > &initFreqs, const std::string &name="Fixed")
FixedCodonFrequencySet(const FixedCodonFrequencySet &fcfs)
std::shared_ptr< const GeneticCode > getGeneticCode() const override
FixedCodonFrequencySet * clone() const override
Parametrize a set of state frequencies.
Definition: FrequencySet.h:29
virtual std::shared_ptr< const Alphabet > getAlphabet() const =0
A generic FrequencySet for Full Codon alphabets.
FullCodonFrequencySet & operator=(const FullCodonFrequencySet &fcfs)
unsigned short getMethod() const
FullCodonFrequencySet(std::shared_ptr< const GeneticCode > gCode, bool allowNullFreqs=false, unsigned short method=1, const std::string &name="Full")
Construction with uniform frequencies on the letters of the alphabet. The stop codon frequencies are ...
Simplex sFreq_
Simplex to handle the probabilities and the parameters.
std::shared_ptr< const GeneticCode > pgc_
void setFrequencies(const std::vector< double > &frequencies) override
the given frequencies are normalized such that the sum of the frequencies on the non-stop codons equa...
void fireParameterChanged(const ParameterList &parameters) override
void setNamespace(const std::string &nameSpace) override
std::shared_ptr< const GeneticCode > getGeneticCode() const override
FullCodonFrequencySet * clone() const override
std::shared_ptr< const CodonAlphabet > getCodonAlphabet() const override
FrequencySet integrating ProteinFrequencySet inside CodonFrequencySet. In this case,...
std::unique_ptr< ProteinFrequencySetInterface > ppfs_
std::shared_ptr< const GeneticCode > pgc_
std::shared_ptr< const CodonAlphabet > getCodonAlphabet() const override
void setFrequencies(const std::vector< double > &frequencies) override
the given frequencies are normalized such thaat the sum of the frequencies on the non-stop codons equ...
FullPerAACodonFrequencySet * clone() const override
const ProteinFrequencySetInterface & proteinFrequencySet() const
unsigned short getMethod() const
std::shared_ptr< const GeneticCode > getGeneticCode() const override
void setNamespace(const std::string &prefix) override
std::vector< Simplex > vS_
vector of the simplexes, one for each AA
FullPerAACodonFrequencySet(std::shared_ptr< const GeneticCode > gencode, std::unique_ptr< ProteinFrequencySetInterface > ppfs, unsigned short method=1)
Create a new FullPerAACodonFrequencySet object.
FullPerAACodonFrequencySet & operator=(const FullPerAACodonFrequencySet &ffs)
void fireParameterChanged(const ParameterList &parameters) override
Parametrize a set of state frequencies for proteins.
unsigned short getMethod() const
UserCodonFrequencySet(std::shared_ptr< const GeneticCode > gCode, const std::string &path, size_t nCol=1)
UserCodonFrequencySet(const UserCodonFrequencySet &fcfs)
std::shared_ptr< const GeneticCode > pgc_
UserCodonFrequencySet & operator=(const UserCodonFrequencySet &fcfs)
std::shared_ptr< const CodonAlphabet > getCodonAlphabet() const override
UserCodonFrequencySet * clone() const override
void setFrequencies(const std::vector< double > &frequencies) override
the given frequencies are normalized such thaat the sum of the frequencies on the non-stop codons equ...
void fireParameterChanged(const ParameterList &parameters) override
std::shared_ptr< const GeneticCode > getGeneticCode() const override
FrequencySet to be read in a file. More specifically, a frequency set is read in a column of a given ...
Definition: FrequencySet.h:386
UserFrequencySet & operator=(const UserFrequencySet &fmfs)
the Frequencies in words are the product of Independent Frequencies in letters
Defines the basic types of data flow nodes.