bpp-phyl  2.1.0
 All Classes Namespaces Files Functions Variables Friends Pages
YNGKP_M7.cpp
Go to the documentation of this file.
1 //
2 // File: YNGKP_M7.cpp
3 // Created by: Laurent Gueguen
4 // Created on: May 2010
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9  This software is a computer program whose purpose is to provide classes
10  for phylogenetic data analysis.
11 
12  This software is governed by the CeCILL license under French law and
13  abiding by the rules of distribution of free software. You can use,
14  modify and/ or redistribute the software under the terms of the CeCILL
15  license as circulated by CEA, CNRS and INRIA at the following URL
16  "http://www.cecill.info".
17 
18  As a counterpart to the access to the source code and rights to copy,
19  modify and redistribute granted by the license, users are provided only
20  with a limited warranty and the software's author, the holder of the
21  economic rights, and the successive licensors have only limited
22  liability.
23 
24  In this respect, the user's attention is drawn to the risks associated
25  with loading, using, modifying and/or developing or reproducing the
26  software by the user in light of its specific status of free software,
27  that may mean that it is complicated to manipulate, and that also
28  therefore means that it is reserved for developers and experienced
29  professionals having in-depth computer knowledge. Users are therefore
30  encouraged to load and test the software's suitability as regards their
31  requirements in conditions enabling the security of their systems and/or
32  data to be ensured and, more generally, to use and operate it in the
33  same conditions as regards security.
34 
35  The fact that you are presently reading this means that you have had
36  knowledge of the CeCILL license and that you accept its terms.
37  */
38 
39 #include "YNGKP_M7.h"
40 #include "YN98.h"
41 
44 
45 #include <Bpp/Text/TextTools.h>
46 
47 using namespace bpp;
48 
49 using namespace std;
50 
51 /******************************************************************************/
52 
53 YNGKP_M7::YNGKP_M7(const GeneticCode* gc, FrequenciesSet* codonFreqs, unsigned int nclass) :
55  pmixmodel_(0),
56  synfrom_(-1),
57  synto_(-1)
58 {
59  if (nclass <= 0)
60  throw Exception("Bad number of classes for model YNGKP_M7: " + TextTools::toString(nclass));
61 
62  // build the submodel
63 
64  BetaDiscreteDistribution* pbdd = new BetaDiscreteDistribution(nclass, 2, 2);
65 
66  map<string, DiscreteDistribution*> mpdd;
67  mpdd["omega"] = pbdd;
68 
69  pmixmodel_.reset(new MixtureOfASubstitutionModel(gc->getSourceAlphabet(), new YN98(gc, codonFreqs), mpdd));
70  delete pbdd;
71 
72  // mapping the parameters
73 
74  ParameterList pl = pmixmodel_->getParameters();
75  for (size_t i = 0; i < pl.size(); i++)
76  {
78  }
79 
80  vector<std::string> v = dynamic_cast<YN98*>(pmixmodel_->getNModel(0))->getFrequenciesSet()->getParameters().getParameterNames();
81 
82  for (size_t i = 0; i < v.size(); i++)
83  {
84  mapParNamesFromPmodel_[v[i]] = getParameterNameWithoutNamespace("YNGKP_M7." + v[i].substr(5));
85  }
86 
87  mapParNamesFromPmodel_["YN98.kappa"] = "kappa";
88  mapParNamesFromPmodel_["YN98.omega_Beta.alpha"] = "p";
89  mapParNamesFromPmodel_["YN98.omega_Beta.beta"] = "q";
90 
91  // specific parameters
92 
93  string st;
94  for (map<string, string>::iterator it = mapParNamesFromPmodel_.begin(); it != mapParNamesFromPmodel_.end(); it++)
95  {
96  st = pmixmodel_->getParameterNameWithoutNamespace(it->first);
97  addParameter_(new Parameter("YNGKP_M7." + it->second, pmixmodel_->getParameterValue(st),
98  pmixmodel_->getParameter(st).hasConstraint() ? pmixmodel_->getParameter(st).getConstraint()->clone() : 0, true));
99  }
100 
101  // look for synonymous codons
102  for (synfrom_ = 1; synfrom_ < (int)gc->getSourceAlphabet()->getSize(); synfrom_++)
103  {
104  for (synto_ = 0; synto_ < synfrom_; synto_++)
105  {
106  if ((gc->areSynonymous(synfrom_, synto_))
107  && (pmixmodel_->getNModel(0)->Qij(synfrom_, synto_) != 0)
108  && (pmixmodel_->getNModel(1)->Qij(synfrom_, synto_) != 0))
109  break;
110  }
111  if (synto_ < synfrom_)
112  break;
113  }
114 
115  if (synto_ == (int)gc->getSourceAlphabet()->getSize())
116  throw Exception("Impossible to find synonymous codons");
117 
118  // update Matrices
119 
120  updateMatrices();
121 }
122 
124  pmixmodel_(new MixtureOfASubstitutionModel(*mod2.pmixmodel_)),
125  synfrom_(mod2.synfrom_),
126  synto_(mod2.synto_)
127 {}
128 
130 {
132 
134  synfrom_ = mod2.synfrom_;
135  synto_ = mod2.synto_;
136 
137  return *this;
138 }
139 
141 
143 {
145 
146  // homogeneization of the synonymous substitution rates
147 
148  Vdouble vd;
149 
150  for (unsigned int i = 0; i < pmixmodel_->getNumberOfModels(); i++)
151  {
152  vd.push_back(1 / pmixmodel_->getNModel(i)->Qij(synfrom_, synto_));
153  }
154 
155  pmixmodel_->setVRates(vd);
156 }
157