unsigned n_nuc_differences(const Triplets& T,int i,int j) { unsigned n=0; for(int pos=0;pos<3;pos++) if (T.sub_nuc(i,pos) != T.sub_nuc(j,pos)) n++; return n; }
valarray<double> get_codon_frequencies_from_independent_nucleotide_frequencies(const Triplets& C,const valarray<double>& fN ) { valarray<double> fC(C.size()); for(int i=0;i<fC.size();i++) { fC[i] = 1.0; for(int pos=0;pos<3;pos++) fC[i] *= fN[ C.sub_nuc(i,pos) ]; } fC /= fC.sum(); return fC; }
valarray<double> get_nucleotide_counts_from_codon_counts(const Triplets& C,const valarray<double>& C_counts) { const Nucleotides& N = C.getNucleotides(); valarray<double> N_counts(0.0,N.size()); // For each codon type for(int i=0;i<C.size();i++) { // For each position in the codon for(int pos=0;pos<3;pos++) // Cound the nucleotides that occur there N_counts[ C.sub_nuc(i,pos) ] += C_counts[i]; } return N_counts; }