LocARNA-1.8.11
rna_structure.hh
1 #ifndef LOCARNA_RNA_STRUCTURE_HH
2 #define LOCARNA_RNA_STRUCTURE_HH
3 
4 #ifdef HAVE_CONFIG_H
5 # include <config.h>
6 #endif
7 
8 #include <assert.h>
9 #include <set>
10 #include <string>
11 
12 namespace LocARNA {
26  class RnaStructure {
27  public:
29  typedef std::pair<size_t,size_t> bp_t;
30 
32  typedef std::set<bp_t,std::less<bp_t> > bps_t;
33 
34  private:
35  size_t length_;
36  bps_t bps_;
37 
38  static const char unpaired_symbol_='.';
39  static const std::string open_symbols_;
40  static const std::string close_symbols_;
41 
42  bool
43  parse(const std::string &s,
44  bps_t &bps,
45  char op,
46  char cl);
47 
48  bool
49  parse(const std::string &s,
50  bps_t &bps,
51  const std::string &op_syms,
52  const std::string &cl_syms);
53 
54  void
55  assert_valid_bp(const bp_t &bp) {
56  assert(1 <= bp.first);
57  assert(bp.first<bp.second);
58  assert(bp.second<=length_);
59  }
60 
61  public:
65  RnaStructure(): length_(0), bps_() {}
66 
85  explicit
86  RnaStructure(const std::string &structure);
87 
88 
95  bool
96  operator ==(const RnaStructure &s) const {
97  return
98  this->length_ == s.length_
99  &&
100  this->bps_ == s.bps_;
101  }
102 
110  bool
111  contains(const bp_t &x) const {
112  return bps_.find(x) != bps_.end();
113  }
114 
117  size_t
118  length() const {return length_;}
119 
122  size_t
123  size() const {return bps_.size();}
124 
128  void
129  insert(const bp_t &bp) {
130  assert_valid_bp(bp);
131  bps_.insert(bp);
132  }
133 
137  void
138  remove(const bp_t &bp) {
139  assert_valid_bp(bp);
140  bps_.erase(bp);
141  }
142 
146  void
147  clear() {bps_.clear();}
148 
149 
150  // This is not well supported by the current structure
151  // represenation. Therefore, we don't offer such functionality.
152  // /**
153  // * @brief Check whether a loop contains a position
154  // *
155  // * @param k position
156  // * @param x loop; (0,length+1) means external loop
157  // *
158  // * @return whether the loop enclosed by x contains k
159  // *
160  // * Definition: the loop enclosed by (i,j) contains k iff i<k<j
161  // * and there is no base pair (i',j') in the structure, where
162  // * i<i'<k<j'<j. Note that we don't require (i,j) to be element
163  // * of the structure.
164  // *
165  // * k can be member of more than one loop unless nested().
166  // */
167  // bp_t
168  // in_loop_of(size_t k, bp_t x) const;
169 
170 
171  //support contant iteration over base pair set
172 
174  typedef bps_t::const_iterator const_iterator;
175 
181  const_iterator begin() const {return bps_.begin();}
182 
188  const_iterator end() const {return bps_.end();}
189 
204  std::string
205  to_string() const;
206 
207  private:
208  std::string
209  to_string( const bps_t &bps ) const;
210 
211  public:
212 
220  static
221  bool
222  empty(const bps_t &bps);
223 
229  bool
230  empty() const {return empty(bps_);}
231 
245  static
246  bool
247  nested(const bps_t &bps);
248 
254  bool
255  nested() const {return nested(bps_);}
256 
271  static
272  bool
273  crossing(const bps_t &bps);
274 
280  bool
281  crossing() const {return crossing(bps_);}
282 
283  }; // end class RnaStructure
284 
285 
286 } // end namespace LocARNA
287 
288 #endif
289 
const_iterator begin() const
begin of base pair set
Definition: rna_structure.hh:181
size_t length() const
sequence length
Definition: rna_structure.hh:118
bool empty() const
Check for empty structure / class PLAIN.
Definition: rna_structure.hh:230
void insert(const bp_t &bp)
insert base pair
Definition: rna_structure.hh:129
std::string to_string() const
convert to dot-bracket string
Definition: rna_structure.cc:66
std::set< bp_t, std::less< bp_t > > bps_t
base pair set type
Definition: rna_structure.hh:32
bool contains(const bp_t &x) const
Base pair for membership test.
Definition: rna_structure.hh:111
void clear()
clear structure set structure to empty
Definition: rna_structure.hh:147
Definition: aligner.cc:17
std::pair< size_t, size_t > bp_t
base pair type
Definition: rna_structure.hh:29
RnaStructure()
construct empty
Definition: rna_structure.hh:65
bool nested() const
Check for nested structure / class NESTED.
Definition: rna_structure.hh:255
const_iterator end() const
end of base pair set
Definition: rna_structure.hh:188
size_t size() const
number of base pairs
Definition: rna_structure.hh:123
An RNA secondary structure.
Definition: rna_structure.hh:26
bool crossing() const
Check for crossing structure / class CROSSING.
Definition: rna_structure.hh:281
bps_t::const_iterator const_iterator
Check whether a loop contains a position.
Definition: rna_structure.hh:174
bool operator==(const RnaStructure &s) const
Equality operator.
Definition: rna_structure.hh:96