1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
// $Id: tamura92.cpp 962 2006-11-07 15:13:34Z privmane $
#include "tamura92.h"
#include "errorMsg.h"
// This implementation was copied from the Bio++ Phyl library (by Julien Dutheil) - file T92.cpp
tamura92::tamura92(const MDOUBLE theta,
const MDOUBLE TrTv)
: _theta(theta), _TrTv(TrTv) {
_freq.resize(4);
changeTheta(theta);
}
void tamura92::changeTheta(const MDOUBLE theta) {
_theta = theta;
_freq[0] = _freq[3] = (1.0 - theta) / 2.0;
_freq[1] = _freq[2] = theta / 2.0;
}
const MDOUBLE tamura92::Pij_t(const int i, const int j, const MDOUBLE t) const {
double k = (_TrTv + 1.0) / 2.0;
double r = 2.0 / (1.0 + 2.0 * _theta * _TrTv - 2.0 * _theta * _theta * _TrTv);
double l = r * t;
double exp1 = exp(-l);
double exp2 = exp(-k * l);
switch(i) {
//A
case 0 : {
switch(j) {
case 0 : return _freq[0] * (1.0 + exp1) + _theta * exp2; //A
case 1 : return _freq[1] * (1.0 - exp1); //C
case 2 : return _freq[2] * (1.0 + exp1) - _theta * exp2; //G
case 3 : return _freq[3] * (1.0 - exp1); //T, U
}
}
//C
case 1 : {
switch(j) {
case 0 : return _freq[0] * (1.0 - exp1); //A
case 1 : return _freq[1] * (1.0 + exp1) + (1. - _theta) * exp2; //C
case 2 : return _freq[2] * (1.0 - exp1); //G
case 3 : return _freq[3] * (1.0 + exp1) - (1. - _theta) * exp2; //T, U
}
}
//G
case 2 : {
switch(j) {
case 0 : return _freq[0] * (1.0 + exp1) - (1. - _theta) * exp2; //A
case 1 : return _freq[1] * (1.0 - exp1); //C
case 2 : return _freq[2] * (1.0 + exp1) + (1. - _theta) * exp2; //G
case 3 : return _freq[3] * (1.0 - exp1); //T, U
}
}
//T, U
case 3 : {
switch(j) {
case 0 : return _freq[0] * (1.0 - exp1); //A
case 1 : return _freq[1] * (1.0 + exp1) - _theta * exp2; //C
case 2 : return _freq[2] * (1.0 - exp1); //G
case 3 : return _freq[3] * (1.0 + exp1) + _theta * exp2; //T, U
}
}
}
return -1;
}
const MDOUBLE tamura92::dPij_dt(const int i,const int j, const MDOUBLE t) const {
double k = (_TrTv + 1.0) / 2.0;
double r = 2.0 / (1.0 + 2.0 * _theta * _TrTv - 2.0 * _theta * _theta * _TrTv);
double l = r * t;
double exp1 = exp(-l);
double exp2 = exp(-k * l);
switch(i) {
//A
case 0 : {
switch(j) {
case 0 : return r * (_freq[0] * - exp1 + _theta * -k * exp2); //A
case 1 : return r * (_freq[1] * exp1); //C
case 2 : return r * (_freq[2] * - exp1 - _theta * -k * exp2); //G
case 3 : return r * (_freq[3] * exp1); //T, U
}
}
//C
case 1 : {
switch(j) {
case 0 : return r * (_freq[0] * exp1); //A
case 1 : return r * (_freq[1] * - exp1 + (1.0 - _theta) * -k * exp2); //C
case 2 : return r * (_freq[2] * exp1); //G
case 3 : return r * (_freq[3] * - exp1 - (1.0 - _theta) * -k * exp2); //T, U
}
}
//G
case 2 : {
switch(j) {
case 0 : return r * (_freq[0] * - exp1 - (1.0 - _theta) * -k * exp2); //A
case 1 : return r * (_freq[1] * exp1); //C
case 2 : return r * (_freq[2] * - exp1 + (1.0 - _theta) * -k * exp2); //G
case 3 : return r * (_freq[3] * exp1); //T, U
}
}
//T, U
case 3 : {
switch(j) {
case 0 : return r * (_freq[0] * exp1); //A
case 1 : return r * (_freq[1] * - exp1 - _theta * -k * exp2); //C
case 2 : return r * (_freq[2] * exp1); //G
case 3 : return r * (_freq[3] * - exp1 + _theta * -k * exp2); //T, U
}
}
}
return -1;
}
const MDOUBLE tamura92::d2Pij_dt2(const int i,const int j, const MDOUBLE t) const {
double k = (_TrTv + 1.0) / 2.;
double k2 = k * k;
double r = 2.0 / (1.0 + 2.0 * _theta * _TrTv - 2.0 * _theta * _theta * _TrTv);
double l = r * t;
double r2 = r * r;
double exp1 = exp(-l);
double exp2 = exp(-k * l);
switch(i) {
//A
case 0 : {
switch(j) {
case 0 : return r2 * (_freq[0] * exp1 + _theta * k2 * exp2); //A
case 1 : return r2 * (_freq[1] * - exp1); //C
case 2 : return r2 * (_freq[2] * exp1 - _theta * k2 * exp2); //G
case 3 : return r2 * (_freq[3] * - exp1); //T, U
}
}
//C
case 1 : {
switch(j) {
case 0 : return r2 * (_freq[0] * - exp1); //A
case 1 : return r2 * (_freq[1] * exp1 + (1.0 - _theta) * k2 * exp2); //C
case 2 : return r2 * (_freq[2] * - exp1); //G
case 3 : return r2 * (_freq[3] * exp1 - (1.0 - _theta) * k2 * exp2); //T, U
}
}
//G
case 2 : {
switch(j) {
case 0 : return r2 * (_freq[0] * exp1 - (1.0 - _theta) * k2 * exp2); //A
case 1 : return r2 * (_freq[1] * - exp1); //C
case 2 : return r2 * (_freq[2] * exp1 + (1.0 - _theta) * k2 * exp2); //G
case 3 : return r2 * (_freq[3] * - exp1); //T, U
}
}
//T, U
case 3 : {
switch(j) {
case 0 : return r2 * (_freq[0] * - exp1); //A
case 1 : return r2 * (_freq[1] * exp1 - _theta * k2 * exp2); //C
case 2 : return r2 * (_freq[2] * - exp1); //G
case 3 : return r2 * (_freq[3] * exp1 + _theta * k2 * exp2); //T, U
}
}
}
return -1;
}
|