1 #ifndef CODONS_H
2 #define CODONS_H
3 #include "GBase.h"
4 #include <ctype.h>
5 
6 unsigned short packCodon(char n1, char n2, char n3);
7 //assumes n1,n2,n3 are UPPERCASE!
8 
9 struct Codon {
10  char nuc[3];
11  Codon(char* str=NULL) {
12   if (str==NULL) {
13    nuc[0]='N';
14    nuc[1]='N';
15    nuc[2]='N';
16    }
17   else {
18    nuc[0]=toupper(str[0]);
19    nuc[1]=toupper(str[1]);
20    nuc[2]=toupper(str[2]);
21    }
22   }
23 
CodonCodon24  Codon(char s1, char s2, char s3) {
25    nuc[0]=toupper(s1);
26    nuc[1]=toupper(s2);
27    nuc[2]=toupper(s3);
28    }
29 
30 
31  char& operator[](int idx) {
32    if (idx<0 || idx>2)
33       GError("Error: Codon index out of bounds!\n");
34    return nuc[idx];
35    }
36 
37  char operator[](int idx) const {
38    if (idx<0 || idx>2)
39       GError("Error: Codon index out of bounds!\n");
40    return nuc[idx];
41    }
42 
43  char translate();
44  };
45 
46 //simple 1st frame forward translation of a given DNA string
47 //will allocated memory for the translation --  the caller is
48 // responsible for freeing the returned string!
49 char* translateDNA(const char* dnastr, int& aalen, int dnalen=0);
50 
51 
52 bool codonTableInit();
53 
54 #endif
55