bpp-phyl3 3.0.0
TripletSubstitutionModel.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
8
10
11// From SeqLib:
14
15using namespace bpp;
16
17// From the STL:
18#include <cmath>
19
20using namespace std;
21
22/******************************************************************************/
23
24TripletSubstitutionModel::TripletSubstitutionModel(
25 std::shared_ptr<const CodonAlphabet> palph,
26 std::unique_ptr<NucleotideSubstitutionModelInterface> pmod) :
28 WordSubstitutionModel(palph, make_shared<CanonicalStateMap>(palph, false), "Triplet.")
29{
30 unsigned int i;
31 addParameters_(pmod->getParameters());
32
33 Vrate_.resize(3);
34 for (i = 0; i < 3; i++)
35 {
36 VSubMod_.push_back(std::move(pmod));
37 VnestedPrefix_.push_back(VSubMod_[i]->getNamespace());
38 Vrate_[i] = 1. / 3.;
39 }
40
41 // relative rates
42 for (i = 0; i < 2; i++)
43 {
44 addParameter_(new Parameter("Triplet.relrate" + TextTools::toString(i + 1), 1.0 / (3 - i), Parameter::PROP_CONSTRAINT_EX));
45 }
46
48}
49
51 std::shared_ptr<const CodonAlphabet> palph,
52 std::unique_ptr<NucleotideSubstitutionModelInterface> pmod1,
53 std::unique_ptr<NucleotideSubstitutionModelInterface> pmod2,
54 std::unique_ptr<NucleotideSubstitutionModelInterface> pmod3) :
56 WordSubstitutionModel(palph, make_shared<CanonicalStateMap>(palph, false), "Triplet.")
57{
58 string st = "Triplet.";
59
60 VSubMod_.push_back(std::move(pmod1));
61 VnestedPrefix_.push_back(VSubMod_[0]->getNamespace());
62 VSubMod_[0]->setNamespace(st + "1_" + VnestedPrefix_[0]);
64
65 VSubMod_.push_back(std::move(pmod2));
66 VnestedPrefix_.push_back(VSubMod_[1]->getNamespace());
67 VSubMod_[1]->setNamespace(st + "2_" + VnestedPrefix_[1]);
69
70 VSubMod_.push_back(std::move(pmod3));
71 VnestedPrefix_.push_back(VSubMod_[2]->getNamespace());
72 VSubMod_[2]->setNamespace(st + "3_" + VnestedPrefix_[2]);
74
75 Vrate_.resize(3);
76 for (unsigned int i = 0; i < 3; ++i)
77 {
78 Vrate_[i] = 1.0 / 3;
79 }
80
81 // relative rates
82 for (unsigned int i = 0; i < 2; ++i)
83 {
84 addParameter_(new Parameter(st + "relrate" + TextTools::toString(i + 1), 1.0 / (3 - i), Parameter::PROP_CONSTRAINT_EX));
85 }
86
88}
89
91{
92 string s = "TripletSubstitutionModel model:";
93 for (auto& vi : VSubMod_)
94 {
95 s += " " + vi->getName();
96 }
97
98 return s;
99}
void addParameters_(const ParameterList &parameters)
void addParameter_(Parameter *parameter)
std::string getNamespace() const override
const ParameterList & getParameters() const override
std::vector< std::shared_ptr< SubstitutionModelInterface > > VSubMod_
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
std::string getName() const override
Get the name of the model.
TripletSubstitutionModel(std::shared_ptr< const CodonAlphabet > palph, std::unique_ptr< NucleotideSubstitutionModelInterface > pmod)
Build a new TripletSubstitutionModel object from a pointer to a NucleotideSubstitutionModel.
Basal class for words of substitution models.
virtual void updateMatrices_() override
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
std::string toString(T t)
Defines the basic types of data flow nodes.