multovl  1.3
Multiple overlaps of genomic regions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
region.hh
Go to the documentation of this file.
1 /* <LICENSE>
2 License for the MULTOVL multiple genomic overlap tools
3 
4 Copyright (c) 2007-2012, Dr Andras Aszodi,
5 Campus Science Support Facilities GmbH (CSF),
6 Dr-Bohr-Gasse 3, A-1030 Vienna, Austria, Europe.
7 All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are
11 met:
12 
13  * Redistributions of source code must retain the above copyright notice,
14  this list of conditions and the following disclaimer.
15  * Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18  * Neither the name of the Campus Science Support Facilities GmbH
19  nor the names of its contributors may be used to endorse
20  or promote products derived from this software without specific prior
21  written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
24 AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 </LICENSE> */
35 #ifndef MULTOVL_REGION_HEADER
36 #define MULTOVL_REGION_HEADER
37 
38 // == HEADER region.hh ==
39 
46 // -- Standard headers --
47 
48 #include <string>
49 #include <iostream>
50 
51 // -- Boost headers --
52 
53 #include "boost/operators.hpp"
54 #include "boost/serialization/access.hpp"
55 #include "boost/serialization/string.hpp"
56 #include "boost/serialization/version.hpp"
57 #include "boost/serialization/split_member.hpp"
58 
59 namespace multovl {
60 
65 class Region:
66  boost::less_than_comparable< Region,
67  boost::equality_comparable<Region> >
68 {
69  public:
70 
72  Region():
73  _first(0), _last(0), _length(0),
74  _strand(0), _name("")
75  {}
76 
89  Region(unsigned int f, unsigned int l,
90  char s, const std::string& nm);
91 
93  virtual ~Region() {}
94 
95  // -- Setters --
96 
99  void set_coords(unsigned int f, unsigned int l);
100 
102  void strand(char s);
103 
106  std::string name(const std::string& nm);
107 
108  // -- Getters --
109 
111  const unsigned int& first() const { return _first; }
112 
114  const unsigned int& last() const { return _last; }
115 
117  const unsigned int& length() const { return _length; }
118 
120  bool is_empty() const { return (_length == 0); }
121 
123  const char& strand() const { return _strand; }
124 
126  const std::string& name() const { return _name; }
127 
130  bool equal_pos(const Region& rhs) const
131  {
132  return (this->first() == rhs.first() && this->last() == rhs.last());
133  }
134 
137  bool operator==(const Region& rhs) const
138  {
139  return (
140  equal_pos(rhs) &&
141  this->strand() == rhs.strand() &&
142  this->name() == rhs.name()
143  );
144  }
145 
148  bool operator<(const Region& rhs) const;
149 
150  private:
151 
152  // data
153  unsigned int _first, _last, _length;
154  char _strand;
155  std::string _name;
156 
157  // "split" serialization
158  friend class boost::serialization::access;
159  template <class Archive>
160  void save(Archive& ar, const unsigned int version) const
161  {
162  ar << _first << _last
163  << _strand << _name;
164  }
165 
166  template <class Archive>
167  void load(Archive& ar, const unsigned int version)
168  {
169  unsigned int first, last;
170  ar >> first >> last;
171  this->set_coords(first, last); // sets _length, too
172  ar >> _strand;
173  ar >> _name;
174  }
175  BOOST_SERIALIZATION_SPLIT_MEMBER()
176 }; // class Region
177 
178 } // namespace multovl
179 
180 #endif // MULTOVL_REGION_HEADER
const unsigned int & first() const
Returns the first coordinate.
Definition: region.hh:111
bool operator<(const Region &rhs) const
bool is_empty() const
Zero-length regions are considered empty.
Definition: region.hh:120
Region()
Inits to empty (makes sense when using as input buffer)
Definition: region.hh:72
Instances of the Region class represent regions on a sequence. They have first and last coordinates...
Definition: region.hh:65
bool operator==(const Region &rhs) const
Definition: region.hh:137
const std::string & name() const
Returns the name of the region.
Definition: region.hh:126
const char & strand() const
Returns the strand information.
Definition: region.hh:123
void set_coords(unsigned int f, unsigned int l)
bool equal_pos(const Region &rhs) const
Definition: region.hh:130
virtual ~Region()
empty virtual dtor
Definition: region.hh:93
std::string name(const std::string &nm)
const unsigned int & last() const
Returns the last coordinate.
Definition: region.hh:114
const unsigned int & length() const
Returns the length.
Definition: region.hh:117
void strand(char s)
Sets the strand.