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 <cmath>
00025 #include <cfloat>
00026 #include <Sequence/Grantham.hpp>
00027 #include <Sequence/Translate.hpp>
00028 #include <Sequence/PathwayHelper.hpp>
00029 #include <Sequence/GranthamWeights.hpp>
00030
00031 using std::string;
00032
00033 namespace Sequence
00034 {
00035 GranthamWeights2::GranthamWeights2(GeneticCodes genetic_code)
00036 :code(genetic_code)
00040 {
00041 }
00042
00043 GranthamWeights2::~GranthamWeights2(void)
00044 {}
00045
00046 void GranthamWeights2::Calculate(const std::string &codon1, const std::string &codon2) const
00052 {
00053 Grantham gdist;
00054 string intermediates[2];
00055 Intermediates2(intermediates,codon1,codon2);
00056
00057
00058
00059 double len_path_1 = 0.0, len_path_2 = 0.0;
00060
00061 string t1 = Translate (codon1.begin(),codon1.end(), code);
00062 string t2 = Translate (intermediates[0].begin(),
00063 intermediates[0].end(), code);
00064 len_path_1 += gdist ((t1)[0], (t2)[0]);
00065
00066 t1 = Translate (intermediates[0].begin(),intermediates[0].end(), code);
00067 t2 = Translate (codon2.begin(),codon2.end(), code);
00068 len_path_1 += gdist ((t1)[0], (t2)[0]);
00069
00070 t1 = Translate (codon1.begin(),codon1.end(), code);
00071 t2 = Translate (intermediates[1].begin(),intermediates[1].end(), code);
00072 len_path_2 += gdist ((t1)[0], (t2)[0]);
00073
00074 t1 = Translate (intermediates[1].begin(),intermediates[1].end(), code);
00075 t2 = Translate (codon2.begin(),codon2.end(), code);
00076 len_path_2 += gdist ((t1)[0], (t2)[0]);
00077
00078
00079
00080 double w_tot = 0.;
00081 __weights[0]=0.;
00082 __weights[1]=0.;
00083
00084 if (fabs(len_path_1-0.) <= DBL_EPSILON && fabs(len_path_2-0.) <= DBL_EPSILON)
00085 {
00086 __weights[0] = __weights[1] = 0.5;
00087 w_tot = 1.;
00088 }
00089 else
00090 {
00091 __weights[0] = 1. - len_path_1 / (len_path_1 + len_path_2);
00092 __weights[1] = 1. - len_path_2 / (len_path_1 + len_path_2);
00093 w_tot = __weights[0] + __weights[1];
00094 }
00095
00096 __weights[0] /= w_tot;
00097 __weights[1] /= w_tot;
00098
00099 }
00100
00101 double * GranthamWeights2::weights(void) const
00105 {
00106 return __weights;
00107 }
00108
00109 GranthamWeights3::GranthamWeights3(GeneticCodes genetic_code)
00110 :code(genetic_code)
00114 {
00115 }
00116
00117 GranthamWeights3::~GranthamWeights3(void)
00118 {}
00119
00120 void GranthamWeights3::Calculate(const std::string &codon1, const std::string &codon2) const
00126 {
00127 Grantham gdist;
00128 string intermediates[9];
00129 Intermediates3(intermediates,codon1,codon2);
00130 double len_path_1 = 0.0, len_path_2 = 0.0, len_path_3 =
00131 0., len_path_4 = 0., len_path_5 = 0., len_path_6 = 0.;
00132 double dist = 0.;
00133
00134 string t1 = Translate (codon1.begin(), codon1.end(),code);
00135 string t2 = Translate (intermediates[0].begin(), intermediates[0].end(),code);
00136 dist = gdist ((t1)[0],(t2)[0]);
00137 len_path_1 += dist;
00138
00139
00140 t1 = Translate (intermediates[0].begin(), intermediates[0].end(), code);
00141 t2 = Translate (intermediates[1].begin(), intermediates[1].end(), code);
00142 dist = gdist ((t1)[0],(t2)[0]);
00143 len_path_1 += dist;
00144
00145
00146 t1 = Translate (intermediates[1].begin(), intermediates[1].end(),code);
00147 t2 = Translate (codon2.begin(),codon2.end(), code);
00148 dist = gdist ((t1)[0],(t2)[0]);
00149 len_path_1 += dist;
00150
00151
00152
00153 t1 = Translate (codon1.begin(),codon1.end(), code);
00154 t2 = Translate (intermediates[0].begin(),intermediates[0].end(), code);
00155 dist = gdist ((t1)[0],(t2)[0]);
00156 len_path_2 += dist;
00157
00158 t1 = Translate (intermediates[0].begin(),intermediates[0].end(), code);
00159 t2 = Translate (intermediates[2].begin(),intermediates[2].end(), code);
00160 dist = gdist ((t1)[0],(t2)[0]);
00161 len_path_2 += dist;
00162
00163 t1 = Translate (intermediates[2].begin(),intermediates[2].end(), code);
00164 t2 = Translate (codon2.begin(),codon2.end(), code);
00165 dist = gdist ((t1)[0],(t2)[0]);
00166 len_path_2 += dist;
00167
00168
00169 t1 = Translate (codon1.begin(),codon1.end(), code);
00170 t2 = Translate (intermediates[3].begin(),intermediates[3].end(), code);
00171 dist = gdist ((t1)[0],(t2)[0]);
00172 len_path_3 += dist;
00173
00174 t1 = Translate (intermediates[3].begin(), intermediates[3].end(),code);
00175 t2 = Translate (intermediates[4].begin(), intermediates[4].end(), code);
00176 dist = gdist ((t1)[0],(t2)[0]);
00177 len_path_3 += dist;
00178
00179 t1 = Translate (intermediates[4].begin(), intermediates[4].end(), code);
00180 t2 = Translate (codon2.begin(),codon2.end(), code);
00181 dist = gdist ((t1)[0],(t2)[0]);
00182 len_path_3 += dist;
00183
00184
00185 t1 = Translate (codon1.begin(),codon1.end(), code);
00186 t2 = Translate (intermediates[3].begin(), intermediates[3].end(), code);
00187 dist = gdist ((t1)[0],(t2)[0]);
00188 len_path_4 += dist;
00189
00190 t1 = Translate (intermediates[3].begin(), intermediates[3].end(), code);
00191 t2 = Translate (intermediates[5].begin(), intermediates[5].end(), code);
00192 dist = gdist ((t1)[0],(t2)[0]);
00193 len_path_4 += dist;
00194
00195 t1 = Translate (intermediates[5].begin(), intermediates[5].end(), code);
00196 t2 = Translate (codon2.begin(),codon2.end(), code);
00197 dist = gdist ((t1)[0],(t2)[0]);
00198 len_path_4 += dist;
00199
00200
00201 t1 = Translate (codon1.begin(),codon1.end(), code);
00202 t2 = Translate (intermediates[6].begin(), intermediates[6].end(), code);
00203 dist = gdist ((t1)[0],(t2)[0]);
00204 len_path_5 += dist;
00205
00206 t1 = Translate (intermediates[6].begin(), intermediates[6].end(), code);
00207 t2 = Translate (intermediates[7].begin(), intermediates[7].end(), code);
00208 dist = gdist ((t1)[0],(t2)[0]);
00209 len_path_5 += dist;
00210
00211 t1 = Translate (intermediates[7].begin(), intermediates[7].end(), code);
00212 t2 = Translate (codon2.begin(),codon2.end(), code);
00213 dist = gdist ((t1)[0],(t2)[0]);
00214 len_path_5 += dist;
00215
00216
00217 t1 = Translate (codon1.begin(),codon1.end(), code);
00218 t2 = Translate (intermediates[6].begin(), intermediates[6].end(), code);
00219 dist = gdist ((t1)[0],(t2)[0]);
00220 len_path_6 += dist;
00221
00222 t1 = Translate (intermediates[6].begin(), intermediates[6].end(), code);
00223 t2 = Translate (intermediates[8].begin(), intermediates[8].end(), code);
00224 dist = gdist ((t1)[0],(t2)[0]);
00225 len_path_6 += dist;
00226
00227 t1 = Translate (intermediates[8].begin(), intermediates[8].end(), code);
00228 t2 = Translate (codon2.begin(),codon2.end(), code);
00229 dist = gdist ((t1)[0],(t2)[0]);
00230 len_path_6 += dist;
00231
00232 __weights[0] = 1. / len_path_1;
00233 __weights[1] = 1. /len_path_2;
00234 __weights[2] = 1. /len_path_3;
00235 __weights[3] = 1. / len_path_4;
00236 __weights[4] = 1. /len_path_5;
00237 __weights[5] = 1./ len_path_6;
00238
00239
00240 double w_tot =
00241 __weights[0] + __weights[1] + __weights[2] + __weights[3] + __weights[4] + __weights[5];
00242 __weights[0] /= w_tot;
00243 __weights[1] /= w_tot;
00244 __weights[2] /= w_tot;
00245 __weights[3] /= w_tot;
00246 __weights[4] /= w_tot;
00247 __weights[5] /= w_tot;
00248 }
00249
00250 double * GranthamWeights3::weights(void) const
00254 {
00255 return __weights;
00256 }
00257 }