A library for working with phylogenetic and population genetic data.
v0.32.0
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 &&)=default
 Move constructor. More...
 
 Sample (Sample const &)
 Copy 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 &&)=default
 Move assignment. More...
 
Sampleoperator= (Sample const &)
 Copy assignment. More...
 
utils::Range< iterator_pqueriespqueries ()
 Return a Range iterator to the Pqueries . More...
 
utils::Range< const_iterator_pqueriespqueries () 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...
 
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
 

Friends

void swap (Sample &lhs, Sample &rhs)
 Swap the contents of two Samples with each other. More...
 

Constructor & Destructor Documentation

◆ Sample() [1/4]

Sample ( )
default

Default constructor.

◆ Sample() [2/4]

Sample ( PlacementTree const &  tree)
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.

◆ Sample() [3/4]

Sample ( Sample const &  other)

Copy constructor.

Definition at line 63 of file sample.cpp.

◆ Sample() [4/4]

Sample ( Sample &&  )
default

Move constructor.

◆ ~Sample()

~Sample ( )
default

Member Function Documentation

◆ add() [1/2]

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.

◆ add() [2/2]

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

◆ at() [1/2]

Pquery & at ( size_t  index)

Return the Pquery at a certain index.

Definition at line 190 of file sample.cpp.

◆ at() [2/2]

Pquery const & at ( size_t  index) const

Return the Pquery at a certain index.

Definition at line 195 of file sample.cpp.

◆ begin() [1/2]

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

Definition at line 244 of file sample.cpp.

◆ begin() [2/2]

const_iterator_pqueries begin ( ) const

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

◆ clear()

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.

◆ clear_pqueries()

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.

◆ empty()

bool empty ( ) const

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

Definition at line 143 of file sample.cpp.

◆ end() [1/2]

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

Definition at line 254 of file sample.cpp.

◆ end() [2/2]

const_iterator_pqueries end ( ) const

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

◆ operator=() [1/2]

Sample& operator= ( Sample &&  )
default

Move assignment.

◆ operator=() [2/2]

Sample & operator= ( Sample const &  other)

Copy assignment.

Definition at line 86 of file sample.cpp.

◆ pqueries() [1/2]

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.

◆ pqueries() [2/2]

Return a const Range iterator to the Pqueries .

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

◆ remove() [1/4]

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.

◆ remove() [2/4]

void remove ( iterator_pqueries  position)

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

Definition at line 221 of file sample.cpp.

◆ remove() [3/4]

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.

◆ remove() [4/4]

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()

size_t size ( ) const

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

Definition at line 138 of file sample.cpp.

◆ swap()

void swap ( Sample other)

Swap the contents of this Sample with the contents of another Sample.

Definition at line 96 of file sample.cpp.

◆ tree() [1/2]

PlacementTree const & tree ( )

Get the PlacementTree of this Sample.

Definition at line 124 of file sample.cpp.

◆ tree() [2/2]

PlacementTree const& tree ( ) const

Get the PlacementTree of this Sample.

Friends And Related Function Documentation

◆ swap

void swap ( Sample lhs,
Sample rhs 
)
friend

Swap the contents of two Samples with each other.

Definition at line 104 of file sample.cpp.

Member Typedef Documentation

◆ const_iterator_pqueries

using const_iterator_pqueries = std::vector<Pquery>::const_iterator

Definition at line 78 of file sample.hpp.

◆ iterator_pqueries

using iterator_pqueries = std::vector<Pquery>::iterator

Definition at line 77 of file sample.hpp.

Member Data Documentation

◆ metadata

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

Definition at line 296 of file sample.hpp.


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