source: branches/profile/SL/PRONUC/AP_codon_table.hxx

Last change on this file was 12706, checked in by westram, 11 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
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#ifndef STATIC_ASSERT_H
19#include <static_assert.h>
20#endif
21#ifndef _STDINT_H
22#include <stdint.h>
23#endif
24
25#define pn_assert(cond) arb_assert(cond)
26
27// --------------------------------------------------------------------------------
28
29struct AWT_Codon_Code_Definition {
30    const char *name;
31    const char *aa;             // amino-codes
32    const char *starts;
33    int         embl_feature_transl_table; // number of transl_table-entry in EMBL/GENEBANK features list
34};
35
36#define AWT_CODON_TABLES 17     // number of different Amino-Translation-Tables
37#define AWT_MAX_CODONS   64     // maximum of possible codon ( = 4^3)
38
39const int AWAR_PROTEIN_TYPE_bacterial_code_index = 8; // contains the index of the bacterial code table
40
41// --------------------------------------------------------------------------------
42
43#define ALL_TABLES_MASK ((1<<AWT_CODON_TABLES)-1)
44
45class TransTables {
46    uint32_t allowed;
47
48    static uint32_t bitmask(int nr) { pn_assert(nr >= 0 && nr<AWT_CODON_TABLES); return 1<<nr; }
49
50public:
51    TransTables() { allowAll(); }
52
53    bool is_allowed(int nr) const { return (allowed & bitmask(nr)) != 0; }
54    bool any()  const { return  allowed; }
55    bool none() const { return !allowed; }
56    bool all() const { return allowed == ALL_TABLES_MASK; }
57
58    void allow(int nr) { allowed |= bitmask(nr); }
59    void forbid(int nr) { allowed &= ~bitmask(nr); }
60    void forbid(const TransTables& other) { allowed &= ~other.allowed; }
61
62    void allowAll() {
63        STATIC_ASSERT(sizeof(allowed)*8 > AWT_CODON_TABLES); // one bit wasted
64        allowed = ALL_TABLES_MASK;
65    }
66    void forbidAll() { allowed = 0; }
67    void forbidAllBut(int nr) { allowed &= bitmask(nr); }
68
69    int explicit_table() const {
70        // return explicit table number (or -1 if not exactly one table is allowed)
71        if (any()) {
72            uint32_t tabs = allowed;
73            for (int t = 0; t<AWT_CODON_TABLES; ++t) {
74                if (tabs&1) return (tabs == 1) ? t : -1;
75                tabs >>= 1;
76            }
77            pn_assert(0);
78        }
79        return -1;
80    }
81
82    bool is_subset_of(const TransTables& other) const { return (allowed&other.allowed) == allowed; }
83
84    const char *to_string() const {
85        const int    MAX_LEN = 42;
86        static char  buffer[MAX_LEN];
87        char        *out     = buffer;
88
89        for (int a = 0; a<AWT_CODON_TABLES; ++a) {
90            if (is_allowed(a)) {
91                out += sprintf(out, ",%i", a);
92            }
93        }
94        pn_assert((out-buffer)<MAX_LEN);
95        out[0] = 0;
96        return buffer+1;
97    }
98
99};
100
101// --------------------------------------------------------------------------------
102
103void AP_initialize_codon_tables();
104
105int AWT_embl_transl_table_2_arb_code_nr(int embl_code_nr);
106int AWT_arb_code_nr_2_embl_transl_table(int arb_code_nr);
107
108bool        AWT_is_codon(char protein, const char *const dna, const TransTables& allowed, TransTables& allowed_left, const char **fail_reason_ptr = 0);
109const char *AP_get_codons(char protein, int code_nr);
110
111char AWT_is_start_codon(const char *dna, int arb_code_nr);
112
113const char *AP_get_protein_name(char protein);
114const char* AWT_get_codon_code_name(int code);
115
116#ifdef DEBUG
117void AWT_dump_codons();
118void test_AWT_get_codons();
119#endif
120
121// --------------------------------------------------------------------------------
122
123#else
124#error AP_codon_table.hxx included twice
125#endif // AP_CODON_TABLE_HXX
Note: See TracBrowser for help on using the repository browser.