ARB
SEC_abspos.hxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : sec_abspos.hxx //
4 // Purpose : Encapsulates helix position access //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in July 2007 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // =============================================================== //
11 
12 #ifndef SEC_ABSPOS_HXX
13 #define SEC_ABSPOS_HXX
14 
15 #ifndef _GLIBCXX_CSTDIO
16 #include <cstdio>
17 #endif
18 #ifndef ARBTOOLS_H
19 #include <arbtools.h>
20 #endif
21 
22 #ifndef SEC_DEFS_HXX
23 #include "SEC_defs.hxx"
24 #endif
25 
26 
27 class XString : virtual Noncopyable {
28  char *x_string;
29  size_t x_string_len;
30 
31  int x_count; // number of 'x's found in x_string
32 
33  size_t *abspos; // contains absolute positions for all 'x's in 'x_string'
34  int *number_found; // for each absolute position P, contains number of 'x's from start of sequence till P-1
35 
36  bool initialized; // true if initialize called
37 
38  void set_length(size_t len); // dealloc internal array if length grows
39 
40  void addX(size_t abs_pos) { // add an X at pos
41  initialized = false;
42  sec_assert(abs_pos<x_string_len);
43  x_string[abs_pos] = 'x';
44  }
45 
46 public:
47  XString(size_t ali_length);
48  XString(const char *saved_x_string, size_t saved_len, size_t ali_length);
49  ~XString();
50 
51  void initialize(); // builds all internal data from x_string
52 
53  int getXcount() const {
54  sec_assert(initialized);
55  return x_count;
56  }
57  size_t getLength() const { return x_string_len; }
58 
59  size_t getAbsPos(int x) const; // gets absolute position of a 'x'
60  int getXleftOf(size_t abspos) const; // gets the number of 'x's left of sequence pos
61 
62  void addXpair(size_t start, size_t end) {
63 #if defined(DEBUG) && 0
64  printf("addXpair(%u, %u)\n", start, end);
65 #endif // DEBUG
66  addX(start);
67  addX(end);
68  }
69 
70  const char *get_x_string() const; // version saved to DB
71  bool alignment_too_short() const { return x_string[x_string_len-1] == 'x'; }
72  size_t get_x_string_length() const { return getLength() - (alignment_too_short() ? 0 : 1); } // version saved to DB
73 };
74 
75 #else
76 #error sec_abspos.hxx included twice
77 #endif // SEC_ABSPOS_HXX
int getXleftOf(size_t abspos) const
Definition: SEC_abspos.cxx:114
int getXcount() const
Definition: SEC_abspos.hxx:53
size_t get_x_string_length() const
Definition: SEC_abspos.hxx:72
static HelixNrInfo * start
const char * get_x_string() const
Definition: SEC_abspos.cxx:122
size_t getAbsPos(int x) const
Definition: SEC_abspos.cxx:106
void initialize()
Definition: SEC_abspos.cxx:60
size_t getLength() const
Definition: SEC_abspos.hxx:57
bool alignment_too_short() const
Definition: SEC_abspos.hxx:71
XString(size_t ali_length)
Definition: SEC_abspos.cxx:27
#define sec_assert(cond)
Definition: SEC_defs.hxx:19
void addXpair(size_t start, size_t end)
Definition: SEC_abspos.hxx:62