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  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];
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 ? NULp : 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
Definition: BI_helix.hxx:43
const BI_helix_entry & entry(size_t pos) const
Definition: BI_helix.hxx:90
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:373
size_t opposite_position(size_t pos) const
Definition: BI_helix.hxx:96
static char * alignment_name
bool allocated
Definition: BI_helix.hxx:52
long last_position(const char *helixNr) const
Definition: BI_helix.cxx:381
char * char_bind[HELIX_MAX]
Definition: BI_helix.hxx:68
char * pairs[HELIX_MAX]
Definition: BI_helix.hxx:67
long first_pair_position() const
Definition: BI_helix.cxx:346
bool is_pairtype(char left, char right, BI_PAIR_TYPE pair_type)
Definition: BI_helix.cxx:309
BI_helix()
Definition: BI_helix.cxx:78
long next_pair_position(size_t pos) const
Definition: BI_helix.cxx:350
size_t size() const
Definition: BI_helix.hxx:88
const char * helixNr(size_t pos) const
Definition: BI_helix.hxx:102
#define bi_assert(bed)
Definition: BI_helix.hxx:15
long next_pair_pos
Definition: BI_helix.hxx:48
static void set_error(const char *err)
Definition: BI_helix.hxx:76
~BI_helix()
Definition: BI_helix.cxx:82
bool has_entries() const
Definition: BI_helix.hxx:89
char * helix_nr
Definition: BI_helix.hxx:46
int check_pair(char left, char right, BI_PAIR_TYPE pair_type)
Definition: BI_helix.cxx:320
BI_PAIR_TYPE pairtype(size_t pos) const
Definition: BI_helix.hxx:101
static char * get_error()
Definition: BI_helix.hxx:74
#define NULp
Definition: cxxforward.h:97
static void clear_error()
Definition: BI_helix.hxx:75
const char * initFromData(const char *helix_nr, const char *helix, size_t size)
Definition: BI_helix.cxx:115
GBDATA * gb_main
Definition: adname.cxx:33
BI_PAIR_TYPE pair_type
Definition: BI_helix.hxx:45