#include <genesis/tree/tree.hpp>
Class for representing phylogenetic trees.
A tree in this implementation consists of three types of elements: Links, Nodes and Edges. The topoloty of the tree is completely described by the links, while nodes and edges add the capability to store data on the tree.
Data in the Tree is not directly stored in the elements (Links, Nodes, Edges) of the Tree. Instead, data belonging to nodes and edges can be stored in their data pointers. For this, the data classes need to derive from BaseNodeData and BaseEdgeData, respectively.
Additional information concerning the whole tree, as well as special algorithms working on the tree and its data are also not direct members of the tree - for reasons of flexibility and extensibility: Instead of adding more and more data and algorithms to the tree, we create new classes that encapsulate a tree and all the other needed code to work with it. See the Sample class for an example.
Thus, the tree itself only contains the needed information to store and work with a topology.
This class has several redundant ways of representing the same information. On the one hand, this makes using a Tree easy, as one can chose the representaion of data that best fits a given task. On the other hand, maintaining all those invariants when changing the tree topology is tedious. Here is a (comprehensive?) list of invariants of this class:
node_at(i).index() == i
.Those invariants are established when the Tree is constructed.
Definition at line 97 of file tree/tree.hpp.
Public Member Functions | |
Tree ()=default | |
Tree (Tree &&)=default | |
Tree (Tree const &other) | |
Copy constructor. More... | |
~Tree ()=default | |
IteratorEdges | begin_edges () |
ConstIteratorEdges | begin_edges () const |
IteratorLinks | begin_links () |
ConstIteratorLinks | begin_links () const |
IteratorNodes | begin_nodes () |
ConstIteratorNodes | begin_nodes () const |
void | clear () |
Deletes all data of the tree, including all links, nodes and edges. More... | |
Tree | clone_topology () const |
Return a Tree with the same topology, but without any data. More... | |
TreeEdge & | edge_at (size_t index) |
Return the TreeEdge at a certain index. More... | |
TreeEdge const & | edge_at (size_t index) const |
Return the TreeEdge at a certain index. More... | |
size_t | edge_count () const |
Return the number of TreeEdges of the Tree. More... | |
utils::Range< IteratorEdges > | edges () |
utils::Range< ConstIteratorEdges > | edges () const |
bool | empty () const |
Return whether the Tree is empty (i.e., has no nodes, edges and links). More... | |
IteratorEdges | end_edges () |
ConstIteratorEdges | end_edges () const |
IteratorLinks | end_links () |
ConstIteratorLinks | end_links () const |
IteratorNodes | end_nodes () |
ConstIteratorNodes | end_nodes () const |
EdgeContainerType & | expose_edge_container () |
Get the container that stores all TreeEdges of the Tree. More... | |
LinkContainerType & | expose_link_container () |
Get the container that stores all TreeLinks of the Tree. More... | |
NodeContainerType & | expose_node_container () |
Get the container that stores all TreeNodes of the Tree. More... | |
TreeLink & | link_at (size_t index) |
Return the TreeLink at a certain index. More... | |
TreeLink const & | link_at (size_t index) const |
Return the TreeLink at a certain index. More... | |
size_t | link_count () const |
Return the number of TreeLinks of the Tree. More... | |
utils::Range< IteratorLinks > | links () |
utils::Range< ConstIteratorLinks > | links () const |
TreeNode & | node_at (size_t index) |
Return the TreeNode at a certain index. More... | |
TreeNode const & | node_at (size_t index) const |
Return the TreeNode at a certain index. More... | |
size_t | node_count () const |
Return the number of TreeNodes of the Tree. More... | |
utils::Range< IteratorNodes > | nodes () |
utils::Range< ConstIteratorNodes > | nodes () const |
Tree & | operator= (Tree &&)=default |
Tree & | operator= (Tree const &other) |
Assignment operator. More... | |
Tree & | reset_root_link (TreeLink *root_link) |
Reset the link that is considered to be the root of the Tree. More... | |
TreeLink & | root_link () |
Return the TreeLink at the current root of the Tree. More... | |
TreeLink const & | root_link () const |
Return the TreeLink at the current root of the Tree. More... | |
TreeNode & | root_node () |
Return the TreeNode at the current root of the Tree. More... | |
TreeNode const & | root_node () const |
Return the TreeNode at the current root of the Tree. More... | |
void | swap (Tree &other) |
Swap. More... | |
Friends | |
bool | validate_topology (Tree const &tree) |
Validate the correctness of all Tree pointers etc. More... | |
|
default |
|
default |
Copy constructor.
This function creates all links, nodes and edges new, and shapes them so that the final Tree has the same topology as the input Tree.
The data belonging to the edges and nodes is copied using the clone function of the respective data classes for the nodes and edges. As this data might contain pointers and other structures that need a deep copy, it is the responsibility of the clone function of those data classes to make sure its own data is copied correctly.
This function internally uses clone_topology() first, and then uses the clone functions of the data for all nodes and edges.
Definition at line 50 of file tree/tree.cpp.
|
inline |
Definition at line 432 of file tree/tree.hpp.
|
inline |
Definition at line 437 of file tree/tree.hpp.
|
inline |
Definition at line 364 of file tree/tree.hpp.
|
inline |
Definition at line 369 of file tree/tree.hpp.
|
inline |
Definition at line 398 of file tree/tree.hpp.
|
inline |
Definition at line 403 of file tree/tree.hpp.
void clear | ( | ) |
Deletes all data of the tree, including all links, nodes and edges.
This functions results in an empty tree.
Definition at line 172 of file tree/tree.cpp.
Tree clone_topology | ( | ) | const |
Return a Tree with the same topology, but without any data.
All data pointers of the nodes and edges of the returned tree are nullptr
.
Definition at line 109 of file tree/tree.cpp.
|
inline |
Return the TreeEdge at a certain index.
Definition at line 238 of file tree/tree.hpp.
|
inline |
Return the TreeEdge at a certain index.
Definition at line 247 of file tree/tree.hpp.
|
inline |
Return the number of TreeEdges of the Tree.
Definition at line 272 of file tree/tree.hpp.
|
inline |
Definition at line 452 of file tree/tree.hpp.
|
inline |
Definition at line 457 of file tree/tree.hpp.
|
inline |
Return whether the Tree is empty (i.e., has no nodes, edges and links).
Definition at line 194 of file tree/tree.hpp.
|
inline |
Definition at line 442 of file tree/tree.hpp.
|
inline |
Definition at line 447 of file tree/tree.hpp.
|
inline |
Definition at line 374 of file tree/tree.hpp.
|
inline |
Definition at line 379 of file tree/tree.hpp.
|
inline |
Definition at line 408 of file tree/tree.hpp.
|
inline |
Definition at line 413 of file tree/tree.hpp.
Tree::EdgeContainerType & expose_edge_container | ( | ) |
Get the container that stores all TreeEdges of the Tree.
This function gives direct access to the underlying container for the Links. It is meant to be used by external functions that need to manupulate the Tree, e.g., for reading or re-rooting the tree, or for adding elements to it. Use with care!
Definition at line 202 of file tree/tree.cpp.
Tree::LinkContainerType & expose_link_container | ( | ) |
Get the container that stores all TreeLinks of the Tree.
This function gives direct access to the underlying container for the Links. It is meant to be used by external functions that need to manupulate the Tree, e.g., for reading or re-rooting the tree, or for adding elements to it. Use with care!
Definition at line 192 of file tree/tree.cpp.
Tree::NodeContainerType & expose_node_container | ( | ) |
Get the container that stores all TreeNodes of the Tree.
This function gives direct access to the underlying container for the Links. It is meant to be used by external functions that need to manupulate the Tree, e.g., for reading or re-rooting the tree, or for adding elements to it. Use with care!
Definition at line 197 of file tree/tree.cpp.
|
inline |
Return the TreeLink at a certain index.
Definition at line 202 of file tree/tree.hpp.
|
inline |
Return the TreeLink at a certain index.
Definition at line 211 of file tree/tree.hpp.
|
inline |
Return the number of TreeLinks of the Tree.
Definition at line 256 of file tree/tree.hpp.
|
inline |
Definition at line 384 of file tree/tree.hpp.
|
inline |
Definition at line 389 of file tree/tree.hpp.
|
inline |
Return the TreeNode at a certain index.
Definition at line 220 of file tree/tree.hpp.
|
inline |
Return the TreeNode at a certain index.
Definition at line 229 of file tree/tree.hpp.
|
inline |
Return the number of TreeNodes of the Tree.
Definition at line 264 of file tree/tree.hpp.
|
inline |
Definition at line 418 of file tree/tree.hpp.
|
inline |
Definition at line 423 of file tree/tree.hpp.
Assignment operator.
See Tree copy constructor for more information.
Definition at line 96 of file tree/tree.cpp.
Reset the link that is considered to be the root of the Tree.
This function is meant for tree manipulation functions. Use with care!
Caveat: This function simply sets the link, but does not change any other properties of the tree. Particularly the correct primary/secondary order of TreeEdges and primary links of TreeNodes needs to be maintained manually when using this function! Otherwise, we end up with an invalid Tree that breaks its invariants!
Definition at line 184 of file tree/tree.cpp.
|
inline |
Return the TreeLink at the current root of the Tree.
Definition at line 284 of file tree/tree.hpp.
|
inline |
Return the TreeLink at the current root of the Tree.
Definition at line 292 of file tree/tree.hpp.
|
inline |
Return the TreeNode at the current root of the Tree.
Definition at line 300 of file tree/tree.hpp.
|
inline |
Return the TreeNode at the current root of the Tree.
Definition at line 308 of file tree/tree.hpp.
void swap | ( | Tree & | other | ) |
Swap.
Definition at line 161 of file tree/tree.cpp.
|
friend |
Validate the correctness of all Tree pointers etc.
This function is defined in tree/functions/operators.hpp
This check is a bit pedantic, but better safe than sorry.
Definition at line 332 of file tree/function/operators.cpp.
using ConstIteratorEdges = utils::DereferenceIterator< ContainerType<TreeEdge>::const_iterator > |
Definition at line 134 of file tree/tree.hpp.
using ConstIteratorLinks = utils::DereferenceIterator< ContainerType<TreeLink>::const_iterator > |
Definition at line 128 of file tree/tree.hpp.
using ConstIteratorNodes = utils::DereferenceIterator< ContainerType<TreeNode>::const_iterator > |
Definition at line 131 of file tree/tree.hpp.
using ContainerType = std::vector< std::unique_ptr< T > > |
Alias for the container type that is used to store TreeLinks, TreeNodes and TreeEdges.
Definition at line 110 of file tree/tree.hpp.
using EdgeContainerType = ContainerType< TreeEdge > |
Alias for the container type that is used to store TreeEdges.
Definition at line 125 of file tree/tree.hpp.
using IteratorEdges = utils::DereferenceIterator< ContainerType<TreeEdge>::iterator > |
Definition at line 133 of file tree/tree.hpp.
using IteratorLinks = utils::DereferenceIterator< ContainerType<TreeLink>::iterator > |
Definition at line 127 of file tree/tree.hpp.
using IteratorNodes = utils::DereferenceIterator< ContainerType<TreeNode>::iterator > |
Definition at line 130 of file tree/tree.hpp.
using LinkContainerType = ContainerType< TreeLink > |
Alias for the container type that is used to store TreeLinks.
Definition at line 115 of file tree/tree.hpp.
using NodeContainerType = ContainerType< TreeNode > |
Alias for the container type that is used to store TreeNodes.
Definition at line 120 of file tree/tree.hpp.