bpp-phyl  2.2.0
LGL08_CAT.cpp
Go to the documentation of this file.
1 //
2 // File: LGL08_CAT.cpp
3 // Created by: Mathieu Groussin
4 // Created on: Tuesday 11 December 2012
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 "LGL08_CAT.h"
40 #include "../FrequenciesSet/ProteinFrequenciesSet.h"
41 
42 #include <Bpp/Numeric/Prob/SimpleDiscreteDistribution.h>
43 
44 using namespace bpp;
45 
46 using namespace std;
47 
48 /******************************************************************************/
49 
50 LGL08_CAT::LGL08_CAT(const ProteicAlphabet* alpha, unsigned int nbCat) :
52  pmixmodel_(0)
53 {
54  // build the submodel
55 
56  vector<SubstitutionModel*> vpSM;
57  for(unsigned int i = 1; i < nbCat + 1; i++)
58  vpSM.push_back(new LGL08_CAT::EmbeddedModel(alpha, "C" + TextTools::toString(i), nbCat));
59 
60  Vdouble vrate, vproba;
61 
62  for (size_t i = 0; i < vpSM.size(); i++)
63  {
64  vproba.push_back((dynamic_cast<LGL08_CAT::EmbeddedModel*>(vpSM[i]))->getProportion());
65  vrate.push_back(vpSM[i]->getRate());
66  }
67 
68  pmixmodel_.reset(new MixtureOfSubstitutionModels(alpha, vpSM, vproba, vrate));
69 
70  string name, st;
71  ParameterList pl = pmixmodel_->getParameters();
72  for (unsigned int i = 0; i < pl.size(); i++)
73  {
74  name = pl[i].getName();
75  lParPmodel_.addParameter(Parameter(pl[i]));
76  st = pmixmodel_->getParameterNameWithoutNamespace(name);
77  mapParNamesFromPmodel_[name] = st;
78  addParameter_(new Parameter("LGL08_CAT." + st,
79  pmixmodel_->getParameterValue(st),
80  pmixmodel_->getParameter(st).hasConstraint() ? pmixmodel_->getParameter(st).getConstraint()->clone() : 0, true));
81  }
82 
84 }
85 
87  pmixmodel_(new MixtureOfSubstitutionModels(*mod2.pmixmodel_))
88 {}
89 
91 {
93 
95 
96  return *this;
97 }
98 
100 
101 /**************** sub model classes */ // ////////
102 
103 LGL08_CAT::EmbeddedModel::EmbeddedModel(const ProteicAlphabet* alpha, string name, unsigned int nbCat) :
104  AbstractParameterAliasable(name),
105  AbstractReversibleSubstitutionModel(alpha, new CanonicalStateMap(alpha, false), name),
106  proportion_(1),
107  name_(name)
108 {
109  //Exchangeabilities:
110  for(unsigned int i = 0; i < 20; i++)
111  {
112  for(unsigned int j = 0; j < 20; j++)
113  {
114  if(i == j)
115  exchangeability_(i,i) = -19.;
116  else
117  exchangeability_(i,j) = 1.;
118  }
119  }
120 
121  //Equilibrium frequencies, rates and proportions:
122  if(nbCat == 10)
123  {
124 #include "__CATC10FrequenciesCode"
125 #include "__CATC10RatesProps"
126  }
127  else if(nbCat == 20)
128  {
129 #include "__CATC20FrequenciesCode"
130 #include "__CATC20RatesProps"
131  }
132  else if(nbCat == 30)
133  {
134 #include "__CATC30FrequenciesCode"
135 #include "__CATC30RatesProps"
136  }
137  else if(nbCat == 40)
138  {
139 #include "__CATC40FrequenciesCode"
140 #include "__CATC40RatesProps"
141  }
142  else if(nbCat == 50)
143  {
144 #include "__CATC50FrequenciesCode"
145 #include "__CATC50RatesProps"
146  }
147  else if(nbCat == 60)
148  {
149 #include "__CATC60FrequenciesCode"
150 #include "__CATC60RatesProps"
151  }
152  else
153  throw Exception("LGL08_CAT.cpp: incorrect number of profiles. This number has to be 10, 20, 30, 40, 50 or 60.");
154 
155  updateMatrices();
156 }
157 
158 
std::map< std::string, std::string > mapParNamesFromPmodel_
Tools to make the link between the Parameters of the object and those of pmixmodel_.
RowMatrix< double > exchangeability_
The exchangeability matrix of the model, defined as . When the model is reversible, this matrix is symetric.
Abstract class for mixture models based on the bibliography.
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:161
STL namespace.
LGL08_CAT(const ProteicAlphabet *alpha, unsigned int nbCat=10)
Build a CAT model, with original equilibrium frequencies, probabilities and rates.
Definition: LGL08_CAT.cpp:50
std::auto_ptr< MixtureOfSubstitutionModels > pmixmodel_
Definition: LGL08_CAT.h:95
The Le et al (2008) CAT substitution model for proteins.
Definition: LGL08_CAT.h:74
virtual void updateMatrices()
Compute and diagonalize the matrix, and fill the eigenValues_, leftEigenVectors_ and rightEigenVecto...
Partial implementation of the ReversibleSubstitutionModel interface.
AbstractBiblioMixedSubstitutionModel & operator=(const AbstractBiblioMixedSubstitutionModel &model)
EmbeddedModel(const ProteicAlphabet *alpha, string name, unsigned int nbCat=10)
Definition: LGL08_CAT.cpp:103
LGL08_CAT & operator=(const LGL08_CAT &)
Definition: LGL08_CAT.cpp:90
Substitution models defined as a mixture of several substitution models.