bpp-phyl  2.2.0
AbstractCodonPhaseFrequenciesSubstitutionModel.cpp
Go to the documentation of this file.
1 //
2 // File: AbstractCodonPhaseFrequenciesSubstitutionModel.cpp
3 // Created by: Laurent Gueguen
4 // Created on: vendredi 23 septembre 2011, à 16h 29
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9  This software is a computer program whose purpose is to provide classes
10  for phylogenetic data analysis.
11 
12  This software is governed by the CeCILL license under French law and
13  abiding by the rules of distribution of free software. You can use,
14  modify and/ or redistribute the software under the terms of the CeCILL
15  license as circulated by CEA, CNRS and INRIA at the following URL
16  "http://www.cecill.info".
17 
18  As a counterpart to the access to the source code and rights to copy,
19  modify and redistribute granted by the license, users are provided only
20  with a limited warranty and the software's author, the holder of the
21  economic rights, and the successive licensors have only limited
22  liability.
23 
24  In this respect, the user's attention is drawn to the risks associated
25  with loading, using, modifying and/or developing or reproducing the
26  software by the user in light of its specific status of free software,
27  that may mean that it is complicated to manipulate, and that also
28  therefore means that it is reserved for developers and experienced
29  professionals having in-depth computer knowledge. Users are therefore
30  encouraged to load and test the software's suitability as regards their
31  requirements in conditions enabling the security of their systems and/or
32  data to be ensured and, more generally, to use and operate it in the
33  same conditions as regards security.
34 
35  The fact that you are presently reading this means that you have had
36  knowledge of the CeCILL license and that you accept its terms.
37  */
38 
40 #include "../FrequenciesSet/NucleotideFrequenciesSet.h"
41 
42 using namespace bpp;
43 
44 using namespace std;
45 
46 /******************************************************************************/
47 
49  FrequenciesSet* pfreq,
50  const std::string& prefix) :
52  AbstractParameterAliasable(prefix),
53  posfreqset_(),
54  freqName_("")
55 {
56  CodonFrequenciesSet* pCFS = dynamic_cast<CodonFrequenciesSet*>(pfreq);
57  if (!pCFS)
58  throw Exception("Bad type for equilibrium frequencies " + pfreq->getName());
59 
60  if (dynamic_cast<CodonFromUniqueFrequenciesSet*>(pCFS)
61  || dynamic_cast<CodonFromIndependentFrequenciesSet*>(pCFS))
62  posfreqset_ = dynamic_cast<WordFrequenciesSet*>(pfreq)->clone();
63  else
64  {
65  vector<FrequenciesSet*> vFS;
66  if (dynamic_cast<FixedCodonFrequenciesSet*>(pCFS)) {
67  for (unsigned int i = 0; i < 3; i++)
68  {
69  vFS.push_back(new FixedNucleotideFrequenciesSet(pCFS->getAlphabet()->getNucleicAlphabet()));
70  }
71  } else {
72  for (unsigned int i = 0; i < 3; i++)
73  {
74  vFS.push_back(new FullNucleotideFrequenciesSet(pCFS->getAlphabet()->getNucleicAlphabet()));
75  }
76  }
78  pCFS->getGeneticCode(),
79  vFS, "");
80 
82  }
83 
84  freqName_ = pfreq->getNamespace();
85  posfreqset_->setNamespace(prefix + pfreq->getNamespace());
86  // if (dynamic_cast<FixedCodonFrequenciesSet*>(pCFS)!=NULL)
87  addParameters_(posfreqset_->getParameters());
88 }
89 
91 {
92  if (posfreqset_)
93  delete posfreqset_;
94 }
95 
97 {
98  posfreqset_->matchParametersValues(parameters);
99 }
100 
101 
103 {
105  matchParametersValues(posfreqset_->getParameters());
106 }
107 
109 {
110  size_t i2(i), j2(j);
111 
112  double x = 1.;
113  for (size_t k = 0; k < 3; k++)
114  {
115  if ((i2 % 4) != (j2 % 4))
117  i2 /= 4;
118  j2 /= 4;
119  }
120  return x;
121 }
122 
virtual const FrequenciesSet & getFrequenciesSetForLetter(size_t i) const =0
WordFrequenciesSet * posfreqset_
Position dependent version of Codon Frequencies Set.
const CodonAlphabet * getAlphabet() const =0
the Frequencies in codons are the product of Independent Frequencies in letters with the frequencies ...
virtual void setFrequencies(const std::vector< double > &frequencies)=0
Set the parameters in order to match a given set of frequencies.
STL namespace.
virtual const std::vector< double > getFrequencies() const =0
Parametrize a set of state frequencies.
Parametrize a set of state frequencies for codons.
Frequencies in words computed from the frequencies on letters. The parameters are the parameters of t...
Nucleotide FrequenciesSet using three independent parameters (theta, theta1, theta2) to modelize the ...
virtual std::string getName() const =0
FrequenciesSet useful for homogeneous and stationary models, nucleotide implementation.
void setFreq(std::map< int, double > &frequencies)
Set equilibrium frequencies.
AbstractCodonPhaseFrequenciesSubstitutionModel(FrequenciesSet *pfreq, const std::string &prefix)
Build a AbstractCodonPhaseFrequenciesSubstitutionModel instance.
virtual void setFrequenciesFromAlphabetStatesFrequencies(const std::map< int, double > &frequencies)=0
Set the Frequencies from the one of the map which keys match with a letter of the Alphabet...
Abstract class for codon models.
virtual const GeneticCode * getGeneticCode() const =0
virtual CodonSubstitutionModel * clone() const =0
double getCodonsMulRate(size_t, size_t) const
Returns the multiplicative rate specific to two codons specified by their number. The respective gene...