1 | // =========================================================== // |
---|
2 | // // |
---|
3 | // File : awt_codon_table.hxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // =========================================================== // |
---|
11 | |
---|
12 | #ifndef AWT_CODON_TABLE_HXX |
---|
13 | #define AWT_CODON_TABLE_HXX |
---|
14 | |
---|
15 | #ifndef AWT_HXX |
---|
16 | #include <awt.hxx> |
---|
17 | #endif |
---|
18 | |
---|
19 | // -------------------------------------------------------------------------------- |
---|
20 | |
---|
21 | struct AWT_Codon_Code_Definition { |
---|
22 | const char *name; |
---|
23 | const char *aa; // amino-codes |
---|
24 | const char *starts; |
---|
25 | int embl_feature_transl_table; // number of transl_table-entry in EMBL/GENEBANK features list |
---|
26 | }; |
---|
27 | |
---|
28 | #define AWT_CODON_TABLES 17 // number of different Amino-Translation-Tables |
---|
29 | #define AWT_MAX_CODONS 64 // maximum of possible codon (= 4^3) |
---|
30 | |
---|
31 | extern struct AWT_Codon_Code_Definition AWT_codon_def[AWT_CODON_TABLES+1]; |
---|
32 | |
---|
33 | const int AWAR_PROTEIN_TYPE_bacterial_code_index = 8; // contains the index of the bacterial code table |
---|
34 | |
---|
35 | // -------------------------------------------------------------------------------- |
---|
36 | |
---|
37 | class AWT_allowedCode { |
---|
38 | char allowed[AWT_CODON_TABLES]; |
---|
39 | |
---|
40 | void copy(const AWT_allowedCode& other) { |
---|
41 | for (int a=0; a<AWT_CODON_TABLES; a++) { |
---|
42 | allowed[a] = other.allowed[a]; |
---|
43 | } |
---|
44 | } |
---|
45 | void set(int val) { |
---|
46 | for (int a=0; a<AWT_CODON_TABLES; a++) { |
---|
47 | allowed[a] = val; |
---|
48 | } |
---|
49 | } |
---|
50 | void legal(int nr) const { |
---|
51 | if (nr<0 || nr>=AWT_CODON_TABLES) { |
---|
52 | *((char*)0)=0; // throw exception |
---|
53 | } |
---|
54 | } |
---|
55 | public: |
---|
56 | AWT_allowedCode() { set(1); } |
---|
57 | AWT_allowedCode(const AWT_allowedCode& other) { copy(other); } |
---|
58 | AWT_allowedCode& operator=(const AWT_allowedCode& other) { copy(other); return *this; } |
---|
59 | |
---|
60 | int is_allowed(int nr) const { legal(nr); return allowed[nr]!=0; } |
---|
61 | void allow(int nr) { legal(nr); allowed[nr]=1; } |
---|
62 | void forbid(int nr) { legal(nr); allowed[nr]=0; } |
---|
63 | |
---|
64 | void forbidAll() { set(0); } |
---|
65 | void allowAll() { set(1); } |
---|
66 | |
---|
67 | void forbidAllBut(int nr) { |
---|
68 | legal(nr); |
---|
69 | for (int a=0; a<AWT_CODON_TABLES; a++) { |
---|
70 | if (a != nr) allowed[a] = 0; |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | int explicit_table() const { |
---|
75 | // return explicit table number (or -1 if not exactly 1 table is allowed) |
---|
76 | int table = -1; |
---|
77 | for (int i = 0; i<AWT_CODON_TABLES; ++i) { |
---|
78 | if (allowed[i]) { |
---|
79 | if (table != -1) return -1; |
---|
80 | table = i; |
---|
81 | } |
---|
82 | } |
---|
83 | return table; |
---|
84 | } |
---|
85 | }; |
---|
86 | |
---|
87 | // -------------------------------------------------------------------------------- |
---|
88 | |
---|
89 | void AWT_initialize_codon_tables(); |
---|
90 | |
---|
91 | int AWT_embl_transl_table_2_arb_code_nr(int embl_code_nr); |
---|
92 | int AWT_arb_code_nr_2_embl_transl_table(int arb_code_nr); |
---|
93 | |
---|
94 | bool AWT_is_codon(char protein, const char *dna, const AWT_allowedCode& allowed_code, AWT_allowedCode& allowed_code_left, const char **fail_reason = 0); |
---|
95 | const char *AWT_get_codons(char protein, int code_nr); |
---|
96 | |
---|
97 | char AWT_is_start_codon(const char *dna, int arb_code_nr); |
---|
98 | |
---|
99 | const char *AWT_get_protein_name(char protein); |
---|
100 | const char* AWT_get_codon_code_name(int code); |
---|
101 | |
---|
102 | #ifdef DEBUG |
---|
103 | void AWT_dump_codons(); |
---|
104 | void test_AWT_get_codons(); |
---|
105 | #endif |
---|
106 | |
---|
107 | // -------------------------------------------------------------------------------- |
---|
108 | |
---|
109 | |
---|
110 | #else |
---|
111 | #error awt_codon_table.hxx included twice |
---|
112 | #endif // AWT_CODON_TABLE_HXX |
---|