A library for working with phylogenetic and population genetic data.
v0.27.0
pquery.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2018 Lucas Czech and HITS gGmbH
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@h-its.org>
20  Exelixis Lab, Heidelberg Institute for Theoretical Studies
21  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
22 */
23 
32 
35 
36 namespace genesis {
37 namespace placement {
38 
39 // =============================================================================
40 // General Modifiers
41 // =============================================================================
42 
44 {
46  clear_names();
47 }
48 
49 // =============================================================================
50 // Placement Iterators
51 // =============================================================================
52 
54 {
55  return placements_.begin();
56 }
57 
59 {
60  return placements_.end();
61 }
62 
64 {
65  return placements_.cbegin();
66 }
67 
69 {
70  return placements_.cend();
71 }
72 
74 {
75  return { placements_ };
76 }
77 
79 {
80  return { placements_ };
81 }
82 
83 std::vector<PqueryPlacement>& Pquery::expose_placements()
84 {
85  return placements_;
86 }
87 
88 // =============================================================================
89 // Placement Accessors and Modifiers
90 // =============================================================================
91 
93 {
94  placements_.emplace_back( edge );
95  return placements_.back();
96 }
97 
99 {
100  placements_.emplace_back( val );
101  return placements_.back();
102 }
103 
105  PlacementTreeEdge & edge,
106  PqueryPlacement const& val
107 ) {
108  placements_.emplace_back( val );
109  placements_.back().reset_edge( edge );
110  return placements_.back();
111 }
112 
114 {
115  return placements_.size();
116 }
117 
119 {
120  return placements_[index];
121 }
122 
123 PqueryPlacement const& Pquery::placement_at( size_t index ) const
124 {
125  return placements_[index];
126 }
127 
128 void Pquery::remove_placement_at( size_t index )
129 {
130  placements_.erase( placements_.begin() + index );
131 }
132 
134 {
135  placements_.clear();
136 }
137 
138 // =============================================================================
139 // Name Iterators
140 // =============================================================================
141 
143 {
144  return names_.begin();
145 }
146 
148 {
149  return names_.end();
150 }
151 
153 {
154  return names_.cbegin();
155 }
156 
158 {
159  return names_.cend();
160 }
161 
163 {
164  return { names_ };
165 }
166 
168 {
169  return { names_ };
170 }
171 
172 std::vector<PqueryName>& Pquery::expose_names()
173 {
174  return names_;
175 }
176 
177 // =============================================================================
178 // Name Accessors and Modifiers
179 // =============================================================================
180 
181 PqueryName& Pquery::add_name( std::string name, double multiplicity )
182 {
183  names_.emplace_back( name, multiplicity );
184  return names_.back();
185 }
186 
188 {
189  names_.push_back( PqueryName(other) );
190  return names_.back();
191 }
192 
193 size_t Pquery::name_size() const
194 {
195  return names_.size();
196 }
197 
198 PqueryName& Pquery::name_at( size_t index )
199 {
200  return names_.at(index);
201 }
202 
203 PqueryName const& Pquery::name_at( size_t index ) const
204 {
205  return names_.at(index);
206 }
207 
208 void Pquery::remove_name_at( size_t index )
209 {
210  names_.erase( names_.begin() + index );
211 }
212 
214 {
215  names_.clear();
216 }
217 
218 } // namespace placement
219 } // namespace genesis
genesis::placement::Pquery::clear_placements
void clear_placements()
Delete all PqueryPlacements of this Pquery.
Definition: pquery.cpp:133
genesis::placement::Pquery::name_size
size_t name_size() const
Return the number of PqueryNames stored in this Pquery.
Definition: pquery.cpp:193
genesis::placement::Pquery::remove_name_at
void remove_name_at(size_t index)
Remove the PqueryName at a certain index position within this Pquery.
Definition: pquery.cpp:208
genesis::placement::Pquery::begin_names
iterator_names begin_names()
Definition: pquery.cpp:142
placement_tree.hpp
pquery.hpp
genesis::placement::Pquery::remove_placement_at
void remove_placement_at(size_t index)
Remove the PqueryPlacement at a certain index position within this Pquery.
Definition: pquery.cpp:128
genesis::placement::Pquery::name_at
PqueryName & name_at(size_t index)
Return the PqueryName at a certain index.
Definition: pquery.cpp:198
genesis::placement::Pquery::begin_placements
iterator_placements begin_placements()
Definition: pquery.cpp:53
genesis::placement::Pquery::iterator_placements
std::vector< PqueryPlacement >::iterator iterator_placements
Definition: pquery.hpp:93
std.hpp
Provides some valuable additions to STD.
genesis::placement::Pquery::clear
void clear()
Clear all data stored in this Pquery, i.e., clear all PqueryNames and all PqueryPlacements.
Definition: pquery.cpp:43
genesis::placement::Pquery::placement_at
PqueryPlacement & placement_at(size_t index)
Return the PqueryPlacement at a certain index.
Definition: pquery.cpp:118
genesis::placement::Pquery::add_name
PqueryName & add_name(std::string name="", double multiplicity=1.0)
Create a new PqueryName using the provided parameters, add it to the Pquery and return it.
Definition: pquery.cpp:181
genesis::placement::Pquery::end_names
iterator_names end_names()
Definition: pquery.cpp:147
genesis::placement::Pquery::const_iterator_placements
std::vector< PqueryPlacement >::const_iterator const_iterator_placements
Definition: pquery.hpp:94
genesis::tree::TreeEdge
Definition: edge.hpp:60
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::Pquery::names
utils::Range< iterator_names > names()
Return a Range iterator to the PqueryNames.
Definition: pquery.cpp:162
genesis::placement::Pquery::placements
utils::Range< iterator_placements > placements()
Return a Range iterator to the PqueryPlacements.
Definition: pquery.cpp:73
genesis::placement::Pquery::placement_size
size_t placement_size() const
Return the number of PqueryPlacements stored in this Pquery.
Definition: pquery.cpp:113
genesis::placement::Pquery::clear_names
void clear_names()
Delete all PqueryNames of this Pquery.
Definition: pquery.cpp:213
genesis::placement::Pquery::iterator_names
std::vector< PqueryName >::iterator iterator_names
Definition: pquery.hpp:96
genesis::placement::Pquery::expose_names
std::vector< PqueryName > & expose_names()
Definition: pquery.cpp:172
genesis::placement::PqueryName
A name of a Pquery and its multiplicity.
Definition: name.hpp:55
genesis::placement::Pquery::end_placements
iterator_placements end_placements()
Definition: pquery.cpp:58
genesis::placement::PqueryPlacement
One placement position of a Pquery on a Tree.
Definition: placement/pquery/placement.hpp:75
genesis::placement::Pquery::add_placement
PqueryPlacement & add_placement(PlacementTreeEdge &edge)
Create a new PqueryPlacement at a given PlacementTreeEdge, add it to the Pquery and return it.
Definition: pquery.cpp:92
genesis::placement::Pquery::const_iterator_names
std::vector< PqueryName >::const_iterator const_iterator_names
Definition: pquery.hpp:97
genesis::placement::Pquery::expose_placements
std::vector< PqueryPlacement > & expose_placements()
Definition: pquery.cpp:83