bpp-phyl3  3.0.0
AbstractCodonBGCSubstitutionModel.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 
11 using namespace std;
12 
13 /******************************************************************************/
14 
16  std::shared_ptr<const GeneticCode> pgencode,
17  const string& prefix) :
19  pgencode_(pgencode),
20  B_(0),
21  S_(0),
22  stateMap_(new CanonicalStateMap(pgencode->getSourceAlphabet(), false))
23 {
24  addParameter_(new Parameter(prefix + "S", 0));
25  addParameter_(new Parameter(prefix + "B", 0));
26 }
27 
29 {
30  B_ = getParameterValue("B");
31  S_ = getParameterValue("S");
32 }
33 
35 {
36  int si(stateMap_->getAlphabetStateAsInt(i)), sj(stateMap_->getAlphabetStateAsInt(j));
37 
38  int epsilon = pgencode_->codonAlphabet().getGCinCodon(sj)
39  - pgencode_->codonAlphabet().getGCinCodon(si);
40 
41  switch (epsilon)
42  {
43  case 0:
44  return pgencode_->areSynonymous(si, sj) ? 1.
45  : (S_ == 0 ? 1. : S_ / (1 - exp(-S_)));
46  case 1:
47  return pgencode_->areSynonymous(si, sj)
48  ? (B_ == 0 ? 1 : B_ / (1 - exp(-B_)))
49  : (B_ + S_ == 0 ? 1. : (B_ + S_) / (1 - exp(-(B_ + S_))));
50  case -1:
51  return pgencode_->areSynonymous(si, sj)
52  ? (B_ == 0 ? 1 : -B_ / (1 - exp(B_)))
53  : (-B_ + S_ == 0 ? 1. : (-B_ + S_) / (1 - exp(B_ - S_)));
54  }
55  return 0;
56 }
AbstractCodonBGCSubstitutionModel(std::shared_ptr< const GeneticCode > pgencode, const std::string &prefix)
Build a new AbstractCodonBGCSubstitutionModel object.
std::shared_ptr< const StateMapInterface > stateMap_
std::shared_ptr< const GeneticCode > pgencode_
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)
double getParameterValue(const std::string &name) const override
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:168
Defines the basic types of data flow nodes.
ExtendedFloat exp(const ExtendedFloat &ef)