A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2017 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  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 
124  // -------------------------------------------------------------------------
125  // Modifiers
126  // -------------------------------------------------------------------------
127 
133  void clear();
134 
135  // -------------------------------------------------------------------------
136  // Tree Accessors and Modifiers
137  // -------------------------------------------------------------------------
138 
142  PlacementTree& tree();
143 
147  PlacementTree const& tree() const;
148 
149  // -------------------------------------------------------------------------
150  // Pquery Accessors and Modifiers
151  // -------------------------------------------------------------------------
152 
156  size_t size() const;
157 
161  bool empty() const;
162 
171  Pquery& add();
172 
193  Pquery& add( Pquery const& other );
194 
198  Pquery& at( size_t index );
199 
203  Pquery const& at( size_t index ) const;
204 
211  void remove( size_t index );
212 
217  void remove( size_t first_index, size_t last_index );
218 
222  void remove( iterator_pqueries position );
223 
228  void remove( iterator_pqueries first, iterator_pqueries last );
229 
237  void clear_pqueries();
238 
239  // -------------------------------------------------------------------------
240  // Pquery Iterator
241  // -------------------------------------------------------------------------
242 
247 
253 
258 
263 
270 
277 
278  // -------------------------------------------------------------------------
279  // Members
280  // -------------------------------------------------------------------------
281 
282 private:
283 
284  std::vector<Pquery> pqueries_;
285  PlacementTree tree_;
286 
287 public:
288 
289  // There is not much to mess up here for a user, so we can simply make this public.
290  // Okay, this is ugly. But for now, it's way easier. We never use the metadata anyway...
291  std::unordered_map<std::string, std::string> metadata;
292 
293 };
294 
295 } // namespace placement
296 } // namespace genesis
297 
298 #endif // include guard
size_t size() const
Return the number of Pqueries that are stored in this Sample.
Definition: sample.cpp:133
PlacementTree & tree()
Get the PlacementTree of this Sample.
Definition: sample.cpp:119
A pquery holds a set of PqueryPlacements and a set of PqueryNames.
Definition: pquery.hpp:82
Pquery & at(size_t index)
Return the Pquery at a certain index.
Definition: sample.cpp:185
utils::Range< iterator_pqueries > pqueries()
Return a Range iterator to the Pqueries .
Definition: sample.cpp:259
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:95
Sample()=default
Default constructor.
std::unordered_map< std::string, std::string > metadata
Definition: sample.hpp:291
std::vector< Pquery >::const_iterator const_iterator_pqueries
Definition: sample.hpp:78
bool empty() const
Return whether the tree or the set of Pqueries is empty.
Definition: sample.cpp:138
std::vector< Pquery >::iterator iterator_pqueries
Definition: sample.hpp:77
iterator_pqueries begin()
Return an iterator to the beginning of the Pqueries of this Sample.
Definition: sample.cpp:239
void clear_pqueries()
Clear all Pqueries of this Sample.
Definition: sample.cpp:230
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on...
Definition: sample.hpp:68
void swap(Sample &other)
Swap the contents of this Sample with the contents of another Sample.
Definition: sample.cpp:96
Sample & operator=(Sample const &)
Copy assignment.
Definition: sample.cpp:86
iterator_pqueries end()
Return an iterator to the end of the Pqueries of this Sample.
Definition: sample.cpp:249
void clear()
Clears all data of this object.
Definition: sample.cpp:108
Pquery & add()
Create an empty Pquery, add it to the Sample and return it.
Definition: sample.cpp:147