IntaRNA 3.4.1
RNA-RNA interaction prediction | C++ API
Loading...
Searching...
No Matches
IndexRangeList.h
Go to the documentation of this file.
1
2#ifndef INTARNA_INDEXRANGELIST_H_
3#define INTARNA_INDEXRANGELIST_H_
4
6
7#include <list>
8
9#include <boost/regex.hpp>
10
11namespace IntaRNA {
12
20{
21protected:
22
24 typedef std::list< IndexRange > List;
25
26public:
27
29 static const std::string regexString;
30
32 static const boost::regex regex;
33
34public:
35
36 typedef List::iterator iterator;
37 typedef List::const_iterator const_iterator;
38 typedef List::reverse_iterator reverse_iterator;
39 typedef List::const_reverse_iterator const_reverse_iterator;
40
41public:
42
47 IndexRangeList( const bool allowOverlap = false );
48
60 IndexRangeList( const std::string & stringEncoding
61 , const bool allowOverlap = false
62 , const RnaSequence * seq = NULL
63 , const bool isComplete = false );
64
69 IndexRangeList( const IndexRangeList & toCopy );
70
71
75 virtual ~IndexRangeList();
76
77
85 bool covers( const size_t index ) const;
86
95 bool covers( const size_t from, const size_t to ) const;
96
104 bool covers( const IndexRange & range ) const;
105
113 bool overlaps( const IndexRange& range ) const;
114
120 void push_back( const IndexRange& range );
121
128 iterator insert( const IndexRange& range );
129
136 IndexRange & get( const size_t idx );
137
144 const IndexRange & get( const size_t idx ) const;
145
151
156 iterator begin();
157
162 iterator end();
163
168 const_iterator begin() const;
169
174 const_iterator end() const;
175
181
187
193
199
204 bool empty() const;
205
210 size_t size() const;
211
215 void clear();
216
221 bool isAllowingOverlap() const;
222
230 void
231 fromString( const std::string & stringEncoding, const RnaSequence * seq = NULL );
232
244 shift( const int indexShift, const size_t indexMax ) const;
245
251 reverseInplace( const size_t seqLength );
252
258 reverse( const size_t seqLength ) const;
259
265 const bool operator == ( const IndexRangeList &r ) const {
266 return this->list == r.list;
267 }
268
274 const bool operator != ( const IndexRangeList &r ) const {
275 return this->list != r.list;
276 }
277
278
285 friend std::ostream& operator<<(std::ostream& out, const IndexRangeList& l);
286
291 void
292 setComplete( const bool isComplete );
293
298 bool
299 isComplete() const;
300
301protected:
302
305
308
311
312};
313
314
315
319
320inline
321IndexRangeList::IndexRangeList( const bool allowOverlap_ )
322: allowOverlap(allowOverlap_)
323, list()
324, listIsComplete(false)
325{
326}
327
329
330inline
331IndexRangeList::IndexRangeList( const std::string & stringEncoding
332 , const bool allowOverlap_
333 , const RnaSequence * seq
334 , const bool isComplete )
335: allowOverlap(allowOverlap_)
336, list()
337, listIsComplete(isComplete)
338{
339 fromString(stringEncoding, seq);
340}
341
343
344inline
346: allowOverlap(toCopy.allowOverlap)
347, list(toCopy.list)
348, listIsComplete(toCopy.listIsComplete)
349{
350}
351
353
354inline
358
360
361inline
362void
363IndexRangeList::setComplete( const bool isComplete )
364{
366}
367
369
370inline
371bool
373{
374 return listIsComplete;
375}
376
378
379inline
380bool
382covers( const size_t from, const size_t to ) const
383{
384 return covers( IndexRange(from, to) );
385}
386
388
389inline
392reverse( const size_t seqLength ) const
393{
394 // create copy
395 IndexRangeList tmp(*this);
396 // reverse and return copy
397 return tmp.reverseInplace( seqLength );
398}
399
401
402inline
404 if (listIsComplete) {
405 throw std::runtime_error("IndexRangeList::erase() : cannot erase from complete list");
406 }
407 return list.erase( i );
408}
409
411
412inline
414
416
417inline
419
421
422inline
424
426
427inline
429
431
432inline
434
436
437inline
439
441
442inline
444
446
447inline
449
451
452inline
453bool IndexRangeList::empty() const { return list.empty(); }
454
456
457inline
459
461
462inline
463size_t IndexRangeList::size() const { return list.size(); }
464
466
467inline
469 listIsComplete = false;
470 return list.clear();
471}
472
474
475inline
476std::ostream& operator<<(std::ostream& out, const IndexRangeList& l)
477{
478 // output according to regex
479 for (IndexRangeList::const_iterator i=l.begin(); i!=l.end(); i++)
480 out <<(i==l.begin()?"":",") <<*i;
481 return out;
482}
483
485
486
487} // namespace
488
489#endif /* INDEXRANGELIST_H_ */
Definition IndexRangeList.h:20
iterator begin()
Definition IndexRangeList.h:413
void setComplete(const bool isComplete)
Definition IndexRangeList.h:363
bool listIsComplete
whether or not the list is complete, i.e. cannot be extended
Definition IndexRangeList.h:310
iterator insert(const IndexRange &range)
List list
the list of indices
Definition IndexRangeList.h:307
void fromString(const std::string &stringEncoding, const RnaSequence *seq=NULL)
iterator end()
Definition IndexRangeList.h:418
IndexRangeList(const bool allowOverlap=false)
Definition IndexRangeList.h:321
const IndexRange & get(const size_t idx) const
List::const_iterator const_iterator
Definition IndexRangeList.h:37
List::const_reverse_iterator const_reverse_iterator
Definition IndexRangeList.h:39
IndexRangeList & reverseInplace(const size_t seqLength)
bool covers(const size_t index) const
IndexRange & get(const size_t idx)
static const std::string regexString
regular expression string (without start/end matching)
Definition IndexRangeList.h:29
reverse_iterator rbegin()
Definition IndexRangeList.h:433
IndexRangeList reverse(const size_t seqLength) const
Definition IndexRangeList.h:392
iterator erase(iterator i)
Definition IndexRangeList.h:403
IndexRangeList shift(const int indexShift, const size_t indexMax) const
bool allowOverlap
whether or not overlapping ranges are allowed
Definition IndexRangeList.h:304
List::iterator iterator
Definition IndexRangeList.h:36
void push_back(const IndexRange &range)
void clear()
Definition IndexRangeList.h:468
List::reverse_iterator reverse_iterator
Definition IndexRangeList.h:38
virtual ~IndexRangeList()
Definition IndexRangeList.h:355
bool overlaps(const IndexRange &range) const
bool empty() const
Definition IndexRangeList.h:453
bool isComplete() const
Definition IndexRangeList.h:372
bool isAllowingOverlap() const
Definition IndexRangeList.h:458
bool covers(const IndexRange &range) const
reverse_iterator rend()
Definition IndexRangeList.h:438
const bool operator==(const IndexRangeList &r) const
Definition IndexRangeList.h:265
size_t size() const
Definition IndexRangeList.h:463
std::list< IndexRange > List
List of ranges.
Definition IndexRangeList.h:24
friend std::ostream & operator<<(std::ostream &out, const IndexRangeList &l)
Definition IndexRangeList.h:476
const bool operator!=(const IndexRangeList &r) const
Definition IndexRangeList.h:274
static const boost::regex regex
regular expression that matches valid IndexRangeList string encodings
Definition IndexRangeList.h:32
Definition IndexRange.h:20
Definition RnaSequence.h:29
Definition Accessibility.h:13
std::ostream & operator<<(std::ostream &out, const AccessibilityConstraint &c)
Definition AccessibilityConstraint.h:481