3
// Created by: Julien Dutheil
4
// Created on: Thu Jan 22 16:17:39 2004
8
Copyright or © or Copr. CNRS, (November 16, 2004)
10
This software is a computer program whose purpose is to provide classes
11
for phylogenetic data analysis.
13
This software is governed by the CeCILL license under French law and
14
abiding by the rules of distribution of free software. You can use,
15
modify and/ or redistribute the software under the terms of the CeCILL
16
license as circulated by CEA, CNRS and INRIA at the following URL
17
"http://www.cecill.info".
19
As a counterpart to the access to the source code and rights to copy,
20
modify and redistribute granted by the license, users are provided only
21
with a limited warranty and the software's author, the holder of the
22
economic rights, and the successive licensors have only limited
25
In this respect, the user's attention is drawn to the risks associated
26
with loading, using, modifying and/or developing or reproducing the
27
software by the user in light of its specific status of free software,
28
that may mean that it is complicated to manipulate, and that also
29
therefore means that it is reserved for developers and experienced
30
professionals having in-depth computer knowledge. Users are therefore
31
encouraged to load and test the software's suitability as regards their
32
requirements in conditions enabling the security of their systems and/or
33
data to be ensured and, more generally, to use and operate it in the
34
same conditions as regards security.
36
The fact that you are presently reading this means that you have had
37
knowledge of the CeCILL license and that you accept its terms.
43
#include "NucleotideSubstitutionModel.h"
44
#include "AbstractSubstitutionModel.h"
46
#include <Bpp/Numeric/Constraints.h>
49
#include <Bpp/Seq/Alphabet/NucleicAlphabet.h>
55
* @brief The Hasegawa M, Kishino H and Yano T (1985) substitution model for nucleotides.
57
* This model is similar to K80 model,
58
* but allows distinct equilibrium frequencies between A, C, G and T.
61
* \cdots & r & \kappa r & r \\
62
* r & \cdots & r & \kappa r \\
63
* \kappa r & r & \cdots & r \\
64
* r & \kappa r & r & \cdots \\
68
* \pi = \left(\pi_A, \pi_C, \pi_G, \pi_T\right)
70
* This models hence includes five parameters, the transition / transversion
71
* relative rate \f$\kappa\f$ and four frequencies \f$\pi_A, \pi_C, \pi_G, \pi_T\f$.
72
* These four frequencies are not independent parameters, since they have the constraint to
74
* We use instead a different parametrization to remove this constraint:
77
* \theta = \pi_C + \pi_G\\
78
* \theta_1 = \frac{\pi_A}{1 - \theta} = \frac{\pi_A}{\pi_A + \pi_T}\\
79
* \theta_2 = \frac{\pi_G}{\theta} = \frac{\pi_G}{\pi_C + \pi_G}\\
83
* \pi_A = \theta_1 (1 - \theta)\\
84
* \pi_C = (1 - \theta_2) \theta\\
85
* \pi_G = \theta_2 \theta\\
86
* \pi_T = (1 - \theta_1)(1 - \theta).
89
* These parameters can also be measured from the data and not optimized.
91
* Normalization: \f$r\f$ is set so that \f$\sum_i Q_{i,i}\pi_i = -1\f$:
93
* S = \frac{1}{P}\begin{pmatrix}
94
* \frac{-\pi_T-\kappa\pi_G-\pi_C}{\pi_A} & 1 & \kappa & 1 \\
95
* 1 & \frac{-\kappa\pi_T-\pi_G-\pi_A}{\pi_C} & 1 & \kappa \\
96
* \kappa & 1 & \frac{-\pi_T-\pi_C-\kappa\pi_A}{\pi_G} & 1 \\
97
* 1 & \kappa & 1 & \frac{-\pi_G-\kappa\pi_C-\pi_A}{\pi_T} \\
100
* with \f$P=2\left(\pi_A \pi_C + \pi_C \pi_G + \pi_A \pi_T + \pi_G \pi_T + \kappa \left(\pi_C \pi_T + \pi_A \pi_G\right)\right)\f$.
102
* The normalized generator is obtained by taking the dot product of \f$S\f$ and \f$\pi\f$:
104
* Q = S . \pi = \frac{1}{P}\begin{pmatrix}
105
* -\pi_T-\kappa\pi_G-\pi_C & \pi_C & \kappa\pi_G & \pi_T \\
106
* \pi_A & -\kappa\pi_T-\pi_G-\pi_A & \pi_G & \kappa\pi_T \\
107
* \kappa\pi_A & \pi_C & -\pi_T-\pi_C-\kappa\pi_A & \pi_T \\
108
* \pi_A & \kappa\pi_C & \pi_G & -\pi_G-\kappa\pi_C-\pi_A \\
112
* The eigen values are \f$\left(0, -\frac{\pi_R + \kappa\pi_Y}{P}, -\frac{\pi_Y + \kappa\pi_R}{P}, -\frac{1}{P}\right)\f$,
113
* with \f$\pi_R=\pi_A+\pi_G\f$ and \f$\pi_Y=\pi_C+\pi_T\f$.
114
* The left eigen vectors are, by row:
116
* U = \begin{pmatrix}
117
* \pi_A & \pi_C & \pi_G & \pi_T \\
118
* 0 & \frac{\pi_T}{\pi_Y} & 0 & -\frac{\pi_T}{\pi_Y} \\
119
* \frac{\pi_G}{\pi_R} & 0 & -\frac{\pi_G}{\pi_R} & 0 \\
120
* \frac{\pi_A\pi_Y}{\pi_R} & -\pi_C & \frac{\pi_G\pi_Y}{\pi_R} & -\pi_T \\
123
* and the right eigen vectors are, by column:
125
* U^-1 = \begin{pmatrix}
127
* 1 & 1 & 0 & -\frac{\pi_R}{\pi_Y} \\
128
* 1 & 0 & \frac{\pi_A}{\pi_G} & 1 \\
129
* 1 & -\frac{\pi_C}{\pi_T} & 0 & -\frac{\pi_R}{\pi_Y} \\
133
* In addition, a rate_ factor defines the mean rate of the model.
135
* The probabilities of changes are computed analytically using the formulas:
139
* \frac{\pi_G}{\pi_R}A + \frac{\pi_A\pi_Y}{\pi_R}B + \pi_A & \pi_C - \pi_CB & -\frac{\pi_G}{\pi_R}A + \frac{\pi_G\pi_Y}{\pi_R}B + \pi_G & \pi_T - \pi_TB \\
140
* \pi_A - \pi_AB & \frac{\pi_T}{\pi_Y}A + \frac{\pi_C\pi_R}{\pi_Y}B + \pi_C & \pi_G - \pi_GB & -\frac{\pi_T}{\pi_Y}A + \frac{\pi_T\pi_R}{\pi_Y}B + \pi_T \\
141
* -\frac{\pi_A}{\pi_R}A + \frac{\pi_A\pi_Y}{\pi_R}B + \pi_A & \pi_C - \pi_CB & \frac{\pi_A}{\pi_R}A + \frac{\pi_G\pi_Y}{\pi_R}B + \pi_G & \pi_T - \pi_TB \\
142
* \pi_A - \pi_AB & -\frac{\pi_C}{\pi_Y}A + \frac{\pi_C\pi_R}{\pi_Y}B + \pi_C & \pi_G - \pi_GB & \frac{\pi_C}{\pi_Y}A + \frac{\pi_R\pi_T}{\pi_Y}B + \pi_T \\
145
* with \f$A=e^{-\frac{rate\_*(\pi_Y+\kappa\pi_R)t}{P}}\f$ and \f$B = e^{-\frac{rate\_*t}{P}}\f$.
147
* First and second order derivatives are also computed analytically using the formulas:
149
* \frac{\partial P_{i,j}(t)}{\partial t} = rate\_ * \\
152
* -\frac{\pi_G(\pi_Y+\kappa\pi_R)}{\pi_R}A - \frac{\pi_A\pi_Y}{\pi_R}B & \pi_CB & \frac{\pi_G(\pi_Y+\kappa\pi_R)}{\pi_R}A - \frac{\pi_G\pi_Y}{\pi_R}B & \pi_TB \\
153
* \pi_AB & -\frac{\pi_T(\pi_R+\kappa\pi_Y)}{\pi_Y}A - \frac{\pi_C\pi_R}{\pi_Y}B & \pi_GB & \frac{\pi_T(\pi_R+\kappa\pi_Y)}{\pi_Y}A - \frac{\pi_T\pi_R}{\pi_Y}B \\
154
* \frac{\pi_A(\pi_Y+\kappa\pi_R)}{\pi_R}A - \frac{\pi_A\pi_Y}{\pi_R}B & \pi_CB & -\frac{\pi_A(\pi_Y+\kappa\pi_R)}{\pi_R}A - \frac{\pi_G\pi_Y}{\pi_R}B & \pi_TB \\
155
* \pi_AB & \frac{\pi_C(\pi_R+\kappa\pi_Y)}{\pi_Y}A - \frac{\pi_C\pi_R}{\pi_Y}B & \pi_GB & -\frac{\pi_C(\pi_R+\kappa\pi_Y)}{\pi_Y}A - \frac{\pi_R\pi_T}{\pi_Y}B \\
159
* \frac{\partial^2 P_{i,j}(t)}{\partial t^2} = rate\_^2 * \\
162
* \frac{\pi_G{(\pi_Y+\kappa\pi_R)}^2}{\pi_R}A + \frac{\pi_A\pi_Y}{\pi_R}B & -\pi_CB & -\frac{\pi_G{(\pi_Y+\kappa\pi_R)}^2}{\pi_R}A + \frac{\pi_G\pi_Y}{\pi_R}B & -\pi_TB \\
163
* -\pi_AB & \frac{\pi_T{(\pi_R+\kappa\pi_Y)}^2}{\pi_Y}A + \frac{\pi_C\pi_R}{\pi_Y}B & -\pi_GB & -\frac{\pi_T{(\pi_R+\kappa\pi_Y)}^2}{\pi_Y}A + \frac{\pi_T\pi_R}{\pi_Y}B \\
164
* -\frac{\pi_A{(\pi_Y+\kappa\pi_R)}^2}{\pi_R}A + \frac{\pi_A\pi_Y}{\pi_R}B & -\pi_CB & \frac{\pi_A{(\pi_Y+\kappa\pi_R)}^2}{\pi_R}A + \frac{\pi_G\pi_Y}{\pi_R}B & -\pi_TB \\
165
* -\pi_AB & -\frac{\pi_C{(\pi_R+\kappa\pi_Y)}^2}{\pi_Y}A + \frac{\pi_C\pi_R}{\pi_Y}B & -\pi_GB & \frac{\pi_C{(\pi_R+\kappa\pi_Y)}^2}{\pi_Y}A + \frac{\pi_R\pi_T}{\pi_Y}B \\
169
* The parameters are named \c "kappa", \c "theta", \c "theta1", and \c "theta2"
170
* and their values may be retrieve with the command
172
* getParameterValue("kappa")
177
* - Hasegawa M, Kishino H and Yano T (1985), Molecular_ Biology And Evolution_ 22(2) 160-74.
180
public virtual NucleotideSubstitutionModel,
181
public AbstractReversibleSubstitutionModel
184
double kappa_, k1_, k2_, r_, piA_, piC_, piG_, piT_, piY_, piR_, theta_, theta1_, theta2_;
185
mutable double exp1_, exp21_, exp22_, l_;
186
mutable RowMatrix<double> p_;
190
const NucleicAlphabet * alpha,
199
#ifndef NO_VIRTUAL_COV
204
clone() const { return new HKY85(*this); }
207
double Pij_t (int i, int j, double d) const;
208
double dPij_dt (int i, int j, double d) const;
209
double d2Pij_dt2(int i, int j, double d) const;
210
const Matrix<double> & getPij_t (double d) const;
211
const Matrix<double> & getdPij_dt (double d) const;
212
const Matrix<double> & getd2Pij_dt2(double d) const;
214
std::string getName() const { return "HKY85"; }
217
* @brief This method is redefined to actualize the corresponding parameters piA, piT, piG and piC too.
219
void setFreq(std::map<int, double>& freqs);
221
void updateMatrices();
224
} //end of namespace bpp.