bpp-phyl  2.2.0
WAG01.cpp
Go to the documentation of this file.
1 //
2 // File: WAG01.cpp
3 // Created by: Laurent Gueguen
4 // Created on: mardi 28 septembre 2010, à 14h 43
5 //
6 
7 /*
8 Copyright or © 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 #include "WAG01.h"
41 
42 //From SeqLib:
43 #include <Bpp/Seq/Container/SequenceContainerTools.h>
44 
45 using namespace bpp;
46 using namespace std;
47 
48 /******************************************************************************/
49 
50 WAG01::WAG01(const ProteicAlphabet* alpha) :
51  AbstractParameterAliasable("WAG01."),
52  AbstractReversibleSubstitutionModel(alpha, new CanonicalStateMap(alpha, false), "WAG01."),
53  freqSet_(0)
54 {
55  #include "__WAG01ExchangeabilityCode"
56  #include "__WAG01FrequenciesCode"
58  updateMatrices();
59 }
60 
61 WAG01::WAG01(const ProteicAlphabet* alpha, ProteinFrequenciesSet* freqSet, bool initFreqs) :
62  AbstractParameterAliasable("WAG01+F."),
63  AbstractReversibleSubstitutionModel(alpha, new CanonicalStateMap(alpha, false), "WAG01+F."),
64  freqSet_(freqSet)
65 {
66  #include "__WAG01ExchangeabilityCode"
67  #include "__WAG01FrequenciesCode"
68  freqSet_->setNamespace("WAG01+F."+freqSet_->getNamespace());
69  if (initFreqs) freqSet_->setFrequencies(freq_);
70  else freq_ = freqSet_->getFrequencies();
71  addParameters_(freqSet_->getParameters());
72  updateMatrices();
73 }
74 
75 /******************************************************************************/
76 
77 void WAG01::setFreqFromData(const SequenceContainer& data, double pseudoCount)
78 {
79  map<int, int> counts;
80  SequenceContainerTools::getCounts(data, counts);
81  double t = 0;
82  for (int i = 0; i < static_cast<int>(size_); i++)
83  {
84  t += (counts[i] + pseudoCount);
85  }
86  for (size_t i = 0; i < size_; ++i) freq_[i] = (static_cast<double>(counts[static_cast<int>(i)]) + pseudoCount) / t;
88  //Update parameters and re-compute generator and eigen values:
89  matchParametersValues(freqSet_->getParameters());
90 }
91 
92 /******************************************************************************/
93 
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:161
virtual void setFrequencies(const std::vector< double > &frequencies)=0
Set the parameters in order to match a given set of frequencies.
FrequenciesSet useful for homogeneous and stationary models, protein implementation.
STL namespace.
virtual const std::vector< double > getFrequencies() const =0
Vdouble freq_
The vector of equilibrium frequencies.
virtual void updateMatrices()
Compute and diagonalize the matrix, and fill the eigenValues_, leftEigenVectors_ and rightEigenVecto...
Partial implementation of the ReversibleSubstitutionModel interface.
Parametrize a set of state frequencies for proteins.
void setFreqFromData(const SequenceContainer &data, double pseudoCount=0)
Set equilibrium frequencies equal to the frequencies estimated from the data.
Definition: WAG01.cpp:77
WAG01(const ProteicAlphabet *alpha)
Build a simple WAG01 model, with original equilibrium frequencies.
Definition: WAG01.cpp:50
ProteinFrequenciesSet * freqSet_
Definition: WAG01.h:76
size_t size_
The size of the generator, i.e. the number of states.