A library for working with phylogenetic data.
v0.25.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 
55 {
56 public:
57 
58  // -------------------------------------------------------------------------
59  // Constructors and Rule of Five
60  // -------------------------------------------------------------------------
61 
62  SyncReader() = default;
63  ~SyncReader() = default;
64 
65  SyncReader( SyncReader const& ) = default;
66  SyncReader( SyncReader&& ) = default;
67 
68  SyncReader& operator= ( SyncReader const& ) = default;
69  SyncReader& operator= ( SyncReader&& ) = default;
70 
71  // ---------------------------------------------------------------------
72  // Reading
73  // ---------------------------------------------------------------------
74 
75  std::vector<Variant> read(
76  std::shared_ptr< utils::BaseInputSource > source
77  ) const;
78 
79  std::vector<Variant> read(
80  std::shared_ptr< utils::BaseInputSource > source,
81  std::vector<bool> const& sample_filter
82  ) const;
83 
84  // -------------------------------------------------------------------------
85  // Parsing
86  // -------------------------------------------------------------------------
87 
88  bool parse_line(
89  utils::InputStream& input_stream,
90  Variant& sample_set
91  ) const;
92 
93  bool parse_line(
94  utils::InputStream& input_stream,
95  Variant& sample_set,
96  std::vector<bool> const& sample_filter
97  ) const;
98 
99  // -------------------------------------------------------------------------
100  // Internal Members
101  // -------------------------------------------------------------------------
102 
103 private:
104 
105  bool parse_line_(
106  utils::InputStream& input_stream,
107  Variant& sample_set,
108  std::vector<bool> const& sample_filter,
109  bool use_sample_filter
110  ) const;
111 
112  void parse_sample_(
113  utils::InputStream& input_stream,
114  BaseCounts& sample
115  ) const;
116 
117  void skip_sample_(
118  utils::InputStream& input_stream
119  ) const;
120 
121 };
122 
123 } // namespace population
124 } // namespace genesis
125 
126 #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:80
genesis::population::SyncReader::parse_line
bool parse_line(utils::InputStream &input_stream, Variant &sample_set) const
Definition: sync_reader.cpp:76
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:47
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:53
variant.hpp
genesis::population::SyncReader
Reader for PoPoolation2's "synchronized" files.
Definition: sync_reader.hpp:54
genesis::population::SyncReader::~SyncReader
~SyncReader()=default