45 #include <unordered_map> 58 if( ! tree::tree_data_is< PlacementNodeData, PlacementEdgeData >( tree_ ) ) {
59 throw std::runtime_error(
"Tree for constructing the Sample is no PlacementTree." );
69 pqueries_ = other.pqueries_;
74 for(
auto& pqry : pqueries_ ) {
75 for(
auto& place : pqry.placements() ) {
78 auto index = place.edge().index();
81 place.reset_edge( tree_.
edge_at( index ) );
91 auto tmp =
Sample( other );
99 swap( pqueries_, other.pqueries_ );
100 swap( tree_, other.tree_ );
135 return pqueries_.size();
140 return tree_.
empty() || pqueries_.empty();
149 pqueries_.push_back(
Pquery() );
150 return pqueries_.back();
155 pqueries_.push_back( other );
158 for(
auto& place : pqueries_.back().placements() ) {
162 auto const edge_index = place.edge().index();
163 auto const old_edge_num = old_edge_data.
edge_num();
164 auto const rel_pos = place.proximal_length / old_edge_data.branch_length;
165 place.reset_edge(
tree().edge_at( edge_index ));
170 if( old_edge_num != edge_data.edge_num() ) {
171 throw std::runtime_error(
172 "Trees are incompatible for copying Pqueries between Samples." 175 place.proximal_length = rel_pos * edge_data.branch_length;
178 return pqueries_.back();
187 return pqueries_.at( index );
192 return pqueries_.at( index );
201 pqueries_.erase( pqueries_.begin() + index );
206 if( first_index >= pqueries_.size()
207 || last_index >= pqueries_.size()
208 || first_index >= last_index
210 throw std::out_of_range(
"Invalid indices for removing from SequenceSet." );
213 pqueries_.erase( pqueries_.begin() + first_index, pqueries_.begin() + last_index );
218 pqueries_.erase( position );
223 pqueries_.erase( first, last );
241 return pqueries_.begin();
246 return pqueries_.begin();
251 return pqueries_.end();
256 return pqueries_.end();
261 return { pqueries_ };
266 return { pqueries_ };
Data class for PlacementTreeEdges. Stores the branch length of the edge, and the edge_num, as defined in the jplace standard.
PlacementTree & tree()
Get the PlacementTree of this Sample.
void swap(SequenceSet &lhs, SequenceSet &rhs)
A pquery holds a set of PqueryPlacements and a set of PqueryNames.
bool empty() const
Return whether the Tree is empty (i.e., has no nodes, edges and links).
Pquery & at(size_t index)
Return the Pquery at a certain index.
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
Provides some valuable additions to STD.
tree::Tree PlacementTree
Alias for a tree::Tree used for a tree with information needed for storing Pqueries. This kind of tree is used by Sample.
utils::Range< iterator_pqueries > pqueries()
Return a Range iterator to the Pqueries .
Class for representing phylogenetic trees.
Sample()=default
Default constructor.
std::unordered_map< std::string, std::string > metadata
size_t size() const
Return the number of Pqueries that are stored in this Sample.
std::vector< Pquery >::const_iterator const_iterator_pqueries
TreeEdge & edge_at(size_t index)
Return the TreeEdge at a certain index.
std::vector< Pquery >::iterator iterator_pqueries
iterator_pqueries begin()
Return an iterator to the beginning of the Pqueries of this Sample.
void clear_pqueries()
Clear all Pqueries of this Sample.
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on...
void swap(Sample &other)
Swap the contents of this Sample with the contents of another Sample.
Simple wrapper for typical begin() and end() iterators, to be used in range-based for loops...
EdgeNumType edge_num() const
Return the edge_num of this edge. This value is defined by the jplace standard.
void remove(size_t index)
Remove the Pquery at a given index from the Sample.
Sample & operator=(Sample const &)
Copy assignment.
iterator_pqueries end()
Return an iterator to the end of the Pqueries of this Sample.
void clear()
Clears all data of this object.
bool empty() const
Return whether the tree or the set of Pqueries is empty.
Pquery & add()
Create an empty Pquery, add it to the Sample and return it.