bpp-phyl3  3.0.0
AbstractCodonPhaseFrequenciesSubstitutionModel.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include "../FrequencySet/NucleotideFrequencySet.h"
7 
8 #include <memory>
9 
10 using namespace bpp;
11 using namespace std;
12 
13 /******************************************************************************/
14 
16  unique_ptr<CodonFrequencySetInterface> pfreq,
17  const std::string& prefix) :
19  posFreqSet_(),
20  freqName_("")
21 {
22  if (dynamic_cast<CodonFromUniqueFrequencySet*>(pfreq.get())
23  || dynamic_cast<CodonFromIndependentFrequencySet*>(pfreq.get()))
24  posFreqSet_.reset(pfreq->clone());
25  else
26  {
27  vector<unique_ptr<FrequencySetInterface>> vFS;
28  if (dynamic_cast<FixedCodonFrequencySet*>(pfreq.get()))
29  {
30  for (unsigned int i = 0; i < 3; ++i)
31  {
32  vFS.push_back(make_unique<FixedNucleotideFrequencySet>(pfreq->getCodonAlphabet()->getNucleicAlphabet()));
33  }
34  }
35  else
36  {
37  for (unsigned int i = 0; i < 3; ++i)
38  {
39  vFS.push_back(make_unique<FullNucleotideFrequencySet>(pfreq->getCodonAlphabet()->getNucleicAlphabet()));
40  }
41  }
43  pfreq->getGeneticCode(),
44  vFS, ""));
45 
46  posFreqSet_->setFrequencies(pfreq->getFrequencies());
47  }
48 
49  freqName_ = pfreq->getNamespace();
50  posFreqSet_->setNamespace(prefix + pfreq->getNamespace());
51  addParameters_(posFreqSet_->getParameters());
52  fireParameterChanged(posFreqSet_->getParameters());
53 }
54 
55 /******************************************************************************/
56 
58 
59 /******************************************************************************/
60 
62 {
63  posFreqSet_->matchParametersValues(parameters);
64 }
65 
66 /******************************************************************************/
67 
69 {
70  posFreqSet_->setFrequenciesFromAlphabetStatesFrequencies(frequencies);
71  matchParametersValues(posFreqSet_->getParameters());
72 }
73 
74 /******************************************************************************/
75 
77 {
78  size_t i2(i), j2(j);
79 
80  double x = 1.;
81  for (size_t k = 0; k < 3; k++)
82  {
83  if ((i2 % 4) != (j2 % 4))
84  x *= dynamic_cast<WordFrequencySetInterface&>(*posFreqSet_).frequencySetForLetter(2 - k).getFrequencies()[j2 % 4];
85  i2 /= 4;
86  j2 /= 4;
87  }
88  return x;
89 }
90 
91 /******************************************************************************/
AbstractCodonPhaseFrequenciesSubstitutionModel(std::unique_ptr< CodonFrequencySetInterface > pfreq, const std::string &prefix)
Build a AbstractCodonPhaseFrequenciesSubstitutionModel instance.
double getCodonsMulRate(size_t, size_t) const override
Returns the multiplicative rate specific to two codons specified by their number. The respective gene...
std::unique_ptr< CodonFrequencySetInterface > posFreqSet_
Position dependent version of Codon Frequencies Set.
void addParameters_(const ParameterList &parameters)
bool matchParametersValues(const ParameterList &parameters) override
the Frequencies in codons are the product of Independent Frequencies in letters with the frequencies ...
the Frequencies in codons are the product of the frequencies for a unique FrequencySet in letters,...
FrequencySet useful for homogeneous and stationary models, codon implementation.
virtual const Vdouble & getFrequencies() const =0
Frequencies in words computed from the frequencies on letters. The parameters are the parameters of t...
virtual const FrequencySetInterface & frequencySetForLetter(size_t i) const =0
Returns the n-th FrequencySet.
Defines the basic types of data flow nodes.