00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <cassert>
00025 #include <Sequence/Grantham.hpp>
00026 #include <Sequence/WeightingSchemes.hpp>
00027 #include <Sequence/PathwayHelper.hpp>
00028 #include <Sequence/RedundancyCom95.hpp>
00029 #include <Sequence/SingleSub.hpp>
00030 #include <Sequence/ThreeSubs.hpp>
00031
00032 using std::string;
00033
00034 namespace Sequence
00035 {
00036 ThreeSubs::~ThreeSubs (void)
00040 {
00041 }
00042
00043 void ThreeSubs::operator() (const RedundancyCom95 * sitesObj,
00044 const std::string &codon1, const std::string &codon2,
00045 const Sequence::WeightingScheme3 *weights3)
00054 {
00055 assert(codon1.length() == 3 && codon2.length() == 3);
00056 string intermediates[9];
00057 Intermediates3(intermediates,codon1,codon2);
00058 p0 = p2S = p2V = p4 = q0 = q2S = q2V = q4 = 0.0;
00059
00060 weights3->Calculate(codon1,codon2);
00061 double *weights = weights3->weights();
00062 Calculate (sitesObj, intermediates, codon1, codon2, weights[0],
00063 weights[1], weights[2], weights[3], weights[4], weights[5]);
00064 }
00065
00066 void
00067 ThreeSubs::Calculate (const RedundancyCom95 * sitesObj,
00068 const std::string *intermediates,
00069 const std::string & codon1, const std::string & codon2,
00070 double w_path1, double w_path2, double w_path3,
00071 double w_path4, double w_path5, double w_path6)
00075 {
00076
00077 double p0_b[15], p2S_b[15], p2V_b[15], p4_b[15];
00078 double q0_b[15], q2S_b[15], q2V_b[15], q4_b[15];
00079
00080
00081 SingleSub Single;
00082
00083
00084 for (int i = 0; i <= 14; ++i)
00085 {
00086 switch (i)
00087 {
00088 case 0:
00089
00090
00091 Single(sitesObj, codon1,intermediates[0]);
00092 break;
00093 case 1:
00094 Single (sitesObj, intermediates[0],
00095 intermediates[1]);
00096 break;
00097 case 2:
00098 Single (sitesObj, intermediates[1],
00099 codon2);
00100 break;
00101 case 3:
00102 Single (sitesObj, intermediates[0],
00103 intermediates[2]);
00104 break;
00105 case 4:
00106 Single (sitesObj, intermediates[2],
00107 codon2);
00108 break;
00109 case 5:
00110 Single (sitesObj, codon1,
00111 intermediates[3]);
00112 break;
00113 case 6:
00114 Single (sitesObj, intermediates[3],
00115 intermediates[4]);
00116 break;
00117 case 7:
00118 Single (sitesObj, intermediates[4],
00119 codon2);
00120 break;
00121 case 8:
00122 Single (sitesObj, intermediates[3],
00123 intermediates[5]);
00124 break;
00125 case 9:
00126 Single (sitesObj, intermediates[5],
00127 codon2);
00128 break;
00129 case 10:
00130 Single (sitesObj, codon1,
00131 intermediates[6]);
00132 break;
00133 case 11:
00134 Single (sitesObj, intermediates[6],
00135 intermediates[7]);
00136 break;
00137 case 12:
00138 Single (sitesObj, intermediates[7],
00139 codon2);
00140 break;
00141 case 13:
00142 Single (sitesObj, intermediates[6],
00143 intermediates[8]);
00144 break;
00145 case 14:
00146 Single (sitesObj, intermediates[8],
00147 codon2);
00148 break;
00149 }
00150 p0_b[i] = Single.P0();
00151 p2S_b[i] =Single.P2S();
00152 p2V_b[i] =Single.P2V();
00153 p4_b[i] = Single.P4();
00154 q0_b[i] = Single.Q0();
00155 q2S_b[i] =Single.Q2S();
00156 q2V_b[i] =Single.Q2V();
00157 q4_b[i] = Single.Q4();
00158 }
00159
00160
00161 p0 = (p0_b[0] + p0_b[1] + p0_b[2]) * w_path1
00162 + (p0_b[0] + p0_b[3] + p0_b[4]) * w_path2
00163 + (p0_b[5] + p0_b[6] + p0_b[7]) * w_path3
00164 + (p0_b[5] + p0_b[8] + p0_b[9]) * w_path4
00165 + (p0_b[10] + p0_b[11] + p0_b[12]) * w_path5
00166 + (p0_b[10] + p0_b[13] + p0_b[14]) * w_path6;
00167
00168 p2S = (p2S_b[0] + p2S_b[1] + p2S_b[2]) * w_path1
00169 + (p2S_b[0] + p2S_b[3] + p2S_b[4]) * w_path2
00170 + (p2S_b[5] + p2S_b[6] + p2S_b[7]) * w_path3
00171 + (p2S_b[5] + p2S_b[8] + p2S_b[9]) * w_path4
00172 + (p2S_b[10] + p2S_b[11] + p2S_b[12]) * w_path5
00173 + (p2S_b[10] + p2S_b[13] + p2S_b[14]) * w_path6;
00174
00175 p2V = (p2V_b[0] + p2V_b[1] + p2V_b[2]) * w_path1
00176 + (p2V_b[0] + p2V_b[3] + p2V_b[4]) * w_path2
00177 + (p2V_b[5] + p2V_b[6] + p2V_b[7]) * w_path3
00178 + (p2V_b[5] + p2V_b[8] + p2V_b[9]) * w_path4
00179 + (p2V_b[10] + p2V_b[11] + p2V_b[12]) * w_path5
00180 + (p2V_b[10] + p2V_b[13] + p2V_b[14]) * w_path6;
00181
00182 p4 = (p4_b[0] + p4_b[1] + p4_b[2]) * w_path1
00183 + (p4_b[0] + p4_b[3] + p4_b[4]) * w_path2
00184 + (p4_b[5] + p4_b[6] + p4_b[7]) * w_path3
00185 + (p4_b[5] + p4_b[8] + p4_b[9]) * w_path4
00186 + (p4_b[10] + p4_b[11] + p4_b[12]) * w_path5
00187 + (p4_b[10] + p4_b[13] + p4_b[14]) * w_path6;
00188
00189 q0 = (q0_b[0] + q0_b[1] + q0_b[2]) * w_path1
00190 + (q0_b[0] + q0_b[3] + q0_b[4]) * w_path2
00191 + (q0_b[5] + q0_b[6] + q0_b[7]) * w_path3
00192 + (q0_b[5] + q0_b[8] + q0_b[9]) * w_path4
00193 + (q0_b[10] + q0_b[11] + q0_b[12]) * w_path5
00194 + (q0_b[10] + q0_b[13] + q0_b[14]) * w_path6;
00195
00196 q2S = (q2S_b[0] + q2S_b[1] + q2S_b[2]) * w_path1
00197 + (q2S_b[0] + q2S_b[3] + q2S_b[4]) * w_path2
00198 + (q2S_b[5] + q2S_b[6] + q2S_b[7]) * w_path3
00199 + (q2S_b[5] + q2S_b[8] + q2S_b[9]) * w_path4
00200 + (q2S_b[10] +q2S_b[11] + q2S_b[12]) * w_path5
00201 + (q2S_b[10] + q2S_b[13] + q2S_b[14]) * w_path6;
00202
00203 q2V = (q2V_b[0] + q2V_b[1] + q2V_b[2]) * w_path1
00204 + (q2V_b[0] + q2V_b[3] + q2V_b[4]) * w_path2
00205 + (q2V_b[5] + q2V_b[6] + q2V_b[7]) * w_path3
00206 + (q2V_b[5] + q2V_b[8] + q2V_b[9]) * w_path4
00207 + (q2V_b[10] + q2V_b[11] + q2V_b[12]) * w_path5
00208 + (q2V_b[10] + q2V_b[13] + q2V_b[14]) * w_path6;
00209
00210 q4 = (q4_b[0] + q4_b[1] + q4_b[2]) * w_path1
00211 + (q4_b[0] + q4_b[3] + q4_b[4]) * w_path2
00212 + (q4_b[5] + q4_b[6] + q4_b[7]) * w_path3
00213 + (q4_b[5] + q4_b[8] + q4_b[9]) * w_path4
00214 + (q4_b[10] + q4_b[11] + q4_b[12]) * w_path5
00215 + (q4_b[10] + q4_b[13] + q4_b[14]) * w_path6;
00216 }
00217
00218 }
00219