#include <genesis/placement/sample.hpp>
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on.
This class stores both the tree and the set of pqueries with their placements. It is thus a representation of a whole jplace
file according to the standard.
For more information on the jplace
format, see the following publication:
Matsen FA, Hoffman NG, Gallagher A, Stamatakis A. 2012. A Format for Phylogenetic Placement. PLoS ONE 7(2): e31009. doi:10.1371/journal.pone.0031009 http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0031009
This class and other related classes are modeled after this standard.
Definition at line 68 of file sample.hpp.
Public Member Functions | |
Sample ()=default | |
Default constructor. More... | |
Sample (PlacementTree const &tree) | |
Constructor taking a reference tree. More... | |
Sample (Sample &&)=default | |
Move constructor. More... | |
Sample (Sample const &) | |
Copy constructor. More... | |
~Sample ()=default | |
Pquery & | add () |
Create an empty Pquery, add it to the Sample and return it. More... | |
Pquery & | add (Pquery const &other) |
Create a Pquery as a copy of the provided one, add it to the sample and return it. More... | |
Pquery & | at (size_t index) |
Return the Pquery at a certain index. More... | |
Pquery const & | at (size_t index) const |
Return the Pquery at a certain index. More... | |
iterator_pqueries | begin () |
Return an iterator to the beginning of the Pqueries of this Sample. More... | |
const_iterator_pqueries | begin () const |
Return a constiterator to the beginning of the Pqueries of this Sample. More... | |
void | clear () |
Clears all data of this object. More... | |
void | clear_pqueries () |
Clear all Pqueries of this Sample. More... | |
bool | empty () const |
Return whether the tree or the set of Pqueries is empty. More... | |
iterator_pqueries | end () |
Return an iterator to the end of the Pqueries of this Sample. More... | |
const_iterator_pqueries | end () const |
Return a const iterator to the end of the Pqueries of this Sample. More... | |
Sample & | operator= (Sample &&)=default |
Move assignment. More... | |
Sample & | operator= (Sample const &) |
Copy assignment. More... | |
utils::Range< iterator_pqueries > | pqueries () |
Return a Range iterator to the Pqueries . More... | |
utils::Range< const_iterator_pqueries > | pqueries () const |
Return a const Range iterator to the Pqueries . More... | |
void | remove (iterator_pqueries first, iterator_pqueries last) |
Remove the Pqueries between the first (inclusive) and the last (exclusive) iterator position from the Sample. More... | |
void | remove (iterator_pqueries position) |
Remove the Pquery at a given iterator position from the Sample. More... | |
void | remove (size_t first_index, size_t last_index) |
Remove the Pqueries between the first_index (inclusive) and the last_index (exclusive) from the Sample. More... | |
void | remove (size_t index) |
Remove the Pquery at a given index from the Sample. More... | |
size_t | size () const |
Return the number of Pqueries that are stored in this Sample. More... | |
void | swap (Sample &other) |
Swap the contents of this Sample with the contents of another Sample. More... | |
PlacementTree & | tree () |
Get the PlacementTree of this Sample. More... | |
PlacementTree const & | tree () const |
Get the PlacementTree of this Sample. More... | |
Public Types | |
using | const_iterator_pqueries = std::vector< Pquery >::const_iterator |
using | iterator_pqueries = std::vector< Pquery >::iterator |
Public Attributes | |
std::unordered_map< std::string, std::string > | metadata |
Friends | |
void | swap (Sample &lhs, Sample &rhs) |
Swap the contents of two Samples with each other. More... | |
|
default |
Default constructor.
|
explicit |
Constructor taking a reference tree.
The tree has to have the data types PlacementNodeData and PlacementEdgeData at its nodes and edges, respectively. If not, an exception is thrown.
Definition at line 55 of file sample.cpp.
Copy constructor.
Definition at line 63 of file sample.cpp.
|
default |
Pquery & add | ( | ) |
Create an empty Pquery, add it to the Sample and return it.
The returned reference can then be used to add PqueryPlacements and PqueryNames to the Pquery.
As this function might reallocate the memory where Pqueries are stored, all iterators and pointers to the Pqueries of this Sample are invalidated.
Definition at line 152 of file sample.cpp.
Create a Pquery as a copy of the provided one, add it to the sample and return it.
It is possible to provide a Pquery from a different Sample, as long as the tree topology of both Samples is identical, including identical edge indices and edge_nums. For that purpose, this function automatically adjusts the internal pointers of the Pquery and its PqueryPlacements accordingly. Furthermore, the proximal_length
is also adjusted so that the relative position on the edge maintained.
However, if the trees are incompatible (i.e., have a different topology, indices or edge nums), the PqueryPlacements will either point to different edges or the function might throw an exception, in cases where the tree does not have a corresponding edge at all. To further ensure correct behaviour, the function also checks whether the edge_num is the same for the edge of the original PqueryPlacement and the new one, and throws an std::runtime_error if not.
As this function might reallocate the memory where Pqueries are stored, all iterators and pointers to the Pqueries of this Sample are invalidated.
Definition at line 158 of file sample.cpp.
Pquery & at | ( | size_t | index | ) |
Return the Pquery at a certain index.
Definition at line 190 of file sample.cpp.
Pquery const & at | ( | size_t | index | ) | const |
Return the Pquery at a certain index.
Definition at line 195 of file sample.cpp.
Sample::const_iterator_pqueries begin | ( | ) |
Return an iterator to the beginning of the Pqueries of this Sample.
Definition at line 244 of file sample.cpp.
const_iterator_pqueries begin | ( | ) | const |
void clear | ( | ) |
Clears all data of this object.
The Pqueries , the PlacementTree and the metadata are deleted.
Definition at line 113 of file sample.cpp.
void clear_pqueries | ( | ) |
Clear all Pqueries of this Sample.
All Pqueries are deleted. However, the PlacementTree and the metadata are left as they are. Thus this is a useful method for e.g., simulating placements: Take a copy of a given sample, clear its Pqueries, then generate new ones using the Simulator.
Definition at line 235 of file sample.cpp.
bool empty | ( | ) | const |
Return whether the tree or the set of Pqueries is empty.
Definition at line 143 of file sample.cpp.
Sample::const_iterator_pqueries end | ( | ) |
Return an iterator to the end of the Pqueries of this Sample.
Definition at line 254 of file sample.cpp.
const_iterator_pqueries end | ( | ) | const |
Copy assignment.
Definition at line 86 of file sample.cpp.
utils::Range< Sample::const_iterator_pqueries > pqueries | ( | ) |
Return a Range iterator to the Pqueries .
This makes iterating Pqueries via a range based for loop easy.
Definition at line 264 of file sample.cpp.
utils::Range<const_iterator_pqueries> pqueries | ( | ) | const |
Return a const Range iterator to the Pqueries .
This makes iterating Pqueries via a range based for loop easy.
void remove | ( | iterator_pqueries | first, |
iterator_pqueries | last | ||
) |
Remove the Pqueries between the first
(inclusive) and the last
(exclusive) iterator position from the Sample.
Definition at line 226 of file sample.cpp.
void remove | ( | iterator_pqueries | position | ) |
Remove the Pquery at a given iterator position
from the Sample.
Definition at line 221 of file sample.cpp.
void remove | ( | size_t | first_index, |
size_t | last_index | ||
) |
Remove the Pqueries between the first_index
(inclusive) and the last_index
(exclusive) from the Sample.
Definition at line 209 of file sample.cpp.
void remove | ( | size_t | index | ) |
Remove the Pquery at a given index
from the Sample.
As this function might reallocate the memory where Pqueries are stored, all iterators and pointer to the Pqueries of this Sample are invalidated.
Definition at line 204 of file sample.cpp.
size_t size | ( | ) | const |
Return the number of Pqueries that are stored in this Sample.
Definition at line 138 of file sample.cpp.
void swap | ( | Sample & | other | ) |
Swap the contents of this Sample with the contents of another Sample.
Definition at line 96 of file sample.cpp.
PlacementTree const & tree | ( | ) |
Get the PlacementTree of this Sample.
Definition at line 124 of file sample.cpp.
PlacementTree const& tree | ( | ) | const |
Get the PlacementTree of this Sample.
Swap the contents of two Samples with each other.
Definition at line 104 of file sample.cpp.
using const_iterator_pqueries = std::vector<Pquery>::const_iterator |
Definition at line 78 of file sample.hpp.
using iterator_pqueries = std::vector<Pquery>::iterator |
Definition at line 77 of file sample.hpp.
std::unordered_map<std::string, std::string> metadata |
Definition at line 296 of file sample.hpp.