| 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 | |
|---|
| 19 | enum BI_PAIR_TYPE { |
|---|
| 20 | HELIX_STRONG_PAIR, |
|---|
| 21 | HELIX_NORMAL_PAIR, |
|---|
| 22 | HELIX_WEAK_PAIR, |
|---|
| 23 | |
|---|
| 24 | HELIX_NO_PAIR, |
|---|
| 25 | |
|---|
| 26 | HELIX_USER0, |
|---|
| 27 | HELIX_USER1, |
|---|
| 28 | HELIX_USER2, |
|---|
| 29 | HELIX_USER3, |
|---|
| 30 | HELIX_USER4, |
|---|
| 31 | HELIX_USER5, |
|---|
| 32 | |
|---|
| 33 | HELIX_DEFAULT, |
|---|
| 34 | }; |
|---|
| 35 | |
|---|
| 36 | const BI_PAIR_TYPE PAIR_TYPE_COUNT = BI_PAIR_TYPE(HELIX_DEFAULT+1); |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | class BI_pairdef : virtual Noncopyable { |
|---|
| 40 | |
|---|
| 41 | bool is_pairtype(char left, char right, BI_PAIR_TYPE pair_type) const; |
|---|
| 42 | |
|---|
| 43 | char *pairs_def[PAIR_TYPE_COUNT]; // pairs of upper case sequence characters (or gaps). separated by spaces. e.g.: "AC GT C-" |
|---|
| 44 | char *char_bind[PAIR_TYPE_COUNT]; // helix symbol used for pairs listed in pairs_def |
|---|
| 45 | |
|---|
| 46 | public: |
|---|
| 47 | BI_pairdef(); |
|---|
| 48 | ~BI_pairdef(); |
|---|
| 49 | |
|---|
| 50 | char get_symbol(char left, char right) const; |
|---|
| 51 | int pair_strength(char left, char right); // return >0 if bases form a pair |
|---|
| 52 | |
|---|
| 53 | const char *get_pairs_def(int i) const { |
|---|
| 54 | bi_assert(i>=0 && i<PAIR_TYPE_COUNT); |
|---|
| 55 | return pairs_def[i]; |
|---|
| 56 | } |
|---|
| 57 | const char *get_char_bind(int i) const { |
|---|
| 58 | bi_assert(i>=0 && i<PAIR_TYPE_COUNT); |
|---|
| 59 | return char_bind[i]; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | void set_pairs_def(int i, const char *new_pairs_def) { |
|---|
| 63 | bi_assert(i>=0 && i<PAIR_TYPE_COUNT); |
|---|
| 64 | freedup(pairs_def[i], new_pairs_def); |
|---|
| 65 | } |
|---|
| 66 | void set_char_bind(int i, const char *new_char_bind) { |
|---|
| 67 | bi_assert(i>=0 && i<PAIR_TYPE_COUNT); |
|---|
| 68 | freedup(char_bind[i], new_char_bind); |
|---|
| 69 | } |
|---|
| 70 | }; |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | struct BI_helix_entry { |
|---|
| 74 | long pair_pos; |
|---|
| 75 | bool is_pairpos; // true if position is a pairing position |
|---|
| 76 | char *helix_nr; |
|---|
| 77 | |
|---|
| 78 | long next_pair_pos; /* next position with pair_type != HELIX_NONE |
|---|
| 79 | * contains |
|---|
| 80 | * 0 if uninitialized, |
|---|
| 81 | * -1 behind last position */ |
|---|
| 82 | bool allocated; |
|---|
| 83 | }; |
|---|
| 84 | |
|---|
| 85 | class BI_helix : virtual Noncopyable { |
|---|
| 86 | BI_helix_entry *entries; |
|---|
| 87 | size_t Size; |
|---|
| 88 | |
|---|
| 89 | static char *helix_error; // error occurring during init is stored here |
|---|
| 90 | |
|---|
| 91 | static void clear_error() { freenull(helix_error); } |
|---|
| 92 | static void set_error(GB_ERROR err) { freedup(helix_error, err); } |
|---|
| 93 | |
|---|
| 94 | public: |
|---|
| 95 | |
|---|
| 96 | static GB_ERROR get_error() { return helix_error; } |
|---|
| 97 | |
|---|
| 98 | BI_helix(); |
|---|
| 99 | ~BI_helix(); |
|---|
| 100 | |
|---|
| 101 | GB_ERROR init(GBDATA *gb_main); // [used by NALIGNER + EDIT4] |
|---|
| 102 | GB_ERROR init(GBDATA *gb_main, const char *alignment_name); // [used by SEQ_QUALITY + ColumnStat + SINA] |
|---|
| 103 | GB_ERROR initFromData(const char *helix_nr, const char *helix, size_t size); // [used from SECEDIT] |
|---|
| 104 | |
|---|
| 105 | size_t size() const { return Size; } |
|---|
| 106 | bool has_entries() const { return entries; } |
|---|
| 107 | const BI_helix_entry& entry(size_t pos) const { |
|---|
| 108 | bi_assert(pos<Size); |
|---|
| 109 | bi_assert(entries); |
|---|
| 110 | return entries[pos]; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | size_t opposite_position(size_t pos) const { |
|---|
| 114 | bi_assert(is_pairpos(pos)); // not a pair -> no opposite position |
|---|
| 115 | return entry(pos).pair_pos; |
|---|
| 116 | } |
|---|
| 117 | bool is_pairpos(size_t pos) const { return pos<Size && entry(pos).is_pairpos; } |
|---|
| 118 | const char *helixNr(size_t pos) const { return is_pairpos(pos) ? entry(pos).helix_nr : NULp; } |
|---|
| 119 | // Note: results of helixNr may be compared by == (instead of strcmp()) |
|---|
| 120 | |
|---|
| 121 | long first_pair_position() const; // first pair position (or -1) |
|---|
| 122 | long next_pair_position(size_t pos) const; // next pair position behind 'pos' (or -1) |
|---|
| 123 | |
|---|
| 124 | long first_position(const char *helixNr) const; // returns -1 for non-existing helixNr's |
|---|
| 125 | long last_position(const char *helixNr) const; // returns -1 for non-existing helixNr's |
|---|
| 126 | |
|---|
| 127 | // Note: all position-values used in BI_helix are in range [0 .. N-1]. |
|---|
| 128 | // Consider using info2bio() when using these positions in error messages or similar. |
|---|
| 129 | }; |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | #endif |
|---|