1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : AP_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 AP_CODON_TABLE_HXX |
---|
13 | #define AP_CODON_TABLE_HXX |
---|
14 | |
---|
15 | #ifndef ARB_ASSERT_H |
---|
16 | #include <arb_assert.h> |
---|
17 | #endif |
---|
18 | |
---|
19 | #define pn_assert(cond) arb_assert(cond) |
---|
20 | |
---|
21 | // -------------------------------------------------------------------------------- |
---|
22 | |
---|
23 | struct AWT_Codon_Code_Definition { |
---|
24 | const char *name; |
---|
25 | const char *aa; // amino-codes |
---|
26 | const char *starts; |
---|
27 | int embl_feature_transl_table; // number of transl_table-entry in EMBL/GENEBANK features list |
---|
28 | }; |
---|
29 | |
---|
30 | #define AWT_CODON_TABLES 17 // number of different Amino-Translation-Tables |
---|
31 | #define AWT_MAX_CODONS 64 // maximum of possible codon (= 4^3) |
---|
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 | |
---|
51 | void legal(int IF_ASSERTION_USED(nr)) const { pn_assert(nr >= 0 && nr<AWT_CODON_TABLES); } |
---|
52 | |
---|
53 | public: |
---|
54 | AWT_allowedCode() { set(1); } |
---|
55 | AWT_allowedCode(const AWT_allowedCode& other) { copy(other); } |
---|
56 | AWT_allowedCode& operator=(const AWT_allowedCode& other) { copy(other); return *this; } |
---|
57 | |
---|
58 | int is_allowed(int nr) const { legal(nr); return allowed[nr]!=0; } |
---|
59 | void allow(int nr) { legal(nr); allowed[nr]=1; } |
---|
60 | void forbid(int nr) { legal(nr); allowed[nr]=0; } |
---|
61 | |
---|
62 | void forbidAll() { set(0); } |
---|
63 | void allowAll() { set(1); } |
---|
64 | |
---|
65 | void forbidAllBut(int nr) { |
---|
66 | legal(nr); |
---|
67 | for (int a=0; a<AWT_CODON_TABLES; a++) { |
---|
68 | if (a != nr) allowed[a] = 0; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | int explicit_table() const { |
---|
73 | // return explicit table number (or -1 if not exactly 1 table is allowed) |
---|
74 | int table = -1; |
---|
75 | for (int i = 0; i<AWT_CODON_TABLES; ++i) { |
---|
76 | if (allowed[i]) { |
---|
77 | if (table != -1) return -1; |
---|
78 | table = i; |
---|
79 | } |
---|
80 | } |
---|
81 | return table; |
---|
82 | } |
---|
83 | }; |
---|
84 | |
---|
85 | // -------------------------------------------------------------------------------- |
---|
86 | |
---|
87 | void AP_initialize_codon_tables(); |
---|
88 | |
---|
89 | int AWT_embl_transl_table_2_arb_code_nr(int embl_code_nr); |
---|
90 | int AWT_arb_code_nr_2_embl_transl_table(int arb_code_nr); |
---|
91 | |
---|
92 | bool AWT_is_codon(char protein, const char *dna, const AWT_allowedCode& allowed_code, AWT_allowedCode& allowed_code_left, const char **fail_reason = 0); |
---|
93 | const char *AP_get_codons(char protein, int code_nr); |
---|
94 | |
---|
95 | char AWT_is_start_codon(const char *dna, int arb_code_nr); |
---|
96 | |
---|
97 | const char *AP_get_protein_name(char protein); |
---|
98 | const char* AWT_get_codon_code_name(int code); |
---|
99 | |
---|
100 | #ifdef DEBUG |
---|
101 | void AWT_dump_codons(); |
---|
102 | void test_AWT_get_codons(); |
---|
103 | #endif |
---|
104 | |
---|
105 | // -------------------------------------------------------------------------------- |
---|
106 | |
---|
107 | #else |
---|
108 | #error AP_codon_table.hxx included twice |
---|
109 | #endif // AP_CODON_TABLE_HXX |
---|