bpp-phyl3 3.0.0
YNGP_M7.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
9#include "../MixtureOfASubstitutionModel.h"
10#include "YN98.h"
11#include "YNGP_M7.h"
12
13using namespace bpp;
14using namespace std;
15
16/******************************************************************************/
17
18YNGP_M7::YNGP_M7(
19 std::shared_ptr<const GeneticCode> gc,
20 std::unique_ptr<CodonFrequencySetInterface> codonFreqs,
21 unsigned int nclass) :
23 AbstractWrappedModel("YNGP_M7."),
27 YNGP_M("YNGP_M7.")
28{
29 if (nclass <= 0)
30 throw Exception("Bad number of classes for model YNGP_M7: " + TextTools::toString(nclass));
31
32 // build the submodel
33
34 auto pbdd = make_unique<BetaDiscreteDistribution>(nclass, 2, 2, AbstractDiscreteDistribution::DISCRETIZATION_EQUAL_PROB_WHEN_POSSIBLE);
35
36 map<string, unique_ptr<DiscreteDistributionInterface>> mpdd;
37 mpdd["omega"] = std::move(pbdd);
38
39 auto yn98 = make_unique<YN98>(gc, std::move(codonFreqs));
40 yn98->setConstraint("omega", make_shared<IntervalConstraint>(0, 1000, true, true, 0.));
41
42 mixedModelPtr_.reset(new MixtureOfASubstitutionModel(gc->getSourceAlphabet(), std::move(yn98), mpdd));
44
45 vector<int> supportedChars = mixedModelPtr_->getAlphabetStates();
46
47 // mapping the parameters
48
49 ParameterList pl = mixedModelPtr_->getParameters();
50 for (size_t i = 0; i < pl.size(); ++i)
51 {
53 }
54
55 vector<std::string> v = dynamic_cast<const YN98&>(mixedModelPtr_->nModel(0)).frequencySet().getParameters().getParameterNames();
56
57 for (auto& vi : v)
58 {
59 mapParNamesFromPmodel_[vi] = vi.substr(5);
60 }
61
62 mapParNamesFromPmodel_["YN98.kappa"] = "kappa";
63 mapParNamesFromPmodel_["YN98.omega_Beta.alpha"] = "p";
64 mapParNamesFromPmodel_["YN98.omega_Beta.beta"] = "q";
65
66 // specific parameters
67
68 string st;
69 for (auto& it : mapParNamesFromPmodel_)
70 {
71 st = mixedModelPtr_->getParameterNameWithoutNamespace(it.first);
72 addParameter_(new Parameter("YNGP_M7." + it.second, mixedModelPtr_->getParameterValue(st),
73 mixedModelPtr_->parameter(st).hasConstraint() ? shared_ptr<ConstraintInterface>(mixedModelPtr_->parameter(st).getConstraint()->clone()) : 0));
74 }
75
76 // look for synonymous codons
77 for (synfrom_ = 1; synfrom_ < supportedChars.size(); ++synfrom_)
78 {
79 for (synto_ = 0; synto_ < synfrom_; ++synto_)
80 {
81 if (gc->areSynonymous(supportedChars[synfrom_], supportedChars[synto_])
84 break;
85 }
86 if (synto_ < synfrom_)
87 break;
88 }
89
90 if (synto_ == supportedChars.size())
91 throw Exception("Impossible to find synonymous codons");
92
93 // update Matrices
94
95 computeFrequencies(false);
97}
98
100{
102
103 // homogeneization of the synonymous substitution rates
104
105 Vdouble vd;
106
107 for (unsigned int i = 0; i < mixedModelPtr_->getNumberOfModels(); ++i)
108 {
109 vd.push_back(1 / mixedSubModelPtr_->subNModel(i).Qij(synfrom_, synto_));
110 }
111
112 mixedModelPtr_->setVRates(vd);
113}
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_.
static short DISCRETIZATION_EQUAL_PROB_WHEN_POSSIBLE
void addParameter_(Parameter *parameter)
Abstract class of Wrapping model class, where all methods are redirected from model().
const SubstitutionModelInterface & subNModel(size_t i) const
size_t size() const
virtual std::vector< std::string > getParameterNames() const
virtual void addParameter(const Parameter &param)
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_M7.cpp:99
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
std::string toString(T t)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble