bpp-phyl  2.2.0
TripletSubstitutionModel.cpp
Go to the documentation of this file.
1 //
2 // File: TripletSubstitutionModel.cpp
3 // Created by: Laurent Gueguen
4 // Created on: Feb 2009
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 
40 
41 #include <Bpp/Numeric/VectorTools.h>
42 #include <Bpp/Numeric/Matrix/MatrixTools.h>
43 #include <Bpp/Numeric/Matrix/EigenValue.h>
44 
45 // From SeqLib:
46 #include <Bpp/Seq/Alphabet/WordAlphabet.h>
47 #include <Bpp/Seq/Container/SequenceContainerTools.h>
48 
49 using namespace bpp;
50 
51 // From the STL:
52 #include <cmath>
53 
54 using namespace std;
55 
56 /******************************************************************************/
57 
59  const CodonAlphabet* palph,
61  AbstractParameterAliasable("Triplet."),
62  WordSubstitutionModel(palph, new CanonicalStateMap(palph, false), "Triplet.")
63 {
64  unsigned int i;
65  addParameters_(pmod->getParameters());
66 
67  Vrate_.resize(3);
68  for (i = 0; i < 3; i++)
69  {
70  VSubMod_.push_back(pmod);
71  VnestedPrefix_.push_back(pmod->getNamespace());
72  Vrate_[i] = 1. / 3.;
73  }
74 
75  // relative rates
76  for (i = 0; i < 2; i++)
77  {
78  addParameter_(new Parameter("Triplet.relrate" + TextTools::toString(i+1), 1.0 / (3 - i), &Parameter::PROP_CONSTRAINT_EX));
79  }
80 
82 }
83 
85  const CodonAlphabet* palph,
89  AbstractParameterAliasable("Triplet."),
90  WordSubstitutionModel(palph, new CanonicalStateMap(palph, false), "Triplet.")
91 {
92  string st = "Triplet.";
93 
94  if ((pmod1 == pmod2) || (pmod2 == pmod3) || (pmod1 == pmod3))
95  {
96  int i;
97  for (i = 0; i < 3; i++)
98  {
99  VSubMod_.push_back(pmod1);
100  VnestedPrefix_.push_back(pmod1->getNamespace());
101  }
102 
103  pmod1->setNamespace(st + "123_" + VnestedPrefix_[0]);
104  addParameters_(pmod1->getParameters());
105  }
106  else
107  {
108  VSubMod_.push_back(pmod1);
109  VnestedPrefix_.push_back(pmod1->getNamespace());
110  VSubMod_[0]->setNamespace(st + "1_" + VnestedPrefix_[0]);
111  addParameters_(pmod1->getParameters());
112 
113  VSubMod_.push_back(pmod2);
114  VnestedPrefix_.push_back(pmod2->getNamespace());
115  VSubMod_[1]->setNamespace(st + "2_" + VnestedPrefix_[1]);
116  addParameters_(pmod2->getParameters());
117 
118  VSubMod_.push_back(pmod3);
119  VnestedPrefix_.push_back(pmod3->getNamespace());
120  VSubMod_[2]->setNamespace(st + "3_" + VnestedPrefix_[2]);
121  addParameters_(pmod3->getParameters());
122  }
123 
124  unsigned int i;
125  Vrate_.resize(3);
126  for (i = 0; i < 3; i++)
127  {
128  Vrate_[i] = 1.0 / 3;
129  }
130 
131  // relative rates
132  for (i = 0; i < 2; i++)
133  {
134  addParameter_(new Parameter(st + "relrate" + TextTools::toString(i+1), 1.0 / (3 - i),&Parameter::PROP_CONSTRAINT_EX));
135  }
136 
138 }
139 
141 {
142  string s = "TripletSubstitutionModel model:";
143  for (unsigned int i = 0; i < VSubMod_.size(); i++)
144  {
145  s += " " + VSubMod_[i]->getName();
146  }
147 
148  return s;
149 }
150 
151 
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:161
std::string getName() const
Get the name of the model.
STL namespace.
Specialisation interface for nucleotide substitution model.
Basal class for words of reversible substitution models.
virtual void updateMatrices()
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
TripletSubstitutionModel(const CodonAlphabet *palph, NucleotideSubstitutionModel *pmod)
Build a new TripletSubstitutionModel object from a pointer to a NucleotideSubstitutionModel.
std::vector< SubstitutionModel * > VSubMod_