multovl  1.3
Multiple overlaps of genomic regions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
reglimit.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_REGLIMIT_HEADER
36 #define MULTOVL_REGLIMIT_HEADER
37 
38 // == Header reglimit.hh ==
39 
45 
46 // -- System headers --
47 
48 // -- Boost headers --
49 
50 #include "boost/serialization/shared_ptr.hpp"
51 
52 // -- Own headers --
53 
54 #include "ancregion.hh" // pulls in region.hh as well
55 
56 // == Classes ==
57 
58 namespace multovl {
59 
64 class RegLimit
65 {
66 public:
67 
69  RegLimit(): _regp(), _isfirst(false) {}
70 
74  explicit RegLimit(const boost::shared_ptr<AncestorRegion>& regp,
75  bool isfirst=true)
76  : _regp(regp), _isfirst(isfirst) {}
77 
78  // -- Accessors --
79 
81  const AncestorRegion& region() const
82  {
83  return *_regp;
84  }
85 
87  bool is_first() const
88  {
89  return _isfirst;
90  }
91 
93  void first(bool isfirst)
94  {
95  _isfirst = isfirst;
96  }
97 
98  unsigned int track_id() const
99  {
100  return _regp->track_id(); // convenience function
101  }
102 
105  unsigned int this_pos() const
106  {
107  return (is_first()? _regp->first(): _regp->last());
108  }
109 
112  unsigned int other_pos() const
113  {
114  return (is_first()? _regp->last(): _regp->first());
115  }
116 
118  bool operator<(const RegLimit& other) const;
119 
127  {
128  boost::shared_ptr<AncestorRegion> ancp(new AncestorRegion(this->region()));
129  return RegLimit(ancp, this->is_first());
130  }
131 
132 # if !defined(NDEBUG) || (defined(_MSC_VER) && defined(_DEBUG))
133 #define REGLIMIT_RAWPTR
134 #endif
135 
136  #ifdef REGLIMIT_RAWPTR
137  // these are used by the unit tests only
138  const AncestorRegion* const_raw_region_ptr() const { return _regp.get(); }
139  AncestorRegion* raw_region_ptr() { return _regp.get(); }
140  #endif
141 
142 private:
143 
144  // data
145  boost::shared_ptr<AncestorRegion> _regp;
146  bool _isfirst;
147 
148  // serialization
149  friend class boost::serialization::access;
150  template <class Archive>
151  void serialize(Archive& ar, const unsigned int version)
152  {
153  ar & _regp;
154  ar & _isfirst;
155  }
156 
157 }; // class RegLimit
158 
159 } // namespace multovl
160 
161 #endif // MULTOVL_REGLIMIT_HEADER
unsigned int other_pos() const
Definition: reglimit.hh:112
void first(bool isfirst)
Sets the first attribute of the calling object.
Definition: reglimit.hh:93
RegLimit(const boost::shared_ptr< AncestorRegion > &regp, bool isfirst=true)
Definition: reglimit.hh:74
Ancestor regions representing the regions giving rise to overlaps.
bool is_first() const
Definition: reglimit.hh:87
AncestorRegion objects represent the regions that give rise to overlaps. They are essentially Region-...
Definition: ancregion.hh:68
Definition: reglimit.hh:64
RegLimit()
Init to empty.
Definition: reglimit.hh:69
bool operator<(const RegLimit &other) const
Ordering according to position, or first before last if the same position.
unsigned int this_pos() const
Definition: reglimit.hh:105
const AncestorRegion & region() const
Definition: reglimit.hh:81
RegLimit deep_copy() const
Definition: reglimit.hh:126