A library for working with phylogenetic data.
v0.25.0
genome_region.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_GENOME_REGION_H_
2 #define GENESIS_POPULATION_GENOME_REGION_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2021 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lczech@carnegiescience.edu>
23  Department of Plant Biology, Carnegie Institution For Science
24  260 Panama Street, Stanford, CA 94305, USA
25 */
26 
34 #include <iosfwd>
35 #include <string>
36 #include <vector>
37 
38 namespace genesis {
39 namespace population {
40 
41 // =================================================================================================
42 // Genome Region
43 // =================================================================================================
44 
52 {
53 
54 public:
55 
56  std::string chromosome;
57  size_t start = 0;
58  size_t end = 0;
59 
60  GenomeRegion( std::string const& chr = "", size_t s = 0, size_t e = 0 )
61  : chromosome( chr )
62  , start(s)
63  , end(e)
64  {}
65 };
66 
67 // =================================================================================================
68 // Genome Region List
69 // =================================================================================================
70 
80 {
81 public:
82 
83  // -------------------------------------------------------------------------
84  // Typedefs and Enums
85  // -------------------------------------------------------------------------
86 
88  using container = std::vector<GenomeRegion>;
89 
92  using const_reference = value_type const&;
93 
94  using iterator = typename container::iterator;
95  using const_iterator = typename container::const_iterator;
96  using reverse_iterator = typename container::reverse_iterator;
97  using const_reverse_iterator = typename container::const_reverse_iterator;
98 
99  using difference_type = typename container::difference_type;
100  using size_type = typename container::size_type;
101 
102  // -------------------------------------------------------------------------
103  // Constructors and Rule of Five
104  // -------------------------------------------------------------------------
105 
107  : find_cache_( regions_.end() )
108  {}
109 
110  ~GenomeRegionList() = default;
111 
112  GenomeRegionList( GenomeRegionList const& ) = default;
113  GenomeRegionList( GenomeRegionList&& ) = default;
114 
115  GenomeRegionList& operator= ( GenomeRegionList const& ) = default;
117 
118  // -------------------------------------------------------------------------
119  // Modifiers
120  // -------------------------------------------------------------------------
121 
127  void add( GenomeRegion const& region );
128 
132  void add( std::string const& chromosome, size_t start = 0, size_t end = 0 );
133 
134  // -------------------------------------------------------------------------
135  // Queries
136  // -------------------------------------------------------------------------
137 
141  bool is_covered( std::string const& chromosome, size_t position ) const;
142 
147  const_iterator find( std::string const& chromosome, size_t position ) const;
148 
149  // -------------------------------------------------------------------------
150  // Accessors
151  // -------------------------------------------------------------------------
152 
153  size_t size() const
154  {
155  return regions_.size();
156  }
157 
158  bool empty() const
159  {
160  return regions_.empty();
161  }
162 
163  const_reference operator[]( size_t i ) const
164  {
165  return regions_[i];
166  }
167 
168  const_reference at( size_t i ) const
169  {
170  return regions_.at(i);
171  }
172 
173  // -------------------------------------------------------------------------
174  // Iterators
175  // -------------------------------------------------------------------------
176 
177  // iterator begin()
178  // {
179  // return regions_.begin();
180  // }
181 
183  {
184  return regions_.begin();
185  }
186 
187  // iterator end()
188  // {
189  // return regions_.end();
190  // }
191 
193  {
194  return regions_.end();
195  }
196 
197 
198  // -------------------------------------------------------------------------
199  // Data Members
200  // -------------------------------------------------------------------------
201 
202 private:
203 
204  container regions_;
205  mutable const_iterator find_cache_;
206 
207 };
208 
209 } // namespace population
210 } // namespace genesis
211 
212 #endif // include guard
genesis::population::GenomeRegionList::reverse_iterator
typename container::reverse_iterator reverse_iterator
Definition: genome_region.hpp:96
genesis::population::GenomeRegionList::const_reference
value_type const & const_reference
Definition: genome_region.hpp:92
genesis::population::GenomeRegionList::empty
bool empty() const
Definition: genome_region.hpp:158
genesis::population::GenomeRegionList::difference_type
typename container::difference_type difference_type
Definition: genome_region.hpp:99
genesis::population::GenomeRegionList::iterator
typename container::iterator iterator
Definition: genome_region.hpp:94
genesis::population::GenomeRegionList::size_type
typename container::size_type size_type
Definition: genome_region.hpp:100
genesis::population::GenomeRegionList::end
const_iterator end() const
Definition: genome_region.hpp:192
genesis::population::GenomeRegionList
A sorted list of genome regions.
Definition: genome_region.hpp:79
genesis::population::GenomeRegionList::operator[]
const_reference operator[](size_t i) const
Definition: genome_region.hpp:163
genesis::population::GenomeRegion::start
size_t start
Definition: genome_region.hpp:57
genesis::population::GenomeRegionList::is_covered
bool is_covered(std::string const &chromosome, size_t position) const
Return whether a given position on a chromosome is part of any of the regions stored.
Definition: genome_region.cpp:120
genesis::population::GenomeRegion::chromosome
std::string chromosome
Definition: genome_region.hpp:56
genesis::population::GenomeRegionList::const_iterator
typename container::const_iterator const_iterator
Definition: genome_region.hpp:95
genesis::population::GenomeRegionList::find
const_iterator find(std::string const &chromosome, size_t position) const
Return an iterator to the GenomeRegion that covers the given position on the chromosome,...
Definition: genome_region.cpp:125
genesis::population::GenomeRegionList::container
std::vector< GenomeRegion > container
Definition: genome_region.hpp:88
genesis::population::GenomeRegion::GenomeRegion
GenomeRegion(std::string const &chr="", size_t s=0, size_t e=0)
Definition: genome_region.hpp:60
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::population::GenomeRegionList::operator=
GenomeRegionList & operator=(GenomeRegionList const &)=default
genesis::population::GenomeRegionList::at
const_reference at(size_t i) const
Definition: genome_region.hpp:168
genesis::population::GenomeRegionList::const_reverse_iterator
typename container::const_reverse_iterator const_reverse_iterator
Definition: genome_region.hpp:97
genesis::population::GenomeRegionList::size
size_t size() const
Definition: genome_region.hpp:153
genesis::population::GenomeRegion
A region (between two positions) on a chromosome.
Definition: genome_region.hpp:51
genesis::population::GenomeRegionList::begin
const_iterator begin() const
Definition: genome_region.hpp:182
genesis::population::GenomeRegionList::GenomeRegionList
GenomeRegionList()
Definition: genome_region.hpp:106
genesis::population::GenomeRegionList::~GenomeRegionList
~GenomeRegionList()=default
genesis::population::GenomeRegionList::add
void add(GenomeRegion const &region)
Add a GenomeRegion to the list.
Definition: genome_region.cpp:45
genesis::population::GenomeRegion::end
size_t end
Definition: genome_region.hpp:58