| 1 | #ifndef BI_HELIX_HXX |
|---|
| 2 | #define BI_HELIX_HXX |
|---|
| 3 | |
|---|
| 4 | #ifndef ARBDB_BASE_H |
|---|
| 5 | #include <arbdb_base.h> |
|---|
| 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 | #ifndef bi_assert |
|---|
| 15 | #define bi_assert(bed) arb_assert(bed) |
|---|
| 16 | #endif |
|---|
| 17 | |
|---|
| 18 | enum BI_PAIR_TYPE { |
|---|
| 19 | HELIX_NONE, // used in entries |
|---|
| 20 | HELIX_STRONG_PAIR, |
|---|
| 21 | HELIX_PAIR, // used in entries |
|---|
| 22 | HELIX_WEAK_PAIR, |
|---|
| 23 | HELIX_NO_PAIR, // used in entries |
|---|
| 24 | HELIX_USER0, |
|---|
| 25 | HELIX_USER1, |
|---|
| 26 | HELIX_USER2, |
|---|
| 27 | HELIX_USER3, |
|---|
| 28 | HELIX_DEFAULT, |
|---|
| 29 | HELIX_NON_STANDARD0, // used in entries |
|---|
| 30 | HELIX_NON_STANDARD1, // used in entries |
|---|
| 31 | HELIX_NON_STANDARD2, // used in entries |
|---|
| 32 | HELIX_NON_STANDARD3, // used in entries |
|---|
| 33 | HELIX_NON_STANDARD4, // used in entries |
|---|
| 34 | HELIX_NON_STANDARD5, // used in entries |
|---|
| 35 | HELIX_NON_STANDARD6, // used in entries |
|---|
| 36 | HELIX_NON_STANDARD7, // used in entries |
|---|
| 37 | HELIX_NON_STANDARD8, // used in entries |
|---|
| 38 | HELIX_NON_STANDARD9, // used in entries |
|---|
| 39 | HELIX_NO_MATCH, |
|---|
| 40 | HELIX_MAX |
|---|
| 41 | }; |
|---|
| 42 | |
|---|
| 43 | struct BI_helix_entry { |
|---|
| 44 | long pair_pos; |
|---|
| 45 | BI_PAIR_TYPE pair_type; |
|---|
| 46 | char *helix_nr; |
|---|
| 47 | |
|---|
| 48 | long next_pair_pos; /* next position with pair_type != HELIX_NONE |
|---|
| 49 | * contains |
|---|
| 50 | * 0 if uninitialized, |
|---|
| 51 | * -1 behind last position */ |
|---|
| 52 | bool allocated; |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | class BI_helix : virtual Noncopyable { |
|---|
| 56 | BI_helix_entry *entries; |
|---|
| 57 | size_t Size; |
|---|
| 58 | |
|---|
| 59 | void _init(); |
|---|
| 60 | |
|---|
| 61 | static char *helix_error; // error occurring during init is stored here |
|---|
| 62 | |
|---|
| 63 | const char *init(GBDATA *gb_main, const char *alignment_name, const char *helix_nr_name, const char *helix_name); |
|---|
| 64 | |
|---|
| 65 | protected: |
|---|
| 66 | |
|---|
| 67 | char *pairs[HELIX_MAX]; |
|---|
| 68 | char *char_bind[HELIX_MAX]; |
|---|
| 69 | |
|---|
| 70 | bool is_pairtype(char left, char right, BI_PAIR_TYPE pair_type); |
|---|
| 71 | |
|---|
| 72 | public: |
|---|
| 73 | |
|---|
| 74 | static char *get_error() { return helix_error; } |
|---|
| 75 | static void clear_error() { freenull(helix_error); } |
|---|
| 76 | static void set_error(const char *err) { freedup(helix_error, err); } |
|---|
| 77 | |
|---|
| 78 | BI_helix(); |
|---|
| 79 | ~BI_helix(); |
|---|
| 80 | |
|---|
| 81 | const char *init(GBDATA *gb_main); |
|---|
| 82 | const char *init(GBDATA *gb_main, const char *alignment_name); |
|---|
| 83 | const char *init(GBDATA *gb_helix_nr, GBDATA *gb_helix, size_t size); |
|---|
| 84 | const char *initFromData(const char *helix_nr, const char *helix, size_t size); |
|---|
| 85 | |
|---|
| 86 | int check_pair(char left, char right, BI_PAIR_TYPE pair_type); // return 1 if bases form a pair |
|---|
| 87 | |
|---|
| 88 | size_t size() const { return Size; } |
|---|
| 89 | bool has_entries() const { return entries; } |
|---|
| 90 | const BI_helix_entry& entry(size_t pos) const { |
|---|
| 91 | bi_assert(pos<Size); |
|---|
| 92 | bi_assert(entries); |
|---|
| 93 | return entries[pos]; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | size_t opposite_position(size_t pos) const { |
|---|
| 97 | const BI_helix_entry& Entry = entry(pos); |
|---|
| 98 | bi_assert(Entry.pair_type != HELIX_NONE); // not a pair -> no opposite position |
|---|
| 99 | return Entry.pair_pos; |
|---|
| 100 | } |
|---|
| 101 | BI_PAIR_TYPE pairtype(size_t pos) const { return pos<Size ? entry(pos).pair_type : HELIX_NONE; } |
|---|
| 102 | const char *helixNr(size_t pos) const { return pairtype(pos) == HELIX_NONE ? 0 : entry(pos).helix_nr; } |
|---|
| 103 | // Note: results of helixNr may be compared by == (instead of strcmp()) |
|---|
| 104 | |
|---|
| 105 | long first_pair_position() const; // first pair position (or -1) |
|---|
| 106 | long next_pair_position(size_t pos) const; // next pair position behind 'pos' (or -1) |
|---|
| 107 | |
|---|
| 108 | long first_position(const char *helixNr) const; // returns -1 for non-existing helixNr's |
|---|
| 109 | long last_position(const char *helixNr) const; // returns -1 for non-existing helixNr's |
|---|
| 110 | }; |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | #endif |
|---|