bpp-phyl3  3.0.0
AbstractCodonAAFitnessSubstitutionModel.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 
9 using namespace bpp;
10 using namespace std;
11 
12 /****************************************************************************************/
13 
15  std::shared_ptr<FrequencySetInterface> pfitset,
16  std::shared_ptr<const GeneticCode> pgencode,
17  const string& prefix) :
18  AbstractParameterAliasable(prefix), pfitset_(pfitset), pgencode_(pgencode), fitName_(""), stateMap_(new CanonicalStateMap(pgencode->getSourceAlphabet(), false)),
19  protStateMap_(pfitset->getStateMap()), Ns_(1)
20 {
22  throw Exception("AbstractCodonAAFitnessSubstitutionModel::AbstractCodonAAFitnessSubstitutionModel need Proteic Fitness.");
23 
24  fitName_ = "fit_" + pfitset_->getNamespace();
25  pfitset_->setNamespace(prefix + fitName_);
26 
27  addParameters_(pfitset_->getParameters());
28 }
29 
31 {}
32 
34 {
36  if (hasParameter("Ns"))
37  Ns_ = getParameterValue("Ns");
38 
39  pfitset_->matchParametersValues(parameters);
40 }
41 
42 void AbstractCodonAAFitnessSubstitutionModel::setFreq(map<int, double>& frequencies)
43 {
44  pfitset_->setFrequenciesFromAlphabetStatesFrequencies(frequencies);
45  matchParametersValues(pfitset_->getParameters() );
46 }
47 
49 {
50  double mu;
51 
52  int aai = pgencode_->translate(stateMap_->getAlphabetStateAsInt(i));
53  int aaj = pgencode_->translate(stateMap_->getAlphabetStateAsInt(j));
54 
55  double phi_i = pfitset_->getFrequencies() [protStateMap_->getModelStates(aai)[0]];
56  double phi_j = pfitset_->getFrequencies() [protStateMap_->getModelStates(aaj)[0]];
57 
58  if (phi_i == phi_j || Ns_ == 0)
59  mu = 1;
60  else if (phi_i == 0)
61  mu = 100;
62  else if (phi_j == 0)
63  mu = 0;
64  else
65  {
66  if (Ns_ == 1)
67  mu = -(log(phi_i / phi_j) / (1 - (phi_i / phi_j)));
68  else
69  {
70  double x = pow(phi_i / phi_j, Ns_);
71  mu = -log(x) / (1 - x);
72  }
73  }
74 
75  return mu;
76 }
void setFreq(std::map< int, double > &frequencies) override
AbstractCodonAAFitnessSubstitutionModel(std::shared_ptr< FrequencySetInterface > pfitset, std::shared_ptr< const GeneticCode > pgencode, const std::string &prefix)
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...
double Ns_
The Ns of the model (default: 1), The generator (and all its vectorial components) is independent of ...
void addParameters_(const ParameterList &parameters)
virtual void fireParameterChanged(const ParameterList &parameters)
bool matchParametersValues(const ParameterList &parameters) override
bool hasParameter(const std::string &name) const override
double getParameterValue(const std::string &name) const override
static bool isProteicAlphabet(const Alphabet &alphabet)
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:168
Defines the basic types of data flow nodes.
double log(const ExtendedFloat &ef)
ExtendedFloat pow(const ExtendedFloat &ef, double exp)