A toolkit for working with phylogenetic data.
v0.24.0
jplace_reader.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_PLACEMENT_FORMATS_JPLACE_READER_H_
2 #define GENESIS_PLACEMENT_FORMATS_JPLACE_READER_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2019 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 
35 
36 #include <iosfwd>
37 #include <memory>
38 #include <string>
39 #include <unordered_map>
40 #include <vector>
41 
42 namespace genesis {
43 
44 // =================================================================================================
45 // Forward Declarations
46 // =================================================================================================
47 
48 namespace utils {
49  class JsonDocument;
50 }
51 
52 namespace tree {
53  class TreeEdge;
54 }
55 
56 namespace placement {
58 
59  class Pquery;
60  class Sample;
61  class SampleSet;
62 }
63 
64 // =================================================================================================
65 // Jplace Reader
66 // =================================================================================================
67 
68 namespace placement {
69 
100 {
101  // ---------------------------------------------------------------------
102  // Constructor and Rule of Five
103  // ---------------------------------------------------------------------
104 
105 public:
106 
107  JplaceReader() = default;
108  ~JplaceReader() = default;
109 
110  JplaceReader( JplaceReader const& ) = default;
111  JplaceReader( JplaceReader&& ) = default;
112 
113  JplaceReader& operator= ( JplaceReader const& ) = default;
114  JplaceReader& operator= ( JplaceReader&& ) = default;
115 
116  // ---------------------------------------------------------------------
117  // Reading
118  // ---------------------------------------------------------------------
119 
120 public:
121 
128  Sample read(
129  std::shared_ptr<utils::BaseInputSource> source
130  ) const;
131 
137  Sample read(
139  ) const;
140 
144  SampleSet read(
145  std::vector<std::shared_ptr<utils::BaseInputSource>> sources
146  ) const;
147 
154  void read(
155  std::vector<std::shared_ptr<utils::BaseInputSource>> sources,
156  SampleSet& target
157  ) const;
158 
159  // ---------------------------------------------------------------------
160  // Processing
161  // ---------------------------------------------------------------------
162 
163 private:
164 
174  int get_jplace_version_( utils::JsonDocument const& doc ) const;
175 
180  void process_jplace_version_( utils::JsonDocument const& doc ) const;
181 
186  void process_jplace_metadata_( utils::JsonDocument const& doc, Sample& smp ) const;
187 
192  void process_jplace_tree_( utils::JsonDocument const& doc, Sample& smp ) const;
193 
198  std::vector<std::string> process_jplace_fields_( utils::JsonDocument const& doc ) const;
199 
204  void process_jplace_placements_(
205  utils::JsonDocument& doc,
206  Sample& smp,
207  std::vector<std::string> const& fields
208  ) const;
209 
213  void process_jplace_placements_p_(
214  utils::JsonDocument const& pqry_obj,
215  Pquery& pquery,
216  std::vector<std::string> const& fields,
217  std::unordered_map<size_t, PlacementTreeEdge*> const& edge_num_map
218  ) const;
219 
223  void process_jplace_placements_nm_(
224  utils::JsonDocument const& pqry_obj,
225  Pquery& pquery
226  ) const;
227 
228  // ---------------------------------------------------------------------
229  // Properties
230  // ---------------------------------------------------------------------
231 
232 public:
233 
259  kIgnore,
260 
267  kLog,
268 
275  kFix,
276 
280  kLogAndFix,
281 
285  kThrow
286  };
287 
292  {
293  return invalid_number_behaviour_;
294  }
295 
305  {
306  invalid_number_behaviour_ = val;
307  return *this;
308  }
309 
310  // ---------------------------------------------------------------------
311  // Members
312  // ---------------------------------------------------------------------
313 
314 private:
315 
316  InvalidNumberBehaviour invalid_number_behaviour_ = InvalidNumberBehaviour::kIgnore;
317 
318 };
319 
320 } // namespace placement
321 } // namespace genesis
322 
323 #endif // include guard
A pquery holds a set of PqueryPlacements and a set of PqueryNames.
Definition: pquery.hpp:82
InvalidNumberBehaviour invalid_number_behaviour() const
Return the currenlty set InvalidNumberBehaviour.
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
JplaceReader & invalid_number_behaviour(InvalidNumberBehaviour val)
Set the InvalidNumberBehaviour.
Store a set of Samples with associated names.
Definition: sample_set.hpp:54
Store a Json value of any kind.
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on...
Definition: sample.hpp:68
InvalidNumberBehaviour
Enum to determine the behaviour of the reader in case of invalid numbers.