bpp-phyl  2.2.0
CodonFrequenciesSet.h
Go to the documentation of this file.
1 //
2 // File: CodonFrequenciesSet.h
3 // Created by: laurent Gueguen
4 // Created on: lundi 2 avril 2012, à 14h 03
5 //
6 
7 /*
8  Copyright or (c) or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
40 #ifndef _CODONFREQUENCIESSET_H_
41 #define _CODONFREQUENCIESSET_H_
42 
43 #include "WordFrequenciesSet.h"
44 #include "FrequenciesSet.h"
45 #include "ProteinFrequenciesSet.h"
46 
47 #include <Bpp/Seq/Alphabet/CodonAlphabet.h>
48 #include <Bpp/Seq/GeneticCode/GeneticCode.h>
49 #include <Bpp/Numeric/Prob/Simplex.h>
50 
51 namespace bpp
52 {
57  public virtual FrequenciesSet
58 {
59 public:
60 #ifndef NO_VIRTUAL_COV
61  CodonFrequenciesSet* clone() const = 0;
62 
63  const CodonAlphabet* getAlphabet() const = 0;
64 #endif
65 
66 public:
70  virtual const GeneticCode* getGeneticCode() const = 0;
71 
93  static FrequenciesSet* getFrequenciesSetForCodons(short option, const GeneticCode* gCode, const std::string& mgmtStopFreq = "quadratic", unsigned short method = 1);
94 
95  static const short F0;
96  static const short F1X4;
97  static const short F3X4;
98  static const short F61;
99 };
100 
101 
109  public virtual CodonFrequenciesSet,
111 {
112 protected:
113  const GeneticCode* pgc_;
114 
115 private:
121  Simplex sFreq_;
122 
123 public:
128  FullCodonFrequenciesSet(const GeneticCode* gCode, bool allowNullFreqs = false, unsigned short method = 1, const std::string& name = "Full");
129  FullCodonFrequenciesSet(const GeneticCode* gCode, const std::vector<double>& initFreqs, bool allowNullFreqs = false, unsigned short method = 1, const std::string& name = "Full");
130 
133 
134 #ifndef NO_VIRTUAL_COV
136 #else
137  Clonable*
138 #endif
139  clone() const { return new FullCodonFrequenciesSet(*this); }
140 
141 public:
142  const GeneticCode* getGeneticCode() const { return pgc_; }
143 
149  void setFrequencies(const std::vector<double>& frequencies);
150 
151 #ifndef NO_VIRTUAL_COV
152  const CodonAlphabet* getAlphabet() const
153  {
154  return dynamic_cast<const CodonAlphabet*>(AbstractFrequenciesSet::getAlphabet());
155  }
156 #endif
157 
158  void setNamespace(const std::string& nameSpace);
159 
160  unsigned short getMethod() const
161  {
162  return sFreq_.getMethod();
163  }
164 
165 protected:
166  void fireParameterChanged(const ParameterList& parameters);
167 
168  void updateFreq_();
169 };
170 
171 
178  public virtual CodonFrequenciesSet,
180 {
181 protected:
182  const GeneticCode* pgc_;
183 
184 public:
185  FixedCodonFrequenciesSet(const GeneticCode* gCode, const std::vector<double>& initFreqs, const std::string& name = "Fixed");
186 
191  FixedCodonFrequenciesSet(const GeneticCode* gCode, const std::string& name = "Fixed");
192 
195  pgc_(fcfs.pgc_)
196  {}
197 
199  {
201  pgc_ = fcfs.pgc_;
202  return *this;
203  }
204 
205 #ifndef NO_VIRTUAL_COV
207 #else
208  Clonable*
209 #endif
210  clone() const { return new FixedCodonFrequenciesSet(*this); }
211 
212 public:
213  const GeneticCode* getGeneticCode() const { return pgc_; }
214 
215 #ifndef NO_VIRTUAL_COV
216  const CodonAlphabet* getAlphabet() const
217  {
218  return dynamic_cast<const CodonAlphabet*>(AbstractFrequenciesSet::getAlphabet());
219  }
220 #endif
221 
226  void setFrequencies(const std::vector<double>& frequencies);
227 
228 protected:
229  void fireParameterChanged(const ParameterList& parameters) {}
230 };
231 
247  public virtual CodonFrequenciesSet,
249 {
250 private:
251  const GeneticCode* pgc_;
252  std::auto_ptr<ProteinFrequenciesSet> ppfs_;
253 
254  /*
255  *@ brief vector of the simplexes, one for each AA
256  *
257  */
258 
259  std::vector<Simplex> vS_;
260 
261  void updateFrequencies();
262 
263 public:
273  FullPerAACodonFrequenciesSet(const GeneticCode* gencode, ProteinFrequenciesSet* ppfs, unsigned short method = 1);
274 
282  FullPerAACodonFrequenciesSet(const GeneticCode* gencode, unsigned short method = 1);
283 
285 
287 
289 
290 #ifndef NO_VIRTUAL_COV
292 #else
293  Clonable*
294 #endif
295  clone() const { return new FullPerAACodonFrequenciesSet(*this); }
296 
297 public:
298 #ifndef NO_VIRTUAL_COV
299  const CodonAlphabet* getAlphabet() const
300  {
301  return dynamic_cast<const CodonAlphabet*>(AbstractFrequenciesSet::getAlphabet());
302  }
303 #endif
304 
305  const GeneticCode* getGeneticCode() const { return pgc_; }
306 
312  void setFrequencies(const std::vector<double>& frequencies);
313 
314  void setNamespace(const std::string& prefix);
315 
317  {
318  return ppfs_.get();
319  }
320 
321  unsigned short getMethod() const
322  {
323  return vS_.size() > 0 ? vS_[0].getMethod() : static_cast<unsigned short>(1);
324  }
325 
326 protected:
327  void fireParameterChanged(const ParameterList& parameters);
328 };
329 
330 
339  public virtual CodonFrequenciesSet,
341 {
342 private:
343  // a map associating stop codons numbers with numbers of neighbour non-stop codons
344  std::map<int, Vint> mStopNeigh_;
345 
346  unsigned short mgmtStopFreq_;
347 
348  const GeneticCode* pgc_;
349 
350 public:
370  CodonFromIndependentFrequenciesSet(const GeneticCode* gCode, const std::vector<FrequenciesSet*>& freqvector, const std::string& name = "Codon", const std::string& mgmtStopFreq = "quadratic");
371 
373 
375 
377 
379 
380  const CodonAlphabet* getAlphabet() const;
381 
382  const GeneticCode* getGeneticCode() const { return pgc_; }
383 
387  void updateFrequencies();
388 };
389 
390 
400  public virtual CodonFrequenciesSet,
402 {
403 private:
404  // a map associating stop codons numbers with numbers of neighbour non-stop codons
405  std::map<int, Vint> mStopNeigh_;
406 
407  unsigned short mgmtStopFreq_;
408 
409  const GeneticCode* pgc_;
410 
411 public:
431  const GeneticCode* gCode,
432  FrequenciesSet* pfreq,
433  const std::string& name = "Codon",
434  const std::string& mgmtStopFreq = "quadratic");
435 
437 
439 
441 
443 
444  const CodonAlphabet* getAlphabet() const;
445 
446  const GeneticCode* getGeneticCode() const { return pgc_; }
447 
452  void updateFrequencies();
453 };
454 } // end of namespace bpp.
455 
456 #endif // _CODONFREQUENCIESSET_H_
const GeneticCode * getGeneticCode() const
A generic FrequenciesSet for Full Codon alphabets.
FixedCodonFrequenciesSet * clone() const
void setNamespace(const std::string &prefix)
CodonFromUniqueFrequenciesSet & operator=(const CodonFromUniqueFrequenciesSet &iwfs)
const CodonAlphabet * getAlphabet() const
const CodonAlphabet * getAlphabet() const =0
FixedCodonFrequenciesSet & operator=(const FixedCodonFrequenciesSet &fcfs)
FullCodonFrequenciesSet(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 ...
the Frequencies in codons are the product of Independent Frequencies in letters with the frequencies ...
FrequenciesSet integrating ProteinFrequenciesSet inside CodonFrequenciesSet. In this case...
CodonFromIndependentFrequenciesSet(const GeneticCode *gCode, const std::vector< FrequenciesSet *> &freqvector, const std::string &name="Codon", const std::string &mgmtStopFreq="quadratic")
Constructor from a CodonAlphabet* and a vector of different FrequenciesSet*. Throws an Exception if t...
FullPerAACodonFrequenciesSet & operator=(const FullPerAACodonFrequenciesSet &ffs)
CodonFromUniqueFrequenciesSet(const GeneticCode *gCode, FrequenciesSet *pfreq, const std::string &name="Codon", const std::string &mgmtStopFreq="quadratic")
Constructor from a CodonAlphabet* and a FrequenciesSet* repeated three times.
void setFrequencies(const std::vector< double > &frequencies)
the given frequencies are normalized such thaat the sum of the frequencies on the non-stop codons equ...
FixedCodonFrequenciesSet(const GeneticCode *gCode, const std::vector< double > &initFreqs, const std::string &name="Fixed")
void setFrequencies(const std::vector< double > &frequencies)
the given frequencies are normalized such that the sum of the frequencies on the non-stop codons equa...
void fireParameterChanged(const ParameterList &parameters)
Parametrize a set of state frequencies.
CodonFromUniqueFrequenciesSet * clone() const
FullPerAACodonFrequenciesSet * clone() const
Parametrize a set of state frequencies for codons.
FixedCodonFrequenciesSet(const FixedCodonFrequenciesSet &fcfs)
CodonFromIndependentFrequenciesSet & operator=(const CodonFromIndependentFrequenciesSet &iwfs)
void fireParameterChanged(const ParameterList &parameters)
const ProteinFrequenciesSet * getProteinFrequenciesSet() const
const CodonAlphabet * getAlphabet() const
const Alphabet * getAlphabet() const
FrequenciesSet useful for homogeneous and stationary models, codon implementation.
CodonFromIndependentFrequenciesSet * clone() const
Parametrize a set of state frequencies for proteins.
const CodonAlphabet * getAlphabet() const
void updateFrequencies()
Update the frequencies given the parameters.
const GeneticCode * getGeneticCode() const
FullCodonFrequenciesSet & operator=(const FullCodonFrequenciesSet &fcfs)
FullPerAACodonFrequenciesSet(const GeneticCode *gencode, ProteinFrequenciesSet *ppfs, unsigned short method=1)
Create a new FullPerAACodonFrequenciesSet object.
void setFrequencies(const std::vector< double > &frequencies)
the given frequencies are normalized such thaat the sum of the frequencies on the non-stop codons equ...
void fireParameterChanged(const ParameterList &parameters)
static FrequenciesSet * getFrequenciesSetForCodons(short option, const GeneticCode *gCode, const std::string &mgmtStopFreq="quadratic", unsigned short method=1)
A helper function that provide frequencies set for codon models according to PAML option...
FullCodonFrequenciesSet * clone() const
void setNamespace(const std::string &nameSpace)
const CodonAlphabet * getAlphabet() const
unsigned short getMethod() const
const GeneticCode * getGeneticCode() const
the Frequencies in words are the product of Independent Frequencies in letters
const GeneticCode * getGeneticCode() const
virtual const GeneticCode * getGeneticCode() const =0
const GeneticCode * getGeneticCode() const
AbstractFrequenciesSet & operator=(const AbstractFrequenciesSet &af)
Simplex sFreq_
Simplex to handle the probabilities and the parameters.
std::auto_ptr< ProteinFrequenciesSet > ppfs_
the Frequencies in codons are the product of the frequencies for a unique FrequenciesSet in letters...
Basic implementation of the FrequenciesSet interface.
CodonFrequenciesSet * clone() const =0
const CodonAlphabet * getAlphabet() const