Skip to content

Instantly share code, notes, and snippets.

Created November 28, 2012 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4162316 to your computer and use it in GitHub Desktop.
Save anonymous/4162316 to your computer and use it in GitHub Desktop.
Count of how many single base substitutions result in a change of the amino acid.
#include <iostream>
#include <map>
using namespace std;
const static string codon_table[64][2] = {
{"TTT", "F"}, {"TTC", "F"}, {"TTA", "L"}, {"TTG", "L"}, {"TCT", "S"}, {"TCC", "S"}, {"TCA", "S"}, {"TCG", "S"},
{"TAT", "Y"}, {"TAC", "Y"}, {"TAA", "X"}, {"TAG", "X"}, {"TGT", "C"}, {"TGC", "C"}, {"TGA", "X"}, {"TGG", "W"},
{"CTT", "L"}, {"CTC", "L"}, {"CTA", "L"}, {"CTG", "L"}, {"CCT", "P"}, {"CCC", "P"}, {"CCA", "P"}, {"CCG", "P"},
{"CAT", "H"}, {"CAC", "H"}, {"CAA", "Q"}, {"CAG", "Q"}, {"CGT", "R"}, {"CGC", "R"}, {"CGA", "R"}, {"CGG", "R"},
{"ATT", "I"}, {"ATC", "I"}, {"ATA", "I"}, {"ATG", "M"}, {"ACT", "T"}, {"ACC", "T"}, {"ACA", "T"}, {"ACG", "T"},
{"AAT", "N"}, {"AAC", "N"}, {"AAA", "K"}, {"AAG", "K"}, {"AGT", "S"}, {"AGC", "S"}, {"AGA", "R"}, {"AGG", "R"},
{"GTT", "V"}, {"GTC", "V"}, {"GTA", "V"}, {"GTG", "V"}, {"GCT", "A"}, {"GCC", "A"}, {"GCA", "A"}, {"GCG", "A"},
{"GAT", "D"}, {"GAC", "D"}, {"GAA", "E"}, {"GAG", "E"}, {"GGT", "G"}, {"GGC", "G"}, {"GGA", "G"}, {"GGG", "G"},
};
const static string bases = "ACGT";
int main(int argc, const char * argv[]){
int total = 0;
int silent = 0;
int nonsilent = 0;
map<string, string> codons;
for(int i = 0; i < 64; i++){
codons[codon_table[i][0]] = codon_table[i][1];
}
for(int i = 0; i < 64; i++){
string triplet = codon_table[i][0];
string amino_acid = codons[triplet];
for(int j = 0; j < 3; j++){
for(int k = 0; k < 4; k++){
if(bases[k] == triplet[j]){
continue;
}
string temp = triplet;
temp.at(j) = bases[k];
string aa = codons[temp];
total++;
if(aa == amino_acid){
silent++;
}else{
nonsilent++;
}
}
}
}
cout << silent << endl;
cout << nonsilent << endl;
cout << total << endl;
/*
result should be
silent: 138
nonsilent: 438
total: 576
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment