A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Sample Class Reference

#include <genesis/placement/sample.hpp>

Detailed Description

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 const &)
 Copy constructor. More...
 
 Sample (Sample &&)=default
 Move constructor. More...
 
 ~Sample ()=default
 
Pqueryadd ()
 Create an empty Pquery, add it to the Sample and return it. More...
 
Pqueryadd (Pquery const &other)
 Create a Pquery as a copy of the provided one, add it to the sample and return it. More...
 
Pqueryat (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...
 
Sampleoperator= (Sample const &)
 Copy assignment. More...
 
Sampleoperator= (Sample &&)=default
 Move assignment. More...
 
utils::Range< iterator_pqueriespqueries ()
 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 (size_t index)
 Remove the Pquery at a given index 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 (iterator_pqueries position)
 Remove the Pquery at a given iterator position from the Sample. 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...
 
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...
 
PlacementTreetree ()
 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
 

Constructor & Destructor Documentation

Sample ( )
default

Default constructor.

Sample ( PlacementTree const &  tree)

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.

Sample ( Sample const &  other)

Copy constructor.

Definition at line 63 of file sample.cpp.

Sample ( Sample &&  )
default

Move constructor.

~Sample ( )
default

Member Function Documentation

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 147 of file sample.cpp.

Pquery & add ( Pquery const &  other)

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 153 of file sample.cpp.

Pquery & at ( size_t  index)

Return the Pquery at a certain index.

Definition at line 185 of file sample.cpp.

Pquery const & at ( size_t  index) const

Return the Pquery at a certain index.

Definition at line 190 of file sample.cpp.

Return an iterator to the beginning of the Pqueries of this Sample.

Definition at line 239 of file sample.cpp.

Return a constiterator to the beginning of the Pqueries of this Sample.

Definition at line 244 of file sample.cpp.

void clear ( )

Clears all data of this object.

The Pqueries , the PlacementTree and the metadata are deleted.

Definition at line 108 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 230 of file sample.cpp.

bool empty ( ) const

Return whether the tree or the set of Pqueries is empty.

Definition at line 138 of file sample.cpp.

Return an iterator to the end of the Pqueries of this Sample.

Definition at line 249 of file sample.cpp.

Return a const iterator to the end of the Pqueries of this Sample.

Definition at line 254 of file sample.cpp.

Sample & operator= ( Sample const &  other)

Copy assignment.

Definition at line 86 of file sample.cpp.

Sample& operator= ( Sample &&  )
default

Move assignment.

Return a Range iterator to the Pqueries .

This makes iterating Pqueries via a range based for loop easy.

Definition at line 259 of file sample.cpp.

Return a const Range iterator to the Pqueries .

This makes iterating Pqueries via a range based for loop easy.

Definition at line 264 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 199 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 204 of file sample.cpp.

void remove ( iterator_pqueries  position)

Remove the Pquery at a given iterator position from the Sample.

Definition at line 216 of file sample.cpp.

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 221 of file sample.cpp.

size_t size ( ) const

Return the number of Pqueries that are stored in this Sample.

Definition at line 133 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 & tree ( )

Get the PlacementTree of this Sample.

Definition at line 119 of file sample.cpp.

PlacementTree const & tree ( ) const

Get the PlacementTree of this Sample.

Definition at line 124 of file sample.cpp.

Member Typedef Documentation

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.

Member Data Documentation

std::unordered_map<std::string, std::string> metadata

Definition at line 291 of file sample.hpp.


The documentation for this class was generated from the following files: