| 1 | #ifndef PRD_GLOBALS_HXX |
|---|
| 2 | #define PRD_GLOBALS_HXX |
|---|
| 3 | |
|---|
| 4 | #ifndef _GLIBCXX_CLIMITS |
|---|
| 5 | #include <climits> |
|---|
| 6 | #endif |
|---|
| 7 | #ifndef ARB_ASSERT_H |
|---|
| 8 | #include <arb_assert.h> |
|---|
| 9 | #endif |
|---|
| 10 | #ifndef ARBTOOLS_H |
|---|
| 11 | #include <arbtools.h> |
|---|
| 12 | #endif |
|---|
| 13 | |
|---|
| 14 | #define prd_assert(cond) arb_assert(cond) |
|---|
| 15 | |
|---|
| 16 | #ifndef MAX_LONG |
|---|
| 17 | #define MAX_LONG LONG_MAX |
|---|
| 18 | #endif |
|---|
| 19 | |
|---|
| 20 | #define PRD_MAX_SEQUENCE_POS MAX_LONG |
|---|
| 21 | typedef long int PRD_Sequence_Pos; |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | // |
|---|
| 25 | // BaseInverter is used to invert bases while matching sequence |
|---|
| 26 | // backwards vs. the primertrees |
|---|
| 27 | // |
|---|
| 28 | struct BaseInverter { |
|---|
| 29 | char BASE[128]; |
|---|
| 30 | |
|---|
| 31 | BaseInverter() { |
|---|
| 32 | for (int i=0; i < 128; i++) |
|---|
| 33 | BASE[i] = '\x00'; |
|---|
| 34 | |
|---|
| 35 | BASE[(unsigned char)'A'] = 'T'; |
|---|
| 36 | BASE[(unsigned char)'T'] = 'A'; |
|---|
| 37 | BASE[(unsigned char)'U'] = 'A'; |
|---|
| 38 | BASE[(unsigned char)'C'] = 'G'; |
|---|
| 39 | BASE[(unsigned char)'G'] = 'C'; |
|---|
| 40 | |
|---|
| 41 | BASE[(unsigned char)'R'] = 'Y'; |
|---|
| 42 | BASE[(unsigned char)'M'] = 'K'; |
|---|
| 43 | BASE[(unsigned char)'S'] = 'S'; |
|---|
| 44 | BASE[(unsigned char)'Y'] = 'R'; |
|---|
| 45 | BASE[(unsigned char)'K'] = 'M'; |
|---|
| 46 | BASE[(unsigned char)'W'] = 'W'; |
|---|
| 47 | BASE[(unsigned char)'V'] = 'B'; |
|---|
| 48 | BASE[(unsigned char)'B'] = 'V'; |
|---|
| 49 | BASE[(unsigned char)'D'] = 'H'; |
|---|
| 50 | BASE[(unsigned char)'H'] = 'D'; |
|---|
| 51 | BASE[(unsigned char)'N'] = 'N'; |
|---|
| 52 | } |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | static BaseInverter INVERT; |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | struct ChildLookupTable { |
|---|
| 59 | int INDEX[128]; |
|---|
| 60 | |
|---|
| 61 | ChildLookupTable() { |
|---|
| 62 | for (int i=0; i < 128; i++) INDEX[i] = -1; |
|---|
| 63 | |
|---|
| 64 | INDEX[(unsigned char)'C'] = 0; |
|---|
| 65 | INDEX[(unsigned char)'G'] = 1; |
|---|
| 66 | INDEX[(unsigned char)'A'] = 2; |
|---|
| 67 | INDEX[(unsigned char)'T'] = 3; |
|---|
| 68 | INDEX[(unsigned char)'U'] = 3; |
|---|
| 69 | } |
|---|
| 70 | }; |
|---|
| 71 | |
|---|
| 72 | static ChildLookupTable CHAR2CHILD; |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | class BitField { |
|---|
| 76 | // Meaning of single bits: |
|---|
| 77 | // 2^0 = 1 = A |
|---|
| 78 | // 2^1 = 2 = T/U |
|---|
| 79 | // 2^2 = 4 = C |
|---|
| 80 | // 2^3 = 8 = G |
|---|
| 81 | public: |
|---|
| 82 | unsigned int FIELD[128]; // bitoperations are done as unsigned int :( |
|---|
| 83 | |
|---|
| 84 | BitField() { |
|---|
| 85 | for (int i=0; i < 128; i++) |
|---|
| 86 | FIELD[i] = 0; |
|---|
| 87 | |
|---|
| 88 | FIELD[(unsigned char)'A'] = 1; |
|---|
| 89 | FIELD[(unsigned char)'T'] = 2; |
|---|
| 90 | FIELD[(unsigned char)'U'] = 2; |
|---|
| 91 | FIELD[(unsigned char)'C'] = 4; |
|---|
| 92 | FIELD[(unsigned char)'G'] = 8; |
|---|
| 93 | |
|---|
| 94 | FIELD[(unsigned char)'R'] = 9; // A G |
|---|
| 95 | FIELD[(unsigned char)'M'] = 5; // A C |
|---|
| 96 | FIELD[(unsigned char)'S'] = 12; // CG |
|---|
| 97 | FIELD[(unsigned char)'Y'] = 6; // TC |
|---|
| 98 | FIELD[(unsigned char)'K'] = 10; // T G |
|---|
| 99 | FIELD[(unsigned char)'W'] = 3; // AT |
|---|
| 100 | FIELD[(unsigned char)'V'] = 13; // A CG |
|---|
| 101 | FIELD[(unsigned char)'B'] = 14; // TCG |
|---|
| 102 | FIELD[(unsigned char)'D'] = 11; // AT G |
|---|
| 103 | FIELD[(unsigned char)'H'] = 7; // ATC |
|---|
| 104 | FIELD[(unsigned char)'N'] = 15; // ATCG |
|---|
| 105 | } |
|---|
| 106 | }; |
|---|
| 107 | |
|---|
| 108 | static BitField CHAR2BIT; |
|---|
| 109 | |
|---|
| 110 | #else |
|---|
| 111 | #error PRD_Globals.hxx included twice |
|---|
| 112 | #endif // PRD_GLOBALS_HXX |
|---|