bpp-phyl  2.2.0
YNGKP_M1.cpp
Go to the documentation of this file.
1 //
2 // File: YNGKP_M1.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_M1.h"
40 #include "YN98.h"
41 
42 #include <Bpp/Numeric/NumConstants.h>
43 #include <Bpp/Numeric/Prob/SimpleDiscreteDistribution.h>
44 
45 using namespace bpp;
46 
47 using namespace std;
48 
49 /******************************************************************************/
50 
51 YNGKP_M1::YNGKP_M1(const GeneticCode* gc, FrequenciesSet* codonFreqs) :
53  pmixmodel_(0),
54  synfrom_(),
55  synto_()
56 {
57  // build the submodel
58 
59  vector<double> v1, v2;
60  v1.push_back(0.5); v1.push_back(1);
61  v2.push_back(0.5); v2.push_back(0.5);
62 
63  SimpleDiscreteDistribution* psdd = new SimpleDiscreteDistribution(v1, v2);
64 
65  map<string, DiscreteDistribution*> mpdd;
66  mpdd["omega"] = psdd;
67 
68  YN98* yn98 = new YN98(gc, codonFreqs);
69  pmixmodel_.reset(new MixtureOfASubstitutionModel(gc->getSourceAlphabet(), yn98, mpdd));
70  delete psdd;
71  vector<int> supportedChars = yn98->getAlphabetStates();
72 
73  // map the parameters
74 
75  lParPmodel_.addParameters(pmixmodel_->getParameters());
76 
77  vector<std::string> v = dynamic_cast<YN98*>(pmixmodel_->getNModel(0))->getFrequenciesSet()->getParameters().getParameterNames();
78 
79  for (size_t i = 0; i < v.size(); i++)
80  {
81  mapParNamesFromPmodel_[v[i]] = v[i].substr(5);
82  }
83 
84  mapParNamesFromPmodel_["YN98.kappa"] = "kappa";
85  mapParNamesFromPmodel_["YN98.omega_Simple.V1"] = "omega";
86  mapParNamesFromPmodel_["YN98.omega_Simple.theta1"] = "p0";
87 
88  // specific parameters
89 
90  string st;
91  for (map<string, string>::iterator it = mapParNamesFromPmodel_.begin(); it != mapParNamesFromPmodel_.end(); it++)
92  {
93  st = pmixmodel_->getParameterNameWithoutNamespace(it->first);
94  if (st != "omega_Simple.V1")
95  {
96  addParameter_(new Parameter("YNGKP_M1." + it->second, pmixmodel_->getParameterValue(st),
97  pmixmodel_->getParameter(st).hasConstraint() ? pmixmodel_->getParameter(st).getConstraint()->clone() : 0, true));
98  }
99  }
100 
101  addParameter_(new Parameter("YNGKP_M1.omega", 0.5, new IntervalConstraint(NumConstants::MILLI(), 1, true, false, NumConstants::MILLI()), true));
102 
103  // look for synonymous codons
104  for (synfrom_ = 1; synfrom_ < supportedChars.size(); ++synfrom_)
105  {
106  for (synto_ = 0; synto_ < synfrom_; ++synto_)
107  {
108  if (gc->areSynonymous(supportedChars[synfrom_], supportedChars[synto_])
109  && (pmixmodel_->getNModel(0)->Qij(synfrom_, synto_) != 0)
110  && (pmixmodel_->getNModel(1)->Qij(synfrom_, synto_) != 0))
111  break;
112  }
113  if (synto_ < synfrom_)
114  break;
115  }
116 
117  if (synto_ == supportedChars.size())
118  throw Exception("Impossible to find synonymous codons");
119 
120  // update matrice
121 
122  updateMatrices();
123 }
124 
126  pmixmodel_(new MixtureOfASubstitutionModel(*mod2.pmixmodel_)),
127  synfrom_(mod2.synfrom_),
128  synto_(mod2.synto_)
129 {}
130 
132 {
134 
136  synfrom_ = mod2.synfrom_;
137  synto_ = mod2.synto_;
138 
139  return *this;
140 }
141 
143 
145 {
147 
148  // homogeneization of the synonymous substitution rates
149 
150  Vdouble vd;
151 
152  vd.push_back(1. / pmixmodel_->getNModel(0)->Qij(synfrom_, synto_));
153  vd.push_back(1. / pmixmodel_->getNModel(1)->Qij(synfrom_, synto_));
154 
155  pmixmodel_->setVRates(vd);
156 }
157 
std::auto_ptr< MixtureOfASubstitutionModel > pmixmodel_
Definition: YNGKP_M1.h:84
std::map< std::string, std::string > mapParNamesFromPmodel_
Tools to make the link between the Parameters of the object and those of pmixmodel_.
Abstract class for mixture models based on the bibliography.
YNGKP_M1(const GeneticCode *gc, FrequenciesSet *codonFreqs)
Definition: YNGKP_M1.cpp:51
size_t synto_
Definition: YNGKP_M1.h:92
STL namespace.
AbstractBiblioSubstitutionModel & operator=(const AbstractBiblioSubstitutionModel &model)
Parametrize a set of state frequencies.
const std::vector< int > & getAlphabetStates() const
void updateMatrices()
Definition: YNGKP_M1.cpp:144
The Yang and Nielsen (1998) substitution model for codons.
Definition: YN98.h:88
virtual ~YNGKP_M1()
Definition: YNGKP_M1.cpp:142
Substitution models defined as a mixture of nested substitution models.
const FrequenciesSet * getFrequenciesSet() const
If the model owns a FrequenciesSet, returns a pointer to it, otherwise return 0.
Definition: YNGKP_M1.h:120
The Yang et al (2000) M1 substitution model for codons, with the more realistic modification in Wong ...
Definition: YNGKP_M1.h:79
size_t synfrom_
indexes of 2 codons states between which the substitution is synonymous, to set a basis to the homoge...
Definition: YNGKP_M1.h:92
YNGKP_M1 & operator=(const YNGKP_M1 &)
Definition: YNGKP_M1.cpp:131