bpp-phyl3  3.0.0
LG08.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 "LG08.h"
6 
7 // From bpp-seq:
9 
10 using namespace bpp;
11 
12 #include <map>
13 
14 using namespace std;
15 
16 /******************************************************************************/
17 
19  std::shared_ptr<const ProteicAlphabet> alpha) :
21  AbstractReversibleProteinSubstitutionModel(alpha, make_shared<CanonicalStateMap>(alpha, false), "LG08."),
22  freqSet_(nullptr)
23 {
24  #include "__LG08ExchangeabilityCode"
25  #include "__LG08FrequenciesCode"
26  freqSet_.reset(new FixedProteinFrequencySet(alpha, freq_));
28 }
29 
31  std::shared_ptr<const ProteicAlphabet> alpha,
32  std::unique_ptr<ProteinFrequencySetInterface> freqSet,
33  bool initFreqs) :
34  AbstractParameterAliasable("LG08+F."),
35  AbstractReversibleProteinSubstitutionModel(alpha, make_shared<CanonicalStateMap>(alpha, false), "LG08+F."),
36  freqSet_(std::move(freqSet))
37 {
38  #include "__LG08ExchangeabilityCode"
39  #include "__LG08FrequenciesCode"
40  freqSet_->setNamespace("LG08+F." + freqSet_->getNamespace());
41  if (initFreqs)
42  freqSet_->setFrequencies(freq_);
43  else
44  freq_ = freqSet_->getFrequencies();
45 
46  addParameters_(freqSet_->getParameters());
47 
49 }
50 
51 /******************************************************************************/
52 
53 void LG08::setFreqFromData(const SequenceDataInterface& data, double pseudoCount)
54 {
55  map<int, double> counts;
56  SequenceContainerTools::getFrequencies(data, counts, pseudoCount);
57  for (auto i : counts)
58  {
59  freq_[(size_t)i.first] = i.second;
60  }
61 
62  freqSet_->setFrequencies(freq_);
63  // Update parameters and re-compute generator and eigen values:
64  matchParametersValues(freqSet_->getParameters());
65 }
66 
67 /******************************************************************************/
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.
LG08(std::shared_ptr< const ProteicAlphabet > alpha)
Build a simple LG08 model, with original equilibrium frequencies.
Definition: LG08.cpp:18
std::unique_ptr< ProteinFrequencySetInterface > freqSet_
Definition: LG08.h:33
void setFreqFromData(const SequenceDataInterface &data, double pseudoCount=0) override
Set equilibrium frequencies equal to the frequencies estimated from the data.
Definition: LG08.cpp:53
static void getFrequencies(const SequenceContainerInterface &sc, std::map< int, double > &f, double pseudoCount=0)
Defines the basic types of data flow nodes.