|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
55 std::function< std::unique_ptr<BaseNodeData>(
BaseNodeData const& node_data )> node_data_converter,
56 std::function< std::unique_ptr<BaseEdgeData>(
BaseEdgeData const& edge_data )> edge_data_converter
62 for(
size_t i = 0; i < res.node_count(); ++i ) {
67 for(
size_t i = 0; i < res.edge_count(); ++i ) {
103 !node_comparator( it_l.node(), it_r.node() ) ||
104 !edge_comparator( it_l.edge(), it_r.edge() )
119 std::vector<Tree>
const& trees,
130 #pragma omp parallel for
131 for (
size_t i = 1; i < trees.size(); i++) {
136 if( !
equal( trees[i-1], trees[i], node_comparator, edge_comparator )) {
171 auto node_comparator = [ &identical_indices ] (
175 if( identical_indices && node_l.
index() != node_r.index() ) {
181 auto edge_comparator = [ &identical_indices ] (
185 if( identical_indices && edge_l.
index() != edge_r.index() ) {
191 return equal( lhs, rhs, node_comparator, edge_comparator );
203 #pragma omp parallel for
204 for (
size_t i = 1; i < trees.size(); i++) {
265 if( &it.link().outer().node() == &rhs ) {
266 return &it.link().edge();
277 if( &it.link().outer().node() == &rhs ) {
278 return &it.link().edge();
290 return "<genesis::tree::Tree"
299 return "<genesis::tree::TreeEdge"
301 " has_data=" + ( edge.
has_data() ?
"true" :
"false" ) +
307 return "<genesis::tree::TreeLink"
315 return "<genesis::tree::TreeNode"
317 " has_data=" + ( node.
has_data() ?
"true" :
"false" ) +
325 return pc.print( tree );
341 if (tree.links_.empty() || tree.nodes_.empty() || tree.edges_.empty()) {
342 bool empty = tree.links_.empty() && tree.nodes_.empty() && tree.edges_.empty();
344 LOG_INFO <<
"Tree is not empty, but one of its data members is.";
354 std::vector<size_t> links_to_edges(tree.edges_.size(), 0);
355 std::vector<size_t> links_to_nodes(tree.nodes_.size(), 0);
356 for (
size_t i = 0; i < tree.links_.size(); ++i) {
359 LOG_INFO <<
"Link at index " << i <<
" has wrong index ("
365 auto nl = tree.links_[i].get();
367 if( &nl->node() != &tree.links_[i]->node() ) {
368 LOG_INFO <<
"Link at index " << nl->index() <<
" points to wrong node.";
372 }
while(nl != tree.links_[i].get());
373 ++links_to_nodes[tree.links_[i]->node().index()];
376 if( &tree.links_[i]->outer().outer() != tree.links_[i].get() ) {
377 LOG_INFO <<
"Link at index " << i <<
" has wrong outer link.";
382 auto edge = &tree.links_[i]->edge();
384 &edge->primary_link() != tree.links_[i].get() &&
385 &edge->secondary_link() != tree.links_[i].get()
387 LOG_INFO <<
"Link at index " << i <<
" has wrong edge pointer.";
390 ++links_to_edges[tree.links_[i]->edge().index()];
394 for (
size_t i = 0; i < tree.edges_.size(); ++i) {
395 if (links_to_edges[i] != 2) {
396 LOG_INFO <<
"Edge at index " << i <<
" is not visited twice but " << links_to_edges[i]
397 <<
" times when traversing the links.";
403 for (
size_t i = 0; i < tree.nodes_.size(); ++i) {
404 if (links_to_nodes[i] !=
degree( *tree.nodes_[i] ) ) {
405 LOG_INFO <<
"Node at index " << i <<
" is not visited its degree ("
406 <<
degree( *tree.nodes_[i] )
407 <<
") times, but " << links_to_nodes[i] <<
" times when "
408 <<
"traversing the links.";
418 for (
size_t i = 0; i < tree.nodes_.size(); ++i) {
421 LOG_INFO <<
"Node at index " << i <<
" has wrong index ("
427 if( &tree.nodes_[i]->link().node() != tree.nodes_[i].get() ) {
428 LOG_INFO <<
"Node at index " << i <<
" has wrong link.";
434 LOG_INFO <<
"Node at index " << i <<
" has is_root(), but it is not tree.root_node().";
443 LOG_INFO <<
"Node at " << i <<
" (not the root node) has a primary link which is not "
444 <<
"the secondary link of its edge.";
452 root_l = &( root_l->outer().node().primary_link() );
458 LOG_INFO <<
"Node at " << i <<
" and the nodes towards the root contain "
459 <<
"a primary link which is not pointing towards the root.";
470 for (
size_t i = 0; i < tree.edges_.size(); ++i) {
473 LOG_INFO <<
"Edge at index " << i <<
" has wrong index ("
479 if( &tree.edges_[i]->primary_link().edge() != tree.edges_[i].get() ) {
480 LOG_INFO <<
"Edge at index " << i <<
" has wrong primary link.";
483 if( &tree.edges_[i]->secondary_link().edge() != tree.edges_[i].get() ) {
484 LOG_INFO <<
"Edge at index " << i <<
" has wrong secondary link.";
489 if( &tree.edges_[i]->primary_link().outer() != &tree.edges_[i]->secondary_link() ) {
490 LOG_INFO <<
"Edge at index " << i <<
" has a primary link that does not "
491 <<
"connect to its secondary link.";
494 if( &tree.edges_[i]->secondary_link().outer() != &tree.edges_[i]->primary_link() ) {
495 LOG_INFO <<
"Edge at index " << i <<
" has a secondary link that does not "
496 <<
"connect to its primary link.";
504 LOG_INFO <<
"Edge at " << i <<
" has a primary node that does not "
505 <<
"point towards the root.";
511 LOG_INFO <<
"Edge at " << i <<
" has a secondary node that does not "
512 <<
"point towards the root.";
520 root_l = &( root_l->node().primary_link().edge().primary_link() );
526 LOG_INFO <<
"Edge at " << i <<
" and the nodes towards the root contain "
527 <<
"a primary link which is not pointing towards the root.";
541 std::vector<size_t> it_links(tree.links_.size(), 0);
542 std::vector<size_t> it_edges(tree.edges_.size(), 0);
543 std::vector<size_t> it_nodes(tree.nodes_.size(), 0);
547 auto link = tree.links_.front().get();
549 ++it_links[ link->index() ];
550 ++it_edges[ link->edge().index() ];
551 ++it_nodes[ link->node().index() ];
552 link = &link->next().outer();
555 if( it_links[ link->index() ] > 1 ) {
556 LOG_INFO <<
"Loop or other kind of wrong link chain in Tree.";
559 }
while (link != tree.links_.front().get());
562 for (
size_t i = 0; i < tree.links_.size(); i++) {
563 if (it_links[i] != 1) {
564 LOG_INFO <<
"Link at index " << i <<
" is not visited 1 but " << it_links[i]
565 <<
" times when iterating the tree.";
571 for (
size_t i = 0; i < tree.edges_.size(); ++i) {
572 if (it_edges[i] != 2) {
573 LOG_INFO <<
"Edge at index " << i <<
" is not visited 2 but " << it_edges[i]
574 <<
" times when iterating the tree.";
580 for (
size_t i = 0; i < tree.nodes_.size(); ++i) {
581 if (it_nodes[i] !=
degree( *tree.nodes_[i] ) ) {
582 LOG_INFO <<
"Node at index " << i <<
" is not visited "
583 <<
degree( *tree.nodes_[i] )
584 <<
" times, but " << it_nodes[i] <<
" times when iterating the "
597 if( &( rl->edge().primary_link() ) != rl ) {
598 LOG_INFO <<
"Root node of the tree is not root in the topology.";
601 rl = &( rl->next() );
606 LOG_INFO <<
"Tree root link is not the primary link of its node.";
612 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.
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.
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.