Traversing and iterating over trees

The code also provides iterators, and filtered iterators over the branches, nodes, branchnames and nodenames of a tree (using the random tree from Creating phylogenies)

using Phylo
nu = Nonultrametric(5);
tree = rand(nu)

collect(nodeiter(tree))
9-element Vector{LinkNode{OneRoot, String, Dict{String, Any}, LinkBranch{OneRoot, String, Dict{String, Any}, Float64}}}:
 LinkNode tip 1, a tip of the tree with an incoming connection (branch 12).

 LinkNode tip 2, a tip of the tree with an incoming connection (branch 11).

 LinkNode tip 3, a tip of the tree with an incoming connection (branch 14).

 LinkNode tip 4, a tip of the tree with an incoming connection (branch 9).

 LinkNode tip 5, a tip of the tree with an incoming connection (branch 10).

 LinkNode Node 6, an internal node with 1 inbound and 2 outbound connections (branches 13 and 9, 10)

 LinkNode Node 7, an internal node with 1 inbound and 2 outbound connections (branches 15 and 11, 12)

 LinkNode Node 8, an internal node with 1 inbound and 2 outbound connections (branches 16 and 13, 14)

 LinkNode Node 9, a root node with 2 outbound connections (branches 15, 16)
collect(nodenamefilter(isroot, tree))
1-element Vector{String}:
 "Node 9"

TreeSets are iterators themselves

trees = rand(nu, ["Tree 1", "Tree 2"])
collect(trees)
2-element Vector{RootedTree}:
 RootedTree with 5 tips, 9 nodes and 8 branches.
Leaf names are tip 2, tip 3, tip 1, tip 4 and tip 5

 RootedTree with 5 tips, 9 nodes and 8 branches.
Leaf names are tip 2, tip 3, tip 1, tip 4 and tip 5
Phylo.nodeiterFunction
nodeiter(tree::AbstractTree)

Returns an iterator over the nodes of any tree.

source
Phylo.nodefilterFunction
nodefilter(filterfn::Function, tree::AbstractTree)

Returns an iterator over the nodes of any tree, where the AbstractNode is filtered by the function filterfn.

source
Phylo.nodenameiterFunction
nodenameiter(tree::AbstractTree)

Returns an iterator over the names of the nodes of any tree.

source
Phylo.nodenamefilterFunction
nodenamefilter(filterfn::Function, tree::AbstractTree)

Returns an iterator over the nodenames of any tree, where the AbstractNode itself is filtered by the function filterfn.

source
Phylo.branchiterFunction
branchiter(tree::AbstractTree)

Returns an iterator over the branches of any tree.

source
Phylo.branchfilterFunction
branchfilter(filterfn::Function, tree::AbstractTree)

Returns an iterator over the branches of any tree, where the AbstractBranch is filtered by the function filterfn.

source
Phylo.branchnameiterFunction
branchnameiter(tree::AbstractTree)

Returns an iterator over the names of branches of any tree.

source
Phylo.branchnamefilterFunction
branchnamefilter(filterfn::Function, tree::AbstractTree)

Returns an iterator over the names of the branches of any tree, where the AbstractBranch is filtered by the function filterfn.

source
Phylo.traversalFunction
traversal(::AbstractTree, ::TraversalOrder)
traversal(::AbstractTree, ::TraversalOrder, init)

Return an iterable object for a tree containing nodes in given order - preorder, inorder, postorder or breadthfirst - optionally starting from init.

source