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 
19  HELIX_NONE, // used in entries
21  HELIX_PAIR, // used in entries
23  HELIX_NO_PAIR, // used in entries
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
41 };
42 
44  long pair_pos;
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  GB_ERROR init(GBDATA *gb_main, const char *alignment_name, const char *helix_nr_name, const char *helix_name);
64 
65  static void clear_error() { freenull(helix_error); }
66  static void set_error(GB_ERROR err) { freedup(helix_error, err); }
67 
68 protected:
69 
70  char *pairs[HELIX_MAX];
72 
73  bool is_pairtype(char left, char right, BI_PAIR_TYPE pair_type);
74 
75 public:
76 
77  static GB_ERROR get_error() { return helix_error; }
78 
79  BI_helix();
80  ~BI_helix();
81 
82  GB_ERROR init(GBDATA *gb_main);
83  GB_ERROR init(GBDATA *gb_main, const char *alignment_name);
84  GB_ERROR init(GBDATA *gb_helix_nr, GBDATA *gb_helix, size_t size);
85  GB_ERROR initFromData(const char *helix_nr, const char *helix, size_t size);
86 
87  int check_pair(char left, char right, BI_PAIR_TYPE pair_type); // return 1 if bases form a pair
88 
89  size_t size() const { return Size; }
90  bool has_entries() const { return entries; }
91  const BI_helix_entry& entry(size_t pos) const {
92  bi_assert(pos<Size);
93  bi_assert(entries);
94  return entries[pos];
95  }
96 
97  size_t opposite_position(size_t pos) const {
98  const BI_helix_entry& Entry = entry(pos);
99  bi_assert(Entry.pair_type != HELIX_NONE); // not a pair -> no opposite position
100  return Entry.pair_pos;
101  }
102  BI_PAIR_TYPE pairtype(size_t pos) const { return pos<Size ? entry(pos).pair_type : HELIX_NONE; }
103  const char *helixNr(size_t pos) const { return pairtype(pos) == HELIX_NONE ? NULp : entry(pos).helix_nr; }
104  // Note: results of helixNr may be compared by == (instead of strcmp())
105 
106  long first_pair_position() const; // first pair position (or -1)
107  long next_pair_position(size_t pos) const; // next pair position behind 'pos' (or -1)
108 
109  long first_position(const char *helixNr) const; // returns -1 for non-existing helixNr's
110  long last_position(const char *helixNr) const; // returns -1 for non-existing helixNr's
111 };
112 
113 
114 
115 
116 
117 #endif
const char * GB_ERROR
Definition: arb_core.h:25
Definition: BI_helix.hxx:43
const BI_helix_entry & entry(size_t pos) const
Definition: BI_helix.hxx:91
BI_PAIR_TYPE
Definition: BI_helix.hxx:18
long pair_pos
Definition: BI_helix.hxx:44
long first_position(const char *helixNr) const
Definition: BI_helix.cxx:385
size_t opposite_position(size_t pos) const
Definition: BI_helix.hxx:97
static char * alignment_name
bool allocated
Definition: BI_helix.hxx:52
long last_position(const char *helixNr) const
Definition: BI_helix.cxx:393
char * char_bind[HELIX_MAX]
Definition: BI_helix.hxx:71
char * pairs[HELIX_MAX]
Definition: BI_helix.hxx:70
long first_pair_position() const
Definition: BI_helix.cxx:358
bool is_pairtype(char left, char right, BI_PAIR_TYPE pair_type)
Definition: BI_helix.cxx:321
static GB_ERROR get_error()
Definition: BI_helix.hxx:77
BI_helix()
Definition: BI_helix.cxx:78
long next_pair_position(size_t pos) const
Definition: BI_helix.cxx:362
size_t size() const
Definition: BI_helix.hxx:89
const char * helixNr(size_t pos) const
Definition: BI_helix.hxx:103
#define bi_assert(bed)
Definition: BI_helix.hxx:15
long next_pair_pos
Definition: BI_helix.hxx:48
~BI_helix()
Definition: BI_helix.cxx:82
bool has_entries() const
Definition: BI_helix.hxx:90
char * helix_nr
Definition: BI_helix.hxx:46
int check_pair(char left, char right, BI_PAIR_TYPE pair_type)
Definition: BI_helix.cxx:332
BI_PAIR_TYPE pairtype(size_t pos) const
Definition: BI_helix.hxx:102
GB_ERROR initFromData(const char *helix_nr, const char *helix, size_t size)
Definition: BI_helix.cxx:116
#define NULp
Definition: cxxforward.h:114
GBDATA * gb_main
Definition: adname.cxx:33
BI_PAIR_TYPE pair_type
Definition: BI_helix.hxx:45