bpp-phyl3 3.0.0
AbstractCodonDistanceSubstitutionModel.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
8
9using namespace bpp;
10using namespace std;
11
12/******************************************************************************/
13
14AbstractCodonDistanceSubstitutionModel::AbstractCodonDistanceSubstitutionModel(
15 std::shared_ptr<const AlphabetIndex2> pdist,
16 std::shared_ptr<const GeneticCode> pgencode,
17 const string& prefix,
18 bool paramSynRate) :
20 pdistance_(pdist),
21 pgencode_(pgencode),
22 alpha_(10000),
23 beta_(1),
24 gamma_(1),
25 stateMap_(new CanonicalStateMap(pgencode->getSourceAlphabet(), false))
26{
27 if (pdistance_)
28 addParameter_(new Parameter(prefix + "alpha", 10000, Parameter::R_PLUS_STAR));
29
30 if (paramSynRate)
31 addParameter_(new Parameter(prefix + "gamma", 1, std::make_shared<IntervalConstraint>(NumConstants::SMALL(), 999, true, true)));
32
33 addParameter_(new Parameter(prefix + "beta", 1, Parameter::R_PLUS_STAR));
34}
35
37{
38 if (pdistance_)
39 alpha_ = getParameterValue("alpha");
40
41 if (hasParameter("gamma"))
42 gamma_ = getParameterValue("gamma");
43 beta_ = getParameterValue("beta");
44}
45
47{
48 int si(stateMap_->getAlphabetStateAsInt(i)), sj(stateMap_->getAlphabetStateAsInt(j));
49
50 return pgencode_->areSynonymous(si, sj) ? gamma_ :
51 beta_ * (pdistance_ ? exp(-pdistance_->getIndex(
52 pgencode_->translate(si),
53 pgencode_->translate(sj)) / alpha_) : 1);
54}
double getCodonsMulRate(size_t i, size_t j) const override
Returns the multiplicative rate specific to two codons specified by their number. The respective gene...
void fireParameterChanged(const ParameterList &parameters) override
void addParameter_(Parameter *parameter)
bool hasParameter(const std::string &name) const override
double getParameterValue(const std::string &name) const override
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:168
static double SMALL()
static const std::shared_ptr< IntervalConstraint > R_PLUS_STAR
Defines the basic types of data flow nodes.
ExtendedFloat exp(const ExtendedFloat &ef)