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