bpp-phyl3 3.0.0
YNGP_M1.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
7
8#include "../MixtureOfASubstitutionModel.h"
9#include "YN98.h"
10#include "YNGP_M1.h"
11
12using namespace bpp;
13using namespace std;
14
15/******************************************************************************/
16
17YNGP_M1::YNGP_M1(
18 shared_ptr<const GeneticCode> gc,
19 unique_ptr<CodonFrequencySetInterface> codonFreqs) :
21 AbstractWrappedModel("YNGP_M1."),
25 YNGP_M("YNGP_M1.")
26{
27 // build the submodel
28
29 vector<double> v1, v2;
30 v1.push_back(0.5); v1.push_back(1);
31 v2.push_back(0.5); v2.push_back(0.5);
32
33 auto psdd = make_unique<SimpleDiscreteDistribution>(v1, v2);
34
35 map<string, unique_ptr<DiscreteDistributionInterface>> mpdd;
36 mpdd["omega"] = std::move(psdd);
37
38 auto yn98 = make_unique<YN98>(gc, std::move(codonFreqs));
39
40 mixedModelPtr_.reset(new MixtureOfASubstitutionModel(gc->getCodonAlphabet(), std::move(yn98), mpdd));
42
43 vector<int> supportedChars = mixedModelPtr_->getAlphabetStates();
44 // map the parameters
45
47
48 vector<std::string> v = dynamic_cast<const YN98&>(mixedModelPtr_->nModel(0)).frequencySet().getParameters().getParameterNames();
49
50 for (auto& vi : v)
51 {
52 mapParNamesFromPmodel_[vi] = vi.substr(5);
53 }
54
55 mapParNamesFromPmodel_["YN98.kappa"] = "kappa";
56 mapParNamesFromPmodel_["YN98.omega_Simple.V1"] = "omega";
57 mapParNamesFromPmodel_["YN98.omega_Simple.theta1"] = "p0";
58
59 // specific parameters
60
61 string st;
62 for (auto it : mapParNamesFromPmodel_)
63 {
64 st = mixedModelPtr_->getParameterNameWithoutNamespace(it.first);
65 if (st != "omega_Simple.V1")
66 {
67 addParameter_(new Parameter("YNGP_M1." + it.second, mixedModelPtr_->getParameterValue(st),
68 mixedModelPtr_->parameter(st).hasConstraint() ? std::shared_ptr<ConstraintInterface>(mixedModelPtr_->parameter(st).getConstraint()->clone()) : 0));
69 }
70 }
71
72 addParameter_(new Parameter("YNGP_M1.omega", 0.5, std::make_shared<IntervalConstraint>(0.002, 1, true, false, 0.002)));
73
74 // look for synonymous codons
75 for (synfrom_ = 1; synfrom_ < supportedChars.size(); ++synfrom_)
76 {
77 for (synto_ = 0; synto_ < synfrom_; ++synto_)
78 {
79 if (gc->areSynonymous(supportedChars[synfrom_], supportedChars[synto_])
82 break;
83 }
84 if (synto_ < synfrom_)
85 break;
86 }
87
88 if (synto_ == supportedChars.size())
89 throw Exception("Impossible to find synonymous codons");
90
91 // update matrice
92
93 computeFrequencies(false);
95}
96
98{
100
101 // homogeneization of the synonymous substitution rates
102
103 Vdouble vd;
104
105 vd.push_back(1. / mixedSubModelPtr_->subNModel(0).Qij(synfrom_, synto_));
106 vd.push_back(1. / mixedSubModelPtr_->subNModel(1).Qij(synfrom_, synto_));
107
108 mixedModelPtr_->setVRates(vd);
109}
const MixedTransitionModelInterface & mixedModel() const
std::unique_ptr< MixedTransitionModelInterface > mixedModelPtr_
const FrequencySetInterface & frequencySet() const override
Partial implementation of the SubstitutionModel interface for models that are set for matching the bi...
std::map< std::string, std::string > mapParNamesFromPmodel_
Tools to make the link between the Parameters of the object and those of pmixmodel_.
void addParameter_(Parameter *parameter)
Abstract class of Wrapping model class, where all methods are redirected from model().
const SubstitutionModelInterface & subNModel(size_t i) const
virtual void addParameters(const ParameterList &params)
virtual std::vector< std::string > getParameterNames() const
virtual const ParameterList & getParameters() const=0
virtual double Qij(size_t i, size_t j) const =0
A method for computing all necessary matrices.
virtual bool computeFrequencies() const =0
The Yang and Nielsen (1998) substitution model for codons.
Definition: YN98.h:57
void updateMatrices_() override
Definition: YNGP_M1.cpp:97
Abstract generic class for The Yang et al (2000) M substitution models for codons....
Definition: YNGP_M.h:32
size_t synto_
Definition: YNGP_M.h:43
const MixtureOfASubstitutionModel * mixedSubModelPtr_
Definition: YNGP_M.h:37
size_t synfrom_
indexes of 2 codons states between which the substitution is synonymous, to set a basis to the homoge...
Definition: YNGP_M.h:43
Defines the basic types of data flow nodes.
std::vector< double > Vdouble