bpp-phyl3  3.0.0
SSR.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 "SSR.h"
8 
9 // From SeqLib:
11 
12 // From the STL:
13 #include <cmath>
14 
15 using namespace bpp;
16 using namespace std;
17 
18 /******************************************************************************/
19 
21  shared_ptr<const NucleicAlphabet> alpha,
22  double beta,
23  double gamma,
24  double delta,
25  double theta) :
27  AbstractReversibleNucleotideSubstitutionModel(alpha, make_shared<CanonicalStateMap>(alpha, false), "SSR."),
28  beta_(beta), gamma_(gamma), delta_(delta), theta_(theta),
29  piA_((1. - theta) / 2.), piC_(theta / 2.), piG_(theta / 2.), piT_((1. - theta) / 2.)
30 {
31  addParameter_(new Parameter("SSR.beta", beta, Parameter::R_PLUS_STAR));
32  addParameter_(new Parameter("SSR.gamma", gamma, Parameter::R_PLUS_STAR));
33  addParameter_(new Parameter("SSR.delta", delta, Parameter::R_PLUS_STAR));
34  addParameter_(new Parameter("SSR.theta", theta, Parameter::PROP_CONSTRAINT_EX));
36 }
37 
38 /******************************************************************************/
39 
41 {
42  beta_ = getParameterValue("beta");
43  gamma_ = getParameterValue("gamma");
44  delta_ = getParameterValue("delta");
45  theta_ = getParameterValue("theta");
46 
47  freq_[0] = piA_ = (1. - theta_) / 2.;
48  freq_[1] = piC_ = theta_ / 2.;
49  freq_[2] = piG_ = theta_ / 2;
50  freq_[3] = piT_ = (1. - theta_) / 2.;
51 
52  // Exchangeability matrix:
53  exchangeability_(0, 0) = -gamma_ * piT_ - piG_ - beta_ * piC_;
54  exchangeability_(1, 0) = beta_;
55  exchangeability_(0, 1) = beta_;
56  exchangeability_(2, 0) = 1.;
57  exchangeability_(0, 2) = 1.;
58  exchangeability_(3, 0) = gamma_;
59  exchangeability_(0, 3) = gamma_;
60  exchangeability_(1, 1) = -piT_ - delta_ * piG_ - beta_ * piA_;
61  exchangeability_(1, 2) = delta_;
62  exchangeability_(2, 1) = delta_;
63  exchangeability_(1, 3) = 1.;
64  exchangeability_(3, 1) = 1.;
65  exchangeability_(2, 2) = -beta_ * piT_ - delta_ * piC_ - piA_;
66  exchangeability_(2, 3) = beta_;
67  exchangeability_(3, 2) = beta_;
68  exchangeability_(3, 3) = -beta_ * piG_ - piC_ - gamma_ * piA_;
69 
71 }
72 
73 /******************************************************************************/
74 
75 void SSR::setFreq(map<int, double>& freqs)
76 {
77  piC_ = freqs[1];
78  piG_ = freqs[2];
79  setParameterValue("theta", piC_ + piG_);
81 }
82 
83 /******************************************************************************/
void addParameter_(Parameter *parameter)
void setParameterValue(const std::string &name, double value) 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 const std::shared_ptr< IntervalConstraint > PROP_CONSTRAINT_EX
static const std::shared_ptr< IntervalConstraint > R_PLUS_STAR
double gamma_
Definition: SSR.h:66
double theta_
Definition: SSR.h:66
double delta_
Definition: SSR.h:66
void setFreq(std::map< int, double > &) override
This method is redefined to actualize the corresponding parameters theta too.
Definition: SSR.cpp:75
double piC_
Definition: SSR.h:66
double piG_
Definition: SSR.h:66
void updateMatrices_() override
Compute and diagonalize the matrix, and fill the eigenValues_, leftEigenVectors_ and rightEigenVecto...
Definition: SSR.cpp:40
SSR(std::shared_ptr< const NucleicAlphabet > alpha, double beta=1., double gamma=1., double delta=1., double theta=0.5)
Definition: SSR.cpp:20
double piA_
Definition: SSR.h:66
double beta_
Definition: SSR.h:66
double piT_
Definition: SSR.h:66
Defines the basic types of data flow nodes.