|
A library for working with phylogenetic and population genetic data.
v0.27.0
|
|
Go to the documentation of this file.
56 std::function< std::unique_ptr<BaseNodeData>(
BaseNodeData const& node_data )> node_data_converter,
57 std::function< std::unique_ptr<BaseEdgeData>(
BaseEdgeData const& edge_data )> edge_data_converter
63 for(
size_t i = 0; i < res.node_count(); ++i ) {
68 for(
size_t i = 0; i < res.edge_count(); ++i ) {
104 !node_comparator( it_l.node(), it_r.node() ) ||
105 !edge_comparator( it_l.edge(), it_r.edge() )
120 std::vector<Tree>
const& trees,
131 #pragma omp parallel for
132 for (
size_t i = 1; i < trees.size(); i++) {
137 if( !
equal( trees[i-1], trees[i], node_comparator, edge_comparator )) {
172 auto node_comparator = [ &identical_indices ] (
176 if( identical_indices && node_l.
index() != node_r.index() ) {
182 auto edge_comparator = [ &identical_indices ] (
186 if( identical_indices && edge_l.
index() != edge_r.index() ) {
192 return equal( lhs, rhs, node_comparator, edge_comparator );
204 #pragma omp parallel for
205 for (
size_t i = 1; i < trees.size(); i++) {
266 if( &it.link().outer().node() == &rhs ) {
267 return &it.link().edge();
278 if( &it.link().outer().node() == &rhs ) {
279 return &it.link().edge();
291 return "<genesis::tree::Tree"
300 return "<genesis::tree::TreeEdge"
302 " has_data=" + ( edge.
has_data() ?
"true" :
"false" ) +
308 return "<genesis::tree::TreeLink"
316 return "<genesis::tree::TreeNode"
318 " has_data=" + ( node.
has_data() ?
"true" :
"false" ) +
326 return pc.print( tree );
375 if (tree.links_.empty() || tree.nodes_.empty() || tree.edges_.empty()) {
376 bool empty = tree.links_.empty() && tree.nodes_.empty() && tree.edges_.empty();
378 LOG_INFO <<
"Tree is not empty, but one of its data members is.";
388 std::vector<size_t> links_to_edges(tree.edges_.size(), 0);
389 std::vector<size_t> links_to_nodes(tree.nodes_.size(), 0);
390 for (
size_t i = 0; i < tree.links_.size(); ++i) {
393 LOG_INFO <<
"Link at index " << i <<
" has wrong index ("
399 auto nl = tree.links_[i].get();
401 if( &nl->node() != &tree.links_[i]->node() ) {
402 LOG_INFO <<
"Link at index " << nl->index() <<
" points to wrong node.";
406 }
while(nl != tree.links_[i].get());
407 ++links_to_nodes[tree.links_[i]->node().index()];
410 if( &tree.links_[i]->outer().outer() != tree.links_[i].get() ) {
411 LOG_INFO <<
"Link at index " << i <<
" has wrong outer link.";
416 auto edge = &tree.links_[i]->edge();
418 &edge->primary_link() != tree.links_[i].get() &&
419 &edge->secondary_link() != tree.links_[i].get()
421 LOG_INFO <<
"Link at index " << i <<
" has wrong edge pointer.";
424 ++links_to_edges[tree.links_[i]->edge().index()];
428 for (
size_t i = 0; i < tree.edges_.size(); ++i) {
429 if (links_to_edges[i] != 2) {
430 LOG_INFO <<
"Edge at index " << i <<
" is not visited twice but " << links_to_edges[i]
431 <<
" times when traversing the links.";
437 for (
size_t i = 0; i < tree.nodes_.size(); ++i) {
438 if (links_to_nodes[i] !=
degree( *tree.nodes_[i] ) ) {
439 LOG_INFO <<
"Node at index " << i <<
" is not visited its degree ("
440 <<
degree( *tree.nodes_[i] )
441 <<
") times, but " << links_to_nodes[i] <<
" times when "
442 <<
"traversing the links.";
452 for (
size_t i = 0; i < tree.nodes_.size(); ++i) {
455 LOG_INFO <<
"Node at index " << i <<
" has wrong index ("
461 if( &tree.nodes_[i]->link().node() != tree.nodes_[i].get() ) {
462 LOG_INFO <<
"Node at index " << i <<
" has wrong link.";
468 LOG_INFO <<
"Node at index " << i <<
" has is_root(), but it is not tree.root_node().";
477 LOG_INFO <<
"Node at " << i <<
" (not the root node) has a primary link which is not "
478 <<
"the secondary link of its edge.";
486 root_l = &( root_l->outer().node().primary_link() );
492 LOG_INFO <<
"Node at " << i <<
" and the nodes towards the root contain "
493 <<
"a primary link which is not pointing towards the root.";
504 for (
size_t i = 0; i < tree.edges_.size(); ++i) {
507 LOG_INFO <<
"Edge at index " << i <<
" has wrong index ("
513 if( &tree.edges_[i]->primary_link().edge() != tree.edges_[i].get() ) {
514 LOG_INFO <<
"Edge at index " << i <<
" has wrong primary link.";
517 if( &tree.edges_[i]->secondary_link().edge() != tree.edges_[i].get() ) {
518 LOG_INFO <<
"Edge at index " << i <<
" has wrong secondary link.";
523 if( &tree.edges_[i]->primary_link().outer() != &tree.edges_[i]->secondary_link() ) {
524 LOG_INFO <<
"Edge at index " << i <<
" has a primary link that does not "
525 <<
"connect to its secondary link.";
528 if( &tree.edges_[i]->secondary_link().outer() != &tree.edges_[i]->primary_link() ) {
529 LOG_INFO <<
"Edge at index " << i <<
" has a secondary link that does not "
530 <<
"connect to its primary link.";
538 LOG_INFO <<
"Edge at " << i <<
" has a primary node that does not "
539 <<
"point towards the root.";
545 LOG_INFO <<
"Edge at " << i <<
" has a secondary node that does not "
546 <<
"point towards the root.";
554 root_l = &( root_l->node().primary_link().edge().primary_link() );
560 LOG_INFO <<
"Edge at " << i <<
" and the nodes towards the root contain "
561 <<
"a primary link which is not pointing towards the root.";
575 std::vector<size_t> it_links(tree.links_.size(), 0);
576 std::vector<size_t> it_edges(tree.edges_.size(), 0);
577 std::vector<size_t> it_nodes(tree.nodes_.size(), 0);
581 auto link = tree.links_.front().get();
583 ++it_links[ link->index() ];
584 ++it_edges[ link->edge().index() ];
585 ++it_nodes[ link->node().index() ];
586 link = &link->next().outer();
589 if( it_links[ link->index() ] > 1 ) {
590 LOG_INFO <<
"Loop or other kind of wrong link chain in Tree.";
593 }
while (link != tree.links_.front().get());
596 for (
size_t i = 0; i < tree.links_.size(); i++) {
597 if (it_links[i] != 1) {
598 LOG_INFO <<
"Link at index " << i <<
" is not visited 1 but " << it_links[i]
599 <<
" times when iterating the tree.";
605 for (
size_t i = 0; i < tree.edges_.size(); ++i) {
606 if (it_edges[i] != 2) {
607 LOG_INFO <<
"Edge at index " << i <<
" is not visited 2 but " << it_edges[i]
608 <<
" times when iterating the tree.";
614 for (
size_t i = 0; i < tree.nodes_.size(); ++i) {
615 if (it_nodes[i] !=
degree( *tree.nodes_[i] ) ) {
616 LOG_INFO <<
"Node at index " << i <<
" is not visited "
617 <<
degree( *tree.nodes_[i] )
618 <<
" times, but " << it_nodes[i] <<
" times when iterating the "
631 if( &( rl->edge().primary_link() ) != rl ) {
632 LOG_INFO <<
"Root node of the tree is not root in the topology.";
635 rl = &( rl->next() );
640 LOG_INFO <<
"Tree root link is not the primary link of its node.";
646 LOG_INFO <<
"Root node is not true in is_root().";
#define LOG_INFO
Log an info message. See genesis::utils::LoggingLevel.
TreeLink & primary_link()
Return the TreeLink of this TreeEdge that points towards the root.
Tree convert(Tree const &source, std::function< std::unique_ptr< BaseNodeData >(BaseNodeData const &node_data)> node_data_converter, std::function< std::unique_ptr< BaseEdgeData >(BaseEdgeData const &edge_data)> edge_data_converter)
Create a tree with the same topology as the source tree, while converting its data.
TreeLink const & link() const
Get the TreeLink that separates the subtree from the rest of the tree.
size_t node_count() const
Return the number of TreeNodes of the Tree.
bool has_data() const
Return true if the TreeEdge has a data object assigned to it.
size_t link_count() const
Return the number of TreeLinks of the Tree.
Print a Tree in a compact form, i.e., each node and edge on one line.
std::string print_gist(Tree const &tree, long items)
size_t index() const
Return the index of this Link.
TreeLink & next()
Return the next TreeLink within the TreeNode of this link.
TreeNode & node()
Return the TreeNode of this TreeLink.
std::string print_info(Tree const &tree)
size_t index() const
Return the index of this Edge.
Base class for storing data on Edges of a Tree.
TreeNode & node_at(size_t index)
Return the TreeNode at a certain index.
TreeEdge & edge_at(size_t index)
Return the TreeEdge at a certain index.
utils::Range< IteratorPreorder< true > > preorder(ElementType const &element)
bool belongs_to(Tree const &tree, TreeNode const &node)
Return whether the TreeNode belongs to the Tree, i.e., whether it is owned by the Tree.
utils::Range< IteratorNodeLinks< true > > node_links(ElementType const &element)
size_t degree(TreeLink const &link)
Return the degree of the node for a given TreeLink, i.e. how many neighbouring nodes it has.
TreeNode & root_node()
Return the TreeNode at the current root of the Tree.
bool identical_topology(Tree const &lhs, Tree const &rhs, bool identical_indices)
Return whether both trees have an identical topology.
bool equal(Tree const &lhs, Tree const &rhs, std::function< bool(TreeNode const &, TreeNode const &) > node_comparator, std::function< bool(TreeEdge const &, TreeEdge const &) > edge_comparator)
Compare two trees for equality given binary comparator functionals for their nodes and edges.
TreeNode & secondary_node()
Return the TreeNode of this TreeEdge that points away from the root.
std::string to_string(GenomeLocus const &locus)
TreeLink & primary_link()
Return the TreeLink that points towards the root.
TreeEdge * edge_between(TreeNode &lhs, TreeNode &rhs)
Return the TreeEdge between two TreeNode&s, if they are neighbours, or nullptr otherwise.
Class for representing phylogenetic trees.
Provides easy and fast logging functionality.
bool has_data() const
Return true if the TreeNode has a data object assigned to it.
bool is_root(TreeLink const &link)
Return whether the link belongs to the root node of its Tree.
TreeLink & root_link()
Return the TreeLink at the current root of the Tree.
Reference to a subtree of a Tree.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
TreeLink & link()
Return the TreeLink that points towards the root.
std::ostream & operator<<(std::ostream &out, Tree const &tree)
Base class for storing data on Nodes of a Tree.
TreeNode & primary_node()
Return the TreeNode of this TreeEdge that points towards the root.
BaseEdgeData * data_ptr()
Return a pointer to the data.
Tree clone_topology() const
Return a Tree with the same topology, but without any data.
TreeNode & reset_data(std::unique_ptr< BaseNodeData > data)
Reset the data pointer of this TreeNode.
TreeLink & link_at(size_t index)
Return the TreeLink at a certain index.
size_t index() const
Return the index of this Node.
static Options & get()
Returns a single instance of this class.
TreeEdge & edge()
Return the TreeEdge of this TreeLink.
BaseNodeData * data_ptr()
Return a pointer to the data.
bool validate_topology(Tree const &tree)
Validate that all internal pointers of the Tree elements (TreeLinks, TreeNodes, TreeEdges) to each ot...
TreeLink & secondary_link()
Return the TreeLink of this TreeEdge that points away from the root.
size_t edge_count() const
Return the number of TreeEdges of the Tree.