A toolkit for working with phylogenetic data.
v0.24.0
taxonomy_reader.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TAXONOMY_FORMATS_TAXONOMY_READER_H_
2 #define GENESIS_TAXONOMY_FORMATS_TAXONOMY_READER_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2018 Lucas Czech and HITS gGmbH
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 <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
37 
38 #include <string>
39 
40 namespace genesis {
41 
42 // =================================================================================================
43 // Forward Declarations
44 // =================================================================================================
45 
46 namespace utils {
47 
48  class InputStream;
49 
50 } // namespace utils
51 
52 namespace taxonomy {
53 
54  class Taxonomy;
55 
56 // =================================================================================================
57 // Taxonomy Reader
58 // =================================================================================================
59 
109 {
110 public:
111 
112  // ---------------------------------------------------------------------
113  // Enums and Structs
114  // ---------------------------------------------------------------------
115 
119  struct Line
120  {
121  std::string name;
122  std::string rank;
123  std::string id;
124  };
125 
126  // ---------------------------------------------------------------------
127  // Constructor and Rule of Five
128  // ---------------------------------------------------------------------
129 
135  TaxonomyReader();
136  ~TaxonomyReader() = default;
137 
138  TaxonomyReader( TaxonomyReader const& ) = default;
139  TaxonomyReader( TaxonomyReader&& ) = default;
140 
141  TaxonomyReader& operator= ( TaxonomyReader const& ) = default;
142  TaxonomyReader& operator= ( TaxonomyReader&& ) = default;
143 
144  // ---------------------------------------------------------------------
145  // Reading
146  // ---------------------------------------------------------------------
147 
154  void read( std::shared_ptr<utils::BaseInputSource> source, Taxonomy& target ) const;
155 
162  Taxonomy read( std::shared_ptr<utils::BaseInputSource> source ) const;
163 
164  // ---------------------------------------------------------------------
165  // Parsing
166  // ---------------------------------------------------------------------
167 
171  void parse_document(
172  utils::InputStream& it,
173  Taxonomy& tax
174  ) const;
175 
181  Line parse_line(
183  ) const;
184 
185  // ---------------------------------------------------------------------
186  // Properties
187  // ---------------------------------------------------------------------
188 
201  utils::CsvReader& csv_reader();
202 
210  TaxopathParser& taxopath_parser();
211 
230  TaxonomyReader& name_field_position( int value );
231 
237  int name_field_position() const;
238 
253  TaxonomyReader& rank_field_position( int value );
254 
260  int rank_field_position() const;
261 
276  TaxonomyReader& id_field_position( int value );
277 
283  int id_field_position() const;
284 
306  TaxonomyReader& expect_strict_order( bool value );
307 
313  bool expect_strict_order() const;
314 
315  // ---------------------------------------------------------------------
316  // Members
317  // ---------------------------------------------------------------------
318 
319 private:
320 
321  utils::CsvReader csv_reader_;
322  TaxopathParser taxopath_parser_;
323 
324  int name_field_position_ = 0;
325  int rank_field_position_ = -1;
326  int id_field_position_ = -1;
327  bool expect_strict_order_ = false;
328 
329 };
330 
331 } // namespace taxonomy
332 } // namespace genesis
333 
334 #endif // include guard
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
Store a Taxonomy, i.e., a nested hierarchy of Taxa.
Read Comma/Character Separated Values (CSV) data and other delimiter-separated formats.
Helper class to parse a string containing a taxonomic path string into a Taxopath object...
Internal helper structure that stores the relevant data of one line while reading.
Stream interface for reading data from an InputSource, that keeps track of line and column counters...
Read Taxonomy file formats.