A library for working with phylogenetic and population genetic data.
v0.27.0
sync_reader.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_FORMATS_SYNC_READER_H_
2 #define GENESIS_POPULATION_FORMATS_SYNC_READER_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 
37 
38 #include <string>
39 #include <vector>
40 
41 namespace genesis {
42 namespace population {
43 
44 // =================================================================================================
45 // PoPoolation2 Synchronized File Reader
46 // =================================================================================================
47 
63 {
64 public:
65 
66  // -------------------------------------------------------------------------
67  // Constructors and Rule of Five
68  // -------------------------------------------------------------------------
69 
70  SyncReader() = default;
71  ~SyncReader() = default;
72 
73  SyncReader( SyncReader const& ) = default;
74  SyncReader( SyncReader&& ) = default;
75 
76  SyncReader& operator= ( SyncReader const& ) = default;
77  SyncReader& operator= ( SyncReader&& ) = default;
78 
79  // ---------------------------------------------------------------------
80  // Reading
81  // ---------------------------------------------------------------------
82 
83  std::vector<Variant> read(
84  std::shared_ptr< utils::BaseInputSource > source
85  ) const;
86 
87  std::vector<Variant> read(
88  std::shared_ptr< utils::BaseInputSource > source,
89  std::vector<bool> const& sample_filter
90  ) const;
91 
92  // -------------------------------------------------------------------------
93  // Parsing
94  // -------------------------------------------------------------------------
95 
96  bool parse_line(
97  utils::InputStream& input_stream,
98  Variant& sample_set
99  ) const;
100 
101  bool parse_line(
102  utils::InputStream& input_stream,
103  Variant& sample_set,
104  std::vector<bool> const& sample_filter
105  ) const;
106 
107  // -------------------------------------------------------------------------
108  // Internal Members
109  // -------------------------------------------------------------------------
110 
111 private:
112 
113  bool parse_line_(
114  utils::InputStream& input_stream,
115  Variant& sample_set,
116  std::vector<bool> const& sample_filter,
117  bool use_sample_filter
118  ) const;
119 
120  // Only use intrinsics version for the compilers that support them!
121  #if defined(__GNUC__) || defined(__GNUG__) || defined(__clang__)
122 
123  void parse_sample_gcc_intrinsic_(
124  utils::InputStream& input_stream,
125  BaseCounts& sample
126  ) const;
127 
128  #endif
129 
130  void parse_sample_simple_(
131  utils::InputStream& input_stream,
132  BaseCounts& sample
133  ) const;
134 
135  void parse_sample_(
136  utils::InputStream& input_stream,
137  BaseCounts& sample
138  ) const;
139 
140  void skip_sample_(
141  utils::InputStream& input_stream
142  ) const;
143 
144 };
145 
146 } // namespace population
147 } // namespace genesis
148 
149 #endif // include guard
genesis::utils::InputStream
Stream interface for reading data from an InputSource, that keeps track of line and column counters.
Definition: input_stream.hpp:81
genesis::population::SyncReader::parse_line
bool parse_line(utils::InputStream &input_stream, Variant &sample_set) const
Definition: sync_reader.cpp:106
genesis::population::SyncReader::SyncReader
SyncReader()=default
input_source.hpp
genesis::population::SyncReader::read
std::vector< Variant > read(std::shared_ptr< utils::BaseInputSource > source) const
Definition: sync_reader.cpp:69
input_stream.hpp
genesis::population::SyncReader::operator=
SyncReader & operator=(SyncReader const &)=default
genesis::population::Variant
A single variant at a position in a chromosome, along with BaseCounts for a set of samples.
Definition: variant.hpp:62
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::BaseCounts
One set of nucleotide base counts, for example for a given sample that represents a pool of sequenced...
Definition: base_counts.hpp:54
variant.hpp
genesis::population::SyncReader
Reader for PoPoolation2's "synchronized" files.
Definition: sync_reader.hpp:62
genesis::population::SyncReader::~SyncReader
~SyncReader()=default