bpp-phyl3 3.0.0
GTR.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
6
7#include "../FrequencySet/NucleotideFrequencySet.h"
8#include "GTR.h"
9
10// From the STL:
11#include <cmath>
12
13using namespace bpp;
14using namespace std;
15
16/******************************************************************************/
17
18GTR::GTR(
19 shared_ptr<const NucleicAlphabet> alpha,
20 double a,
21 double b,
22 double c,
23 double d,
24 double e,
25 double piA,
26 double piC,
27 double piG,
28 double piT) :
30 AbstractReversibleNucleotideSubstitutionModel(alpha, make_shared<CanonicalStateMap>(alpha, false), "GTR."),
31 a_(a), b_(b), c_(c), d_(d), e_(e), piA_(piA), piC_(piC), piG_(piG), piT_(piT), theta_(piG + piC), theta1_(piA / (1. - theta_)), theta2_(piG / theta_), p_()
32{
42}
43
44/******************************************************************************/
45
47{
48 a_ = getParameterValue("a");
49 b_ = getParameterValue("b");
50 c_ = getParameterValue("c");
51 d_ = getParameterValue("d");
52 e_ = getParameterValue("e");
53 theta_ = getParameterValue("theta");
54 theta1_ = getParameterValue("theta1");
55 theta2_ = getParameterValue("theta2");
56 piA_ = theta1_ * (1. - theta_);
57 piC_ = (1. - theta2_) * theta_;
59 piT_ = (1. - theta1_) * (1. - theta_);
60 p_ = 2 * (a_ * piC_ * piT_ + b_ * piA_ * piT_ + c_ * piG_ * piT_ + d_ * piA_ * piC_ + e_ * piC_ * piG_ + piA_ * piG_);
61
62 freq_[0] = piA_;
63 freq_[1] = piC_;
64 freq_[2] = piG_;
65 freq_[3] = piT_;
66
67 // Exchangeability matrix:
68 exchangeability_(0, 0) = (-b_ * piT_ - piG_ - d_ * piC_) / (piA_ * p_);
69 exchangeability_(1, 0) = d_ / p_;
70 exchangeability_(0, 1) = d_ / p_;
71 exchangeability_(2, 0) = 1 / p_;
72 exchangeability_(0, 2) = 1 / p_;
73 exchangeability_(3, 0) = b_ / p_;
74 exchangeability_(0, 3) = b_ / p_;
75 exchangeability_(1, 1) = (-a_ * piT_ - e_ * piG_ - d_ * piA_) / (piC_ * p_);
76 exchangeability_(1, 2) = e_ / p_;
77 exchangeability_(2, 1) = e_ / p_;
78 exchangeability_(1, 3) = a_ / p_;
79 exchangeability_(3, 1) = a_ / p_;
80 exchangeability_(2, 2) = (-c_ * piT_ - e_ * piC_ - piA_) / (piG_ * p_);
81 exchangeability_(2, 3) = c_ / p_;
82 exchangeability_(3, 2) = c_ / p_;
83 exchangeability_(3, 3) = (-c_ * piG_ - a_ * piC_ - b_ * piA_) / (piT_ * p_);
84
86}
87
88/******************************************************************************/
89
90void GTR::setFreq(map<int, double>& freqs)
91{
92 piA_ = freqs[0];
93 piC_ = freqs[1];
94 piG_ = freqs[2];
95 piT_ = freqs[3];
96 vector<string> thetas(3);
97 thetas[0] = getNamespace() + "theta";
98 thetas[1] = getNamespace() + "theta1";
99 thetas[2] = getNamespace() + "theta2";
101 pl[0].setValue(piC_ + piG_);
102 pl[1].setValue(piA_ / (piA_ + piT_));
103 pl[2].setValue(piG_ / (piC_ + piG_));
105}
106
107/******************************************************************************/
void addParameter_(Parameter *parameter)
void setParametersValues(const ParameterList &parameters) override
std::string getNamespace() const override
const ParameterList & getParameters() const override
double getParameterValue(const std::string &name) const override
Specialisation abstract class for reversible nucleotide substitution model.
virtual void updateMatrices_() override
Compute and diagonalize the matrix, and fill the eigenValues_, leftEigenVectors_ and rightEigenVecto...
RowMatrix< double > exchangeability_
The exchangeability matrix of the model, defined as . When the model is reversible,...
Vdouble freq_
The vector of equilibrium frequencies.
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:168
static std::shared_ptr< IntervalConstraint > FREQUENCE_CONSTRAINT_SMALL
Definition: FrequencySet.h:90
double piT_
Definition: GTR.h:107
double e_
Definition: GTR.h:107
double theta1_
Definition: GTR.h:107
double piA_
Definition: GTR.h:107
double piC_
Definition: GTR.h:107
double theta2_
Definition: GTR.h:107
double piG_
Definition: GTR.h:107
double p_
Definition: GTR.h:107
double d_
Definition: GTR.h:107
double c_
Definition: GTR.h:107
double theta_
Definition: GTR.h:107
void updateMatrices_() override
Compute and diagonalize the matrix, and fill the eigenValues_, leftEigenVectors_ and rightEigenVecto...
Definition: GTR.cpp:46
double b_
Definition: GTR.h:107
void setFreq(std::map< int, double > &freqs) override
This method is redefined to actualize the corresponding parameters piA, piT, piG and piC too.
Definition: GTR.cpp:90
double a_
Definition: GTR.h:107
virtual ParameterList createSubList(const std::vector< std::string > &names) const
static const std::shared_ptr< IntervalConstraint > R_PLUS_STAR
Defines the basic types of data flow nodes.