bpp-phyl3  3.0.0
WAG01.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include "WAG01.h"
6 
7 // From bpp-seq:
9 
10 using namespace bpp;
11 using namespace std;
12 
13 /******************************************************************************/
14 
15 WAG01::WAG01(std::shared_ptr<const ProteicAlphabet> alpha) :
17  AbstractReversibleProteinSubstitutionModel(alpha, make_shared<CanonicalStateMap>(alpha, false), "WAG01."),
18  freqSet_(nullptr)
19 {
20  #include "__WAG01ExchangeabilityCode"
21  #include "__WAG01FrequenciesCode"
22  freqSet_.reset(new FixedProteinFrequencySet(alpha, freq_));
24 }
25 
27  std::shared_ptr<const ProteicAlphabet> alpha,
28  std::unique_ptr<ProteinFrequencySetInterface> freqSet,
29  bool initFreqs) :
30  AbstractParameterAliasable("WAG01+F."),
31  AbstractReversibleProteinSubstitutionModel(alpha, make_shared<CanonicalStateMap>(alpha, false), "WAG01+F."),
32  freqSet_(std::move(freqSet))
33 {
34  #include "__WAG01ExchangeabilityCode"
35  #include "__WAG01FrequenciesCode"
36  freqSet_->setNamespace("WAG01+F." + freqSet_->getNamespace());
37  if (initFreqs)
38  freqSet_->setFrequencies(freq_);
39  else
40  freq_ = freqSet_->getFrequencies();
41  addParameters_(freqSet_->getParameters());
43 }
44 
45 /******************************************************************************/
46 
47 void WAG01::setFreqFromData(const SequenceDataInterface& data, double pseudoCount)
48 {
49  map<int, double> counts;
50  SequenceContainerTools::getFrequencies(data, counts, pseudoCount);
51  for (auto i : counts)
52  {
53  freq_[(size_t)i.first] = i.second;
54  }
55 
56  freqSet_->setFrequencies(freq_);
57  // Update parameters and re-compute generator and eigen values:
58  matchParametersValues(freqSet_->getParameters());
59 }
60 
61 /******************************************************************************/
void addParameters_(const ParameterList &parameters)
bool matchParametersValues(const ParameterList &parameters) override
Specialisation abstract class for reversible protein substitution model.
virtual void updateMatrices_() override
Compute and diagonalize the matrix, and fill the eigenValues_, leftEigenVectors_ and rightEigenVecto...
Vdouble freq_
The vector of equilibrium frequencies.
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:168
FrequencySet useful for homogeneous and stationary models, protein implementation.
static void getFrequencies(const SequenceContainerInterface &sc, std::map< int, double > &f, double pseudoCount=0)
void setFreqFromData(const SequenceDataInterface &data, double pseudoCount=0) override
Set equilibrium frequencies equal to the frequencies estimated from the data.
Definition: WAG01.cpp:47
std::unique_ptr< ProteinFrequencySetInterface > freqSet_
Definition: WAG01.h:38
WAG01(std::shared_ptr< const ProteicAlphabet > alpha)
Build a simple WAG01 model, with original equilibrium frequencies.
Definition: WAG01.cpp:15
Defines the basic types of data flow nodes.