bpp-phyl3 3.0.0
AbstractCodonFitnessSubstitutionModel.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
6using namespace bpp;
7using namespace std;
8
9/****************************************************************************************/
10
11AbstractCodonFitnessSubstitutionModel::AbstractCodonFitnessSubstitutionModel(
12 std::unique_ptr<FrequencySetInterface> pfitset,
13 std::shared_ptr<const GeneticCode> pgencode,
14 const string& prefix) :
16 pfitset_(std::move(pfitset)),
17 pgencode_(pgencode),
18 fitName_("")
19{
20 if (!dynamic_cast<CodonFrequencySetInterface*>(pfitset_.get()))
21 throw Exception("Bad type for fitness parameters" + pfitset_->getName());
22 fitName_ = "fit_" + pfitset_->getNamespace();
23 pfitset_->setNamespace(prefix + fitName_);
24 addParameters_(pfitset_->getParameters());
25}
26/****************************************************************************************/
27
29
30/****************************************************************************************/
31
33{
34 pfitset_->matchParametersValues(parameters);
35}
36
37/****************************************************************************************/
38
39void AbstractCodonFitnessSubstitutionModel::setFreq(map<int, double>& frequencies)
40{
41 pfitset_->setFrequenciesFromAlphabetStatesFrequencies(frequencies);
42 matchParametersValues(pfitset_->getParameters() );
43}
44
45/****************************************************************************************/
46
48{
49 double mu;
50
51 double phi_j = pfitset_->getFrequencies() [j];
52 double phi_i = pfitset_->getFrequencies() [i];
53
54 if (phi_i == phi_j)
55 mu = 1;
56 else if (phi_i == 0)
57 mu = 100;
58 else if (phi_j == 0)
59 mu = 0;
60 else
61 mu = -(log(phi_i / phi_j) / (1 - (phi_i / phi_j)));
62 return mu;
63}
64
65/****************************************************************************************/
void setFreq(std::map< int, double > &frequencies) override
void fireParameterChanged(const ParameterList &parameters) override
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 addParameters_(const ParameterList &parameters)
bool matchParametersValues(const ParameterList &parameters) override
Parametrize a set of state frequencies for codons.
Defines the basic types of data flow nodes.
double log(const ExtendedFloat &ef)