bpp-phyl3 3.0.0
AbstractDFPSubstitutionModel.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
7using namespace bpp;
8using namespace std;
9
10/******************************************************************************/
11
12AbstractDFPSubstitutionModel::AbstractDFPSubstitutionModel(
13 std::shared_ptr<const GeneticCode> gCode,
14 const string& prefix) :
17 gCode->getSourceAlphabet(),
18 std::shared_ptr<const StateMapInterface>(new CanonicalStateMap(gCode->getSourceAlphabet(), false)),
19 prefix),
20 gCode_(gCode),
21 tr_(1), trr_(1), tvv_(1), trv_(1), tsub_(1)
22{
24 addParameter_(new Parameter(prefix + "tr", 1, Parameter::R_PLUS_STAR));
25 addParameter_(new Parameter(prefix + "trr", 1, Parameter::R_PLUS_STAR));
26 addParameter_(new Parameter(prefix + "tvv", 1, Parameter::R_PLUS_STAR));
27 addParameter_(new Parameter(prefix + "trv", 1, Parameter::R_PLUS_STAR));
28 addParameter_(new Parameter(prefix + "tsub", 1, Parameter::R_PLUS_STAR));
29}
30
31/******************************************************************************/
32
34{
35 tr_ = getParameterValue("tr");
36 trr_ = getParameterValue("trr");
37 tvv_ = getParameterValue("tvv");
38 trv_ = getParameterValue("trv");
39 tsub_ = getParameterValue("tsub");
40
42}
43
44/******************************************************************************/
45
47{
48 size_t i, j;
49
50 for (i = 0; i < 64; ++i)
51 {
52 for (j = 0; j < 64; ++j)
53 {
54 if (i == j || gCode_->isStop(static_cast<int>(i)) || gCode_->isStop(static_cast<int>(j)))
55 {
56 generator_(i, j) = 0;
57 }
58 else
59 {
60 generator_(i, j) = getCodonsMulRate(i, j);
61 }
62 }
63 }
64
67}
68
69/******************************************************************************/
70
71double AbstractDFPSubstitutionModel::getCodonsMulRate(size_t i, size_t j) const
72{
73 int nts(0);
74 // sum nb of transitions & transversions between codons
75 // ts = 4 * ntv + ntr
76
77 for (size_t pos = 0; pos < 3; pos++)
78 {
79 int pi = (int) (pos == 0 ? i / 16 :
80 (pos == 1 ? (i / 4) % 4
81 : i % 4));
82 int pj = (int) (pos == 0 ? j / 16 :
83 (pos == 1 ? (j / 4) % 4
84 : j % 4));
85
86 nts += (pi == pj ? 0 : (abs(pi - pj) == 2 ? 1 : 4));
87 }
88
89 switch (nts)
90 {
91 case 0:
92 break;
93 case 1:
94 return tr_;
95 break;
96 case 2:
97 return trr_;
98 break;
99 case 4:
100 return 1;
101 break;
102 case 5:
103 return trv_;
104 break;
105 case 8:
106 return tvv_;
107 break;
108 default:
109 return tsub_;
110 break;
111 }
112
113 return 1.;
114}
115
116/******************************************************************************/
double getCodonsMulRate(size_t i, size_t j) const override
Calls the multiplication by the specific codon-codon rate.
void fireParameterChanged(const ParameterList &parameters) override
Tells the model that a parameter value has changed.
void updateMatrices_() override
Method inherited from AbstractSubstitutionModel.
std::shared_ptr< const GeneticCode > gCode_
void addParameter_(Parameter *parameter)
double getParameterValue(const std::string &name) const override
RowMatrix< double > generator_
The generator matrix of the model.
void setDiagonal()
set the diagonal of the generator such that sum on each line equals 0.
virtual void updateMatrices_()
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
bool enableEigenDecomposition()
Tell if eigenValues and Vectors must be computed.
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:168
static const std::shared_ptr< IntervalConstraint > R_PLUS_STAR
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:25
Defines the basic types of data flow nodes.
ExtendedFloat abs(const ExtendedFloat &ef)