ARB
BI_helix.hxx
Go to the documentation of this file.
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 
23 
25 
32 
34 };
35 
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 
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
bool is_pairpos(size_t pos) const
Definition: BI_helix.hxx:117
const char * GB_ERROR
Definition: arb_core.h:25
Definition: BI_helix.hxx:73
const BI_helix_entry & entry(size_t pos) const
Definition: BI_helix.hxx:107
void set_pairs_def(int i, const char *new_pairs_def)
Definition: BI_helix.hxx:62
BI_PAIR_TYPE
Definition: BI_helix.hxx:19
int pair_strength(char left, char right)
Definition: BI_helix.cxx:94
long pair_pos
Definition: BI_helix.hxx:74
long first_position(const char *helixNr) const
Definition: BI_helix.cxx:369
size_t opposite_position(size_t pos) const
Definition: BI_helix.hxx:113
static char * alignment_name
const char * get_pairs_def(int i) const
Definition: BI_helix.hxx:53
void set_char_bind(int i, const char *new_char_bind)
Definition: BI_helix.hxx:66
bool is_pairpos
Definition: BI_helix.hxx:75
bool allocated
Definition: BI_helix.hxx:82
long last_position(const char *helixNr) const
Definition: BI_helix.cxx:377
long first_pair_position() const
Definition: BI_helix.cxx:342
static GB_ERROR get_error()
Definition: BI_helix.hxx:96
long next_pair_position(size_t pos) const
Definition: BI_helix.cxx:346
size_t size() const
Definition: BI_helix.hxx:105
const char * helixNr(size_t pos) const
Definition: BI_helix.hxx:118
#define bi_assert(bed)
Definition: BI_helix.hxx:15
long next_pair_pos
Definition: BI_helix.hxx:78
char get_symbol(char left, char right) const
Definition: BI_helix.cxx:79
bool has_entries() const
Definition: BI_helix.hxx:106
char * helix_nr
Definition: BI_helix.hxx:76
GB_ERROR initFromData(const char *helix_nr, const char *helix, size_t size)
Definition: BI_helix.cxx:158
#define NULp
Definition: cxxforward.h:116
const char * get_char_bind(int i) const
Definition: BI_helix.hxx:57
GBDATA * gb_main
Definition: adname.cxx:32
const BI_PAIR_TYPE PAIR_TYPE_COUNT
Definition: BI_helix.hxx:36
GB_ERROR init(GBDATA *gb_main)
Definition: BI_helix.cxx:327