A library for working with phylogenetic and population genetic data.
v0.27.0
sample.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_PLACEMENT_SAMPLE_H_
2 #define GENESIS_PLACEMENT_SAMPLE_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 <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #include <memory>
35 #include <string>
36 #include <unordered_map>
37 #include <utility>
38 #include <vector>
39 
42 
44 
45 namespace genesis {
46 namespace placement {
47 
48 // =================================================================================================
49 // Sample
50 // =================================================================================================
51 
68 class Sample
69 {
70 
71 public:
72 
73  // -------------------------------------------------------------------
74  // Typedefs
75  // -------------------------------------------------------------------
76 
77  using iterator_pqueries = std::vector<Pquery>::iterator;
78  using const_iterator_pqueries = std::vector<Pquery>::const_iterator;
79 
80  // -------------------------------------------------------------------------
81  // Constructors and Rule of Five
82  // -------------------------------------------------------------------------
83 
87  Sample() = default;
88 
95  explicit Sample( PlacementTree const& tree );
96 
100  Sample( Sample const& );
101 
105  Sample( Sample&& ) = default;
106 
110  Sample& operator= ( Sample const& );
111 
115  Sample& operator= ( Sample&& ) = default;
116 
117  ~Sample() = default;
118 
122  void swap( Sample& other );
123 
127  friend void swap( Sample& lhs, Sample& rhs );
128 
129  // -------------------------------------------------------------------------
130  // Modifiers
131  // -------------------------------------------------------------------------
132 
138  void clear();
139 
140  // -------------------------------------------------------------------------
141  // Tree Accessors and Modifiers
142  // -------------------------------------------------------------------------
143 
147  PlacementTree& tree();
148 
152  PlacementTree const& tree() const;
153 
154  // -------------------------------------------------------------------------
155  // Pquery Accessors and Modifiers
156  // -------------------------------------------------------------------------
157 
161  size_t size() const;
162 
166  bool empty() const;
167 
176  Pquery& add();
177 
198  Pquery& add( Pquery const& other );
199 
203  Pquery& at( size_t index );
204 
208  Pquery const& at( size_t index ) const;
209 
216  void remove( size_t index );
217 
222  void remove( size_t first_index, size_t last_index );
223 
227  void remove( iterator_pqueries position );
228 
233  void remove( iterator_pqueries first, iterator_pqueries last );
234 
242  void clear_pqueries();
243 
244  // -------------------------------------------------------------------------
245  // Pquery Iterator
246  // -------------------------------------------------------------------------
247 
252 
258 
263 
268 
275 
282 
283  // -------------------------------------------------------------------------
284  // Members
285  // -------------------------------------------------------------------------
286 
287 private:
288 
289  std::vector<Pquery> pqueries_;
290  PlacementTree tree_;
291 
292 public:
293 
294  // There is not much to mess up here for a user, so we can simply make this public.
295  // Okay, this is ugly. But for now, it's way easier. We never use the metadata anyway...
296  std::unordered_map<std::string, std::string> metadata;
297 
298 };
299 
300 } // namespace placement
301 } // namespace genesis
302 
303 #endif // include guard
genesis::placement::Sample::tree
PlacementTree & tree()
Get the PlacementTree of this Sample.
Definition: sample.cpp:124
genesis::placement::Sample::size
size_t size() const
Return the number of Pqueries that are stored in this Sample.
Definition: sample.cpp:138
genesis::placement::Sample::end
iterator_pqueries end()
Return an iterator to the end of the Pqueries of this Sample.
Definition: sample.cpp:254
placement_tree.hpp
genesis::placement::Sample::clear_pqueries
void clear_pqueries()
Clear all Pqueries of this Sample.
Definition: sample.cpp:235
genesis::placement::Sample
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on.
Definition: sample.hpp:68
pquery.hpp
genesis::placement::Sample::const_iterator_pqueries
std::vector< Pquery >::const_iterator const_iterator_pqueries
Definition: sample.hpp:78
genesis::placement::Sample::empty
bool empty() const
Return whether the tree or the set of Pqueries is empty.
Definition: sample.cpp:143
genesis::placement::Sample::add
Pquery & add()
Create an empty Pquery, add it to the Sample and return it.
Definition: sample.cpp:152
genesis::placement::Sample::operator=
Sample & operator=(Sample const &)
Copy assignment.
Definition: sample.cpp:86
genesis::tree::Tree
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:97
genesis::placement::Sample::iterator_pqueries
std::vector< Pquery >::iterator iterator_pqueries
Definition: sample.hpp:77
genesis::placement::Sample::begin
iterator_pqueries begin()
Return an iterator to the beginning of the Pqueries of this Sample.
Definition: sample.cpp:244
genesis::placement::Pquery
A pquery holds a set of PqueryPlacements and a set of PqueryNames.
Definition: pquery.hpp:82
range.hpp
genesis::placement::Sample::at
Pquery & at(size_t index)
Return the Pquery at a certain index.
Definition: sample.cpp:190
genesis::placement::Sample::Sample
Sample()=default
Default constructor.
genesis::utils::Range
Simple wrapper for typical begin() and end() iterators, to be used in range-based for loops.
Definition: range.hpp:46
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::placement::Sample::clear
void clear()
Clears all data of this object.
Definition: sample.cpp:113
genesis::placement::Sample::swap
void swap(Sample &other)
Swap the contents of this Sample with the contents of another Sample.
Definition: sample.cpp:96
genesis::placement::Sample::~Sample
~Sample()=default
genesis::placement::Sample::remove
void remove(size_t index)
Remove the Pquery at a given index from the Sample.
Definition: sample.cpp:204
genesis::placement::Sample::pqueries
utils::Range< iterator_pqueries > pqueries()
Return a Range iterator to the Pqueries .
Definition: sample.cpp:264
genesis::placement::Sample::metadata
std::unordered_map< std::string, std::string > metadata
Definition: sample.hpp:296