bpp-phyl3  3.0.0
DFP07.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
7 
8 #include "../MixtureOfASubstitutionModel.h"
9 #include "DFP07.h"
11 
12 using namespace bpp;
13 using namespace std;
14 
15 /******************************************************************************/
16 
18  std::shared_ptr<const GeneticCode> gCode,
19  std::unique_ptr<ProteinSubstitutionModelInterface> pAAmodel,
20  std::unique_ptr<CodonFrequencySetInterface> codonFreqs) :
22  AbstractWrappedModel("DFP07."),
27  mixedSubModelPtr_(nullptr),
28  synfrom_(),
29  synto_()
30 {
31  // build the submodel
32 
33  auto codmodel = make_unique<DFPDistanceFrequenciesSubstitutionModel>(gCode, std::move(codonFreqs));
34  auto submodel = make_unique<CodonSameAARateSubstitutionModel>(std::move(pAAmodel), std::move(codmodel), unique_ptr<CodonFrequencySetInterface>(nullptr), gCode);
35 
36  map<string, unique_ptr<DiscreteDistributionInterface>> mpdd;
37  vector<double> v1, v2;
38  v1.push_back(0.5); v1.push_back(1);
39  v2.push_back(0.5); v2.push_back(0.5);
40  mpdd["DFPDistFreq.beta"] = make_unique<SimpleDiscreteDistribution>(v1, v2);
41 
42  mixedModelPtr_.reset(new MixtureOfASubstitutionModel(gCode->getSourceAlphabet(), std::move(submodel), mpdd));
43  mixedSubModelPtr_ = dynamic_cast<const MixtureOfASubstitutionModel*>(&mixedModel());
44 
45  vector<int> supportedChars = mixedSubModelPtr_->getAlphabetStates();
46  // map the parameters
47 
48  lParPmodel_.addParameters(mixedModelPtr_->getParameters());
49 
50  vector<std::string> v = mixedModelPtr_->getNModel(0)->getParameters().getParameterNames();
51 
52  for (auto vi : v)
53  {
54  if (vi != "SameAARate.DFPDistFreq.beta")
55  mapParNamesFromPmodel_[vi] = vi.substr(23);
56  }
57 
58  mapParNamesFromPmodel_["SameAARate.DFPDistFreq.beta_Simple.V1"] = "omega";
59  mapParNamesFromPmodel_["SameAARate.DFPDistFreq.beta_Simple.theta1"] = "p0";
60 
61  // specific parameters
62 
63  string st;
64  for (auto it : mapParNamesFromPmodel_)
65  {
66  st = mixedModelPtr_->getParameterNameWithoutNamespace(it.first);
67  if (st != "DFPDistFreq.beta_Simple.V1")
68  {
69  addParameter_(new Parameter("DFP07." + it.second, mixedModelPtr_->getParameterValue(st),
70  mixedModelPtr_->parameter(st).hasConstraint() ? std::shared_ptr<ConstraintInterface>(mixedModelPtr_->parameter(st).getConstraint()->clone()) : 0));
71  }
72  }
73 
74  addParameter_(new Parameter("DFP07.omega", 0.5, std::make_shared<IntervalConstraint>(0.002, 1, true, false, 0.002)));
75 
76  // look for synonymous codons
77  for (synfrom_ = 1; synfrom_ < supportedChars.size(); ++synfrom_)
78  {
79  for (synto_ = 0; synto_ < synfrom_; ++synto_)
80  {
81  if (gCode->areSynonymous(supportedChars[synfrom_], supportedChars[synto_])
84  break;
85  }
86  if (synto_ < synfrom_)
87  break;
88  }
89 
90  if (synto_ == supportedChars.size())
91  throw Exception("Impossible to find synonymous codons");
92 
93  // update matrice
94 
95  computeFrequencies(false);
97 }
98 
100 {
102 
103  // homogeneization of the synonymous substitution rates
104 
105  Vdouble vd;
106 
107  vd.push_back(1. / mixedSubModelPtr_->subNModel(0).Qij(synfrom_, synto_));
108  vd.push_back(1. / mixedSubModelPtr_->subNModel(1).Qij(synfrom_, synto_));
109 
110  mixedModelPtr_->setVRates(vd);
111 }
Abstract class for mixture models based on the bibliography.
const MixedTransitionModelInterface & mixedModel() const
std::unique_ptr< MixedTransitionModelInterface > mixedModelPtr_
Partial implementation of the SubstitutionModel interface for models that are set for matching the bi...
std::map< std::string, std::string > mapParNamesFromPmodel_
Tools to make the link between the Parameters of the object and those of pmixmodel_.
void addParameter_(Parameter *parameter)
const std::vector< int > & getAlphabetStates() const override
Abstract class of Wrapping model class, where all methods are redirected from model().
size_t synto_
Definition: DFP07.h:62
void updateMatrices_() override
Definition: DFP07.cpp:99
const MixtureOfASubstitutionModel * mixedSubModelPtr_
Definition: DFP07.h:56
size_t synfrom_
indexes of 2 codons states between which the substitution is synonymous, to set a basis to the homoge...
Definition: DFP07.h:62
DFP07(std::shared_ptr< const GeneticCode > gCode, std::unique_ptr< ProteinSubstitutionModelInterface > pAAmodel, std::unique_ptr< CodonFrequencySetInterface > codonFreqs)
Definition: DFP07.cpp:17
const SubstitutionModelInterface & subNModel(size_t i) const
virtual void addParameters(const ParameterList &params)
virtual double Qij(size_t i, size_t j) const =0
A method for computing all necessary matrices.
Defines the basic types of data flow nodes.
std::vector< double > Vdouble