A library for working with phylogenetic and population genetic data.
v0.32.0
genome_region_reader.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_FORMAT_GENOME_REGION_READER_H_
2 #define GENESIS_POPULATION_FORMAT_GENOME_REGION_READER_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2024 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 
39 
40 #include <cstdint>
41 #include <functional>
42 #include <string>
43 #include <utility>
44 #include <vector>
45 
46 namespace genesis {
47 namespace population {
48 
49 // =================================================================================================
50 // Genome Region Reader
51 // =================================================================================================
52 
70 {
71 public:
72 
73  // -------------------------------------------------------------------------
74  // Constructors and Rule of Five
75  // -------------------------------------------------------------------------
76 
77  GenomeRegionReader() = default;
78  ~GenomeRegionReader() = default;
79 
80  GenomeRegionReader( GenomeRegionReader const& ) = default;
82 
85 
86  // ---------------------------------------------------------------------
87  // Reading
88  // ---------------------------------------------------------------------
89 
97  std::shared_ptr< utils::BaseInputSource > source
98  ) const;
99 
111  std::shared_ptr< utils::BaseInputSource > source,
112  bool merge = false
113  ) const;
114 
121  std::shared_ptr< utils::BaseInputSource > source,
122  GenomeRegionList& target,
123  bool merge = false
124  ) const;
125 
126  // -------------------------------------------------------------------------
127  // Settings
128  // -------------------------------------------------------------------------
129 
130  bool zero_based() const
131  {
132  return zero_based_;
133  }
134 
136  {
137  zero_based_ = value;
138  return *this;
139  }
140 
141  bool end_exclusive() const
142  {
143  return end_exclusive_;
144  }
145 
147  {
148  end_exclusive_ = value;
149  return *this;
150  }
151 
152  // -------------------------------------------------------------------------
153  // Internal Helpers
154  // -------------------------------------------------------------------------
155 
156 private:
157 
162  void read_(
163  std::shared_ptr< utils::BaseInputSource > source,
164  std::function<void( GenomeRegion const& region )> callback
165  ) const;
166 
167  // -------------------------------------------------------------------------
168  // Member Variables
169  // -------------------------------------------------------------------------
170 
171  bool zero_based_ = false;
172  bool end_exclusive_ = false;
173 };
174 
175 } // namespace population
176 } // namespace genesis
177 
178 #endif // include guard
genesis::population::GenomeRegionReader::zero_based
GenomeRegionReader & zero_based(bool value)
Definition: genome_region_reader.hpp:135
genesis::population::merge
SampleCounts merge(SampleCounts const &p1, SampleCounts const &p2)
Merge the counts of two SampleCountss.
Definition: population/function/functions.cpp:400
genesis::population::GenomeLocusSet
List of positions/coordinates in a genome, for each chromosome.
Definition: genome_locus_set.hpp:75
genesis::population::GenomeRegionReader::read_as_genome_locus_set
GenomeLocusSet read_as_genome_locus_set(std::shared_ptr< utils::BaseInputSource > source) const
Read an input source, and return its content as a GenomeLocusSet.
Definition: genome_region_reader.cpp:50
genesis::population::GenomeRegionList
List of regions in a genome, for each chromosome.
Definition: genome_region_list.hpp:95
input_source.hpp
genome_region.hpp
input_stream.hpp
genesis::population::GenomeRegionReader::GenomeRegionReader
GenomeRegionReader()=default
genesis::population::GenomeRegionReader
Generic reader for inputs that contain a genomic region or locus per line, in different formats.
Definition: genome_region_reader.hpp:69
genesis::population::GenomeRegionReader::operator=
GenomeRegionReader & operator=(GenomeRegionReader const &)=default
genome_region_list.hpp
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
genome_locus_set.hpp
genesis::population::GenomeRegionReader::zero_based
bool zero_based() const
Definition: genome_region_reader.hpp:130
genesis::population::GenomeRegionReader::end_exclusive
bool end_exclusive() const
Definition: genome_region_reader.hpp:141
genesis::population::GenomeRegionReader::~GenomeRegionReader
~GenomeRegionReader()=default
genesis::population::GenomeRegion
A region (between two positions) on a chromosome.
Definition: genome_region.hpp:70
genesis::population::GenomeRegionReader::read_as_genome_region_list
GenomeRegionList read_as_genome_region_list(std::shared_ptr< utils::BaseInputSource > source, bool merge=false) const
Read an input source, and return its content as a GenomeRegionList.
Definition: genome_region_reader.cpp:60
genesis::population::GenomeRegionReader::end_exclusive
GenomeRegionReader & end_exclusive(bool value)
Definition: genome_region_reader.hpp:146