53 std::function<std::string (
64 auto ranks = std::vector<size_t>( tree.
node_count(), 0 );
67 auto parents = std::vector<size_t>();
74 if( limit_ > 0 && count > limit_ ) {
79 size_t cur_idx = it.node().index();
80 size_t par_idx = it.link().outer().node().index();
83 while (!parents.empty() && parents.back() != par_idx) {
86 parents.push_back(cur_idx);
87 ranks[cur_idx] =
degree( it.node() ) - 1;
91 if (it.is_first_iteration()) {
93 out << print_line( it.node(), it.edge() ) <<
"\n";
101 assert( parents.size() >= 2 );
102 assert( parents[ parents.size() - 2 ] == par_idx );
103 assert( parents[ parents.size() - 1 ] == cur_idx );
107 for (
size_t i = 0; i < parents.size() - 2; ++i) {
108 if (ranks[parents[i]] > 0) {
109 if( limit_ > 0 && count == limit_ ) {
124 assert(ranks[par_idx] > 0);
127 if( limit_ > 0 && count == limit_ ) {
135 if (ranks[par_idx] > 0) {
142 out << print_line( it.node(), it.edge() ) <<
"\n";
151 std::function<std::string (
156 std::ostringstream res;
157 print( res, tree, print_line );
166 if( edge.has_data() ) {
177 return print(tree, print_line);
std::string to_string_nice(T const &v)
Return a string representation of a given value.
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
Class for representing phylogenetic trees.
bool has_data() const
Return true if the TreeNode has a data object assigned to it.
Provides some commonly used string utility functions.
size_t node_count() const
Return the number of TreeNodes of the Tree.
double branch_length
Branch length of the edge.
utils::Range< IteratorPreorder< true > > preorder(ElementType const &element)
Common class containing the commonly needed data for tree nodes.
Common class containing the commonly needed data for tree edges.
size_t degree(TreeLink const &link)
Return the degree of the node for a given TreeLink, i.e. how many neighbouring nodes it has...
void print(std::ostream &out, Tree const &tree, std::function< std::string(TreeNode const &node, TreeEdge const &edge)> const print_line)
Print a compact representation of a Tree to an output stream, using a given function for output of th...