46 #include <Bpp/Numeric/Matrix/MatrixTools.h> 47 #include <Bpp/Numeric/VectorTools.h> 48 #include <Bpp/Numeric/Matrix/EigenValue.h> 50 #include <Bpp/Text/TextTools.h> 55 AbstractParameterAliasable(prefix),
58 _nestedPrefix(pm->getNamespace())
62 addParameters_(
pmodel_->getParameters());
66 AbstractParameterAliasable(ypr),
68 pmodel_(ypr.pmodel_->clone()),
69 _nestedPrefix(ypr.getNestedPrefix())
76 AbstractParameterAliasable(ypr),
78 pmodel_(ypr.pmodel_->clone()),
79 _nestedPrefix(ypr.getNestedPrefix())
89 double TgC,
double tGA,
90 double CaT,
double cAG,
91 double TaC,
double tAC)
97 std::vector<size_t> l(4);
99 l[0] = alph->getStateIndex(
"A");
100 l[1] = alph->getStateIndex(
"G");
101 l[2] = alph->getStateIndex(
"C");
102 l[3] = alph->getStateIndex(
"T");
104 unsigned int i, j, i1, i2, i3, j1, j2, j3;
106 std::vector<double> a(4);
107 std::vector<double> b(4);
109 for (i = 0; i < 2; i++)
118 RowMatrix<double> M1(3, 3);
123 M1(1, 0) = b[0] + b[1];
126 M1(2, 0) = b[0] + b[1];
131 RowMatrix<double> M2(4, 4);
151 RowMatrix<double> M3(3, 3);
155 M3(0, 2) = b[2] + b[3];
158 M3(1, 2) = b[2] + b[3];
164 for (i1 = 0; i1 < 3; i1++)
166 for (i2 = 0; i2 < 4; i2++)
168 for (i3 = 0; i3 < 3; i3++)
170 i = 12 * i1 + 3 * i2 + i3;
171 for (j1 = 0; j1 < 3; j1++)
173 for (j2 = 0; j2 < 4; j2++)
175 for (j3 = 0; j3 < 3; j3++)
177 j = 12 * j1 + 3 * j2 + j3;
178 if ((i1 == j1) && (i2 == j2))
180 else if ((i1 == j1) && (i3 == j3))
182 else if ((i2 == j2) && (i3 == j3))
195 for (i3 = 0; i3 < 3; i3++)
198 generator_(12 * i3 + 7, 12 * i3 + 6) += cGA * a[0];
201 generator_(12 * i3 + 7, 12 * i3 + 10) += CgT * a[3];
204 generator_(12 * i3 + 10, 12 * i3 + 9) += tGA * a[0];
207 generator_(12 * i3 + 10, 12 * i3 + 7) += TgC * a[2];
210 generator_(12 * i3 + 6, 12 * i3 + 9) += CaT * a[3];
213 generator_(12 * i3 + 6, 12 * i3 + 7) += cAG * a[1];
216 generator_(12 * i3 + 9, 12 * i3 + 10) += tAC * a[1];
219 generator_(12 * i3 + 9, 12 * i3 + 6) += TaC * a[2];
224 for (i = 0; i < 36; i++)
227 for (j = 0; j < 36; j++)
249 for (i = 0; i <
size_; i++)
267 for (i = 0; i < 36; i++)
276 for (i = 0; i < 36; i++)
281 catch (ZeroDivisionException& e)
283 ApplicationTools::displayMessage(
"Singularity during diagonalization. Taylor series used instead.");
291 for (i = 1; i < 36; i++)
299 MatrixTools::getId(36,
tmpMat_);
304 for (i = 0; i < 36; i++)
309 MatrixTools::getId(36,
vPowGen_[0]);
315 for (i1 = 0; i1 < 3; i1++)
317 for (i2 = 0; i2 < 4; i2++)
319 for (i3 = 0; i3 < 3; i3++)
321 i = 12 * i1 + 3 * i2 + i3;
322 for (j2 = 0; j2 < 4; j2++)
326 j = 12 * i1 + 3 * j2 + i3;
339 for (i = 0; i < 36; i++)
346 for (i = 0; i <
size_; i++)
348 for (j = 0; j <
size_; j++)
359 throw Exception(
"No Model ");
361 const Alphabet* alph = pm->getAlphabet();
362 if (alph->getAlphabetType() !=
"DNA alphabet")
363 throw Exception(
"Need a DNA model");
365 std::vector<size_t> l(4);
367 l[0] = alph->getStateIndex(
"A");
368 l[1] = alph->getStateIndex(
"G");
369 l[2] = alph->getStateIndex(
"C");
370 l[3] = alph->getStateIndex(
"T");
374 for (
size_t i = 0; i < 2; ++i)
376 if (pm->Qij(l[2], l[i]) != pm->Qij(l[3], l[i]))
377 throw Exception(
"Not R/Y Model " + pm->getName());
379 for (
size_t i = 2; i < 4; ++i)
381 if (pm->Qij(l[0], l[i]) != pm->Qij(l[1], l[i]))
382 throw Exception(
"Not R/Y Model " + pm->getName());
388 AbstractSubstitutionModel::setNamespace(prefix);
401 double CgT,
double TgC,
402 double CaT,
double TaC) : AbstractParameterAliasable(
"YpR_Sym."),
403 YpR(alph, pm,
"YpR_Sym.")
405 addParameter_(
new Parameter(
"YpR_Sym.rCgT", CgT, &Parameter::R_PLUS));
406 addParameter_(
new Parameter(
"YpR_Sym.rTgC", TgC, &Parameter::R_PLUS));
407 addParameter_(
new Parameter(
"YpR_Sym.rCaT", CaT, &Parameter::R_PLUS));
408 addParameter_(
new Parameter(
"YpR_Sym.rTaC", TaC, &Parameter::R_PLUS));
415 double rCgT = getParameterValue(
"rCgT");
416 double rTgC = getParameterValue(
"rTgC");
417 double rCaT = getParameterValue(
"rCaT");
418 double rTaC = getParameterValue(
"rTaC");
442 double CgT,
double cGA,
443 double TgC,
double tGA,
444 double CaT,
double cAG,
445 double TaC,
double tAG) : AbstractParameterAliasable(
"YpR_Gen."),
446 YpR(alph, pm,
"YpR_Gen.")
448 addParameter_(
new Parameter(
"YpR_Gen.rCgT", CgT, &Parameter::R_PLUS));
449 addParameter_(
new Parameter(
"YpR_Gen.rcGA", cGA, &Parameter::R_PLUS));
450 addParameter_(
new Parameter(
"YpR_Gen.rTgC", TgC, &Parameter::R_PLUS));
451 addParameter_(
new Parameter(
"YpR_Gen.rtGA", tGA, &Parameter::R_PLUS));
452 addParameter_(
new Parameter(
"YpR_Gen.rCaT", CaT, &Parameter::R_PLUS));
453 addParameter_(
new Parameter(
"YpR_Gen.rcAG", cAG, &Parameter::R_PLUS));
454 addParameter_(
new Parameter(
"YpR_Gen.rTaC", TaC, &Parameter::R_PLUS));
455 addParameter_(
new Parameter(
"YpR_Gen.rtAG", tAG, &Parameter::R_PLUS));
462 double rCgT = getParameterValue(
"rCgT");
463 double rcGA = getParameterValue(
"rcGA");
464 double rTgC = getParameterValue(
"rTgC");
465 double rtGA = getParameterValue(
"rtGA");
466 double rCaT = getParameterValue(
"rCaT");
467 double rcAG = getParameterValue(
"rcAG");
468 double rTaC = getParameterValue(
"rTaC");
469 double rtAG = getParameterValue(
"rtAG");
Interface for all substitution models.
virtual void updateMatrices()
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
void updateMatrices()
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
RowMatrix< double > exchangeability_
The exchangeability matrix of the model, defined as . When the model is reversible, this matrix is symetric.
std::string _nestedPrefix
bool isNonSingular_
boolean value for non-singularity of rightEigenVectors_
This class implements a state map where all resolved states are modeled.
RowMatrix< double > rightEigenVectors_
The matrix made of right eigen vectors (by column).
Vdouble eigenValues_
The vector of eigen values.
std::string getName() const
Get the name of the model.
virtual const Alphabet * getAlphabet() const =0
Vdouble freq_
The vector of equilibrium frequencies.
YpR_Sym(const RNY *alph, SubstitutionModel *pm, double CgT=0., double TgC=0., double CaT=0., double TaC=0.)
Build a new YpR_Sym substitution model.
Partial implementation of the SubstitutionModel interface.
virtual void enableEigenDecomposition(bool yn)=0
Set if eigenValues and Vectors must be computed.
virtual double Qij(size_t i, size_t j) const =0
RowMatrix< double > leftEigenVectors_
The matrix made of left eigen vectors (by row) if rightEigenVectors_ is non-singular.
RowMatrix< double > generator_
The generator matrix of the model.
YpR(const RNY *, SubstitutionModel *const, const std::string &prefix)
Build a new YpR substitution model, with no dependency parameters.
std::vector< RowMatrix< double > > vPowGen_
vector of the powers of generator_ for Taylor development (if rightEigenVectors_ is singular)...
void check_model(SubstitutionModel *const) const
std::string getName() const
Get the name of the model.
SubstitutionModel * pmodel_
virtual void setNamespace(const std::string &)
size_t size_
The size of the generator, i.e. the number of states.
void updateMatrices()
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
YpR_Gen(const RNY *alph, SubstitutionModel *pm, double CgT=0., double cGA=0., double TgC=0., double tGA=0., double CaT=0., double cAG=0., double TaC=0., double tAG=0.)
Build a new YpR_Gen substitution model.
RowMatrix< double > tmpMat_
For computational issues.
bool isDiagonalizable_
boolean value for diagonalizability in R of the generator_
Vdouble iEigenValues_
The vector of the imaginary part of the eigen values.