39 struct RedundancyCom95impl
46 double firstNon[4][4][4];
47 double first2S[4][4][4];
48 double first2V[4][4][4];
49 double thirdFour[4][4][4];
50 double thirdNon[4][4][4];
51 double third2S[4][4][4];
52 double third2V[4][4][4];
53 double l0_vals[4][4][4];
54 double l2S_vals[4][4][4];
55 double l2V_vals[4][4][4];
56 double l4_vals[4][4][4];
57 void FillFirstPositionCounts ();
58 void FillThirdPositionCounts ();
60 void codonPrecondition(
const std::string & codon);
63 RedundancyCom95impl::RedundancyCom95impl(
const GeneticCodes code) : genetic_code(code)
65 FillFirstPositionCounts ();
66 FillThirdPositionCounts ();
70 void RedundancyCom95impl::codonPrecondition(
const std::string & codon)
79 if ( codon.length() != 3 ||
80 std::find_if(codon.begin(),codon.end(),ambiguousNucleotide()) != codon.end() )
82 throw(std::runtime_error(
"Sequence::RedundancyCom95 -- precondition failed, invalid codon"));
87 RedundancyCom95impl::FillFirstPositionCounts ()
89 std::string codon,mutation;
90 int numN, numTsS, numTvS;
92 int numPossTs, numPossTv;
93 double FirstN, First2S, First2V;
94 std::string codonTrans;
95 std::string mutationTrans;
101 for(
unsigned i = 0 ;
i < 4 ; ++
i )
103 for(
unsigned j = 0 ;
j < 4 ; ++
j )
105 for(
unsigned k = 0 ; k < 4 ; ++k )
107 numN = numTsS = numTvS = 0;
108 numPossTs = numPossTv = 0;
117 for(
unsigned l = 0 ; l < 4 ; ++l )
122 mutation[1] = codon[1];
123 mutation[2] = codon[2];
126 codon.end(), genetic_code);
127 mutationTrans =
Translate (mutation.begin(),
128 mutation.end(),genetic_code);
131 if ((codonTrans)[0] !=
'*' 132 && (mutationTrans)[0] !=
'*')
134 if(codonTrans == mutationTrans)
144 if (type == Mutations::Ts)
146 else if (type == Mutations::Tv)
150 else if (S == 1 && type == Mutations::Ts)
153 else if (S == 1 && type == Mutations::Tv)
160 if ((numPossTs + numPossTv) == 0)
166 else if ((numTsS + numTvS) == 0)
172 else if (numPossTs != 0 && numPossTv != 0)
174 if (
double (numTsS) /
175 double (numPossTs) != 1.0
177 double (numPossTv) != 1.0)
187 FirstN = 1.0 - First2S -
198 FirstN = 1.0 - First2S -
207 double (numPossTs + numPossTv);
214 double (numPossTv + numPossTs);
217 FirstN = 1.0 - First2S - First2V;
220 firstNon[
i][
j][k]=FirstN;
221 first2S[
i][
j][k]=First2S;
222 first2V[
i][
j][k]=First2V;
229 RedundancyCom95impl::FillThirdPositionCounts ()
231 std::string codon, mutation;
232 int numN, numTsS, numTvS;
234 int numPossTs, numPossTv;
235 double ThirdN, Third2S, Third2V, Third4;
236 std::string codonTrans;
237 std::string mutationTrans;
242 for(
unsigned i = 0 ;
i < 4 ; ++
i )
244 for(
unsigned j = 0 ;
j < 4 ; ++
j )
246 for(
unsigned k = 0 ; k < 4 ; ++k )
248 numN = numTsS = numTvS = 0;
249 numPossTs = numPossTv = 0;
257 for(
unsigned l = 0 ; l < 4 ; ++l )
261 mutation[0] = codon[0];
262 mutation[1] = codon[1];
266 codon.end(),genetic_code);
267 mutationTrans =
Translate (mutation.begin(),
268 mutation.end(),genetic_code);
270 if ((codonTrans)[0] !=
'*' 271 && (mutationTrans)[0] !=
'*')
273 if(codonTrans==mutationTrans)
283 if (type == Mutations::Ts)
285 else if (type == Mutations::Tv)
289 else if (S && type == Mutations::Ts)
291 else if (S && type == Mutations::Tv)
297 ThirdN = Third2S = Third2V = Third4 = 0.0;
298 if (numPossTs + numPossTv == 0)
305 else if (numTsS + numTvS == 0)
312 else if (numTsS + numTvS == 3)
319 else if (numTsS == 0 || numTvS == 0)
333 ThirdN = 1.0 - Third2S - Third2V;
336 else if (numTsS > 0 && numTvS > 0
337 && (
double (numTsS) /
338 double (numPossTs) != 1.0
340 double (numPossTv) != 1.0))
347 thirdNon[
i][
j][k]=ThirdN;
348 third2S[
i][
j][k]=Third2S;
349 third2V[
i][
j][k]=Third2V;
350 thirdFour[
i][
j][k]=Third4;
358 RedundancyCom95impl::FillLValues ()
362 std::string codon(3,
'A');
363 for(
unsigned i = 0 ;
i < 4 ; ++
i )
364 for(
unsigned j = 0 ;
j < 4 ; ++
j )
365 for(
unsigned k = 0 ; k < 4 ; ++k )
371 trans =
Translate (codon.begin(),codon.end(), genetic_code);
372 if(strcmp(trans.c_str(),
"*")!=0)
374 l0_vals[
i][
j][k] = 1. + firstNon[
i][
j][k] + thirdNon[
i][
j][k];
375 l2S_vals[
i][
j][k] = first2S[
i][
j][k] + third2S[
i][
j][k];
376 l2V_vals[
i][
j][k] = first2V[
i][
j][k] + third2V[
i][
j][k];
377 l4_vals[
i][
j][k] = thirdFour[
i][
j][k];
381 l0_vals[
i][
j][k] = l2S_vals[
i][
j][k] = l2V_vals[
i][
j][k] = l4_vals[
i][
j][k] = 0.;
387 impl(
std::unique_ptr<RedundancyCom95impl>(new RedundancyCom95impl(code)))
394 RedundancyCom95::~RedundancyCom95(
void)
410 impl->codonPrecondition(codon);
420 return impl->firstNon[i][j][k];
433 impl->codonPrecondition(codon);
443 return impl->first2S[i][j][k];
455 impl->codonPrecondition(codon);
465 return impl->first2V[i][j][k];
477 impl->codonPrecondition(codon);
487 return impl->thirdNon[i][j][k];
499 impl->codonPrecondition(codon);
509 return impl->thirdFour[i][j][k];
521 impl->codonPrecondition(codon);
531 return impl->third2S[i][j][k];
543 impl->codonPrecondition(codon);
553 return impl->third2V[i][j][k];
566 impl->codonPrecondition(codon);
576 return impl->l0_vals[i][j][k];
589 impl->codonPrecondition(codon);
599 return impl->l2S_vals[i][j][k];
612 impl->codonPrecondition(codon);
622 return impl->l2V_vals[i][j][k];
635 impl->codonPrecondition(codon);
645 return impl->l4_vals[i][j][k];
650 return impl->genetic_code;
Mutations TsTv(const char &i, const char &j)
double i
Position of site i.
std::string Translate(std::string::const_iterator beg, std::string::const_iterator end, Sequence::GeneticCodes genetic_code=GeneticCodes::UNIVERSAL, const char &gapchar='-')
double L2S_vals(const std::string &codon) const
double j
Position of site j.
The namespace in which this library resides.
const alphabet_t dna_alphabet
Alphabet for DNA sequences Valid DNA characters. Upper-case only. Only - is accepted as gap character...
double First2V(const std::string &codon) const
double FirstNon(const std::string &codon) const
double ThirdFour(const std::string &codon) const
declares Sequence::Translate,a function to translate CDS sequences into peptide sequences ...
class Sequence::RedundancyCom95
double L2V_vals(const std::string &codon) const
double ThirdNon(const std::string &codon) const
double Third2V(const std::string &codon) const
double L4_vals(const std::string &codon) const
double First2S(const std::string &codon) const
delcaration of routines for comparing DNA sequences This file declares a set of functions useful for ...
double Third2S(const std::string &codon) const
Definition of enumeration types.
double L0_vals(const std::string &codon) const
RedundancyCom95(Sequence::GeneticCodes genetic_code=GeneticCodes::UNIVERSAL)