# Getting tree attributes

### Methods on TreeSets

Phylo.ntreesFunction
ntrees(tree::AbstractTree)

Returns the number of trees in a tree object, 1 for a OneTree tree type, and the count of trees for a ManyTrees type.

source
Phylo.nrootsFunction
nroots(::AbstractTree)

Returns the number of roots in a tree. For OneTree types, Unrooted trees will return 0, OneRoot trees should return 1, and manyroots tree (ones with multiple subtrees) will return the number of subtrees. ManyTrees types will return a Dict of counts of the number of roots for each tree in the set.

source
Phylo.getrootsFunction
getroots(::AbstractTree)
getroots(::AbstractTree, id)

Returns a vector containing the root(s) of a single (OneTree) tree or a set of (ManyTrees) trees.

source

### Methods on Trees

Phylo.mrcaFunction
mrca(tree::AbstractTree, target)

Returns the node within tree that is the Most Recent Common Ancestor of the leaves (or internal nodes) defined by target. target can be an iterator over nodes or an AbstractArray of nodes. The return value has the same node type as the elements of target.

Examples

≡≡≡≡≡≡≡≡≡≡≡

julia> tree = open(parsenewick, Phylo.path("H1N1.newick")) RootedTree with 507 tips, 1013 nodes and 1012 branches. Leaf names are 227, 294, 295, 110, 390, ... [501 omitted] ... and 418

julia> tips = rand(collect(nodefilter(isleaf, tree)), 3) 3-element Vector{LinkNode{OneRoot, String, Dict{String, Any}, LinkBranch{OneRoot, String, Dict{String, Any}, Float64}}}: LinkNode 153, a tip of the tree with an incoming connection (branch 888).

LinkNode 120, a tip of the tree with an incoming connection (branch 195).

LinkNode 504, a tip of the tree with an incoming connection (branch 44).

julia> mrca(tree, tips) LinkNode Node 1003, an internal node with 1 inbound and 2 outbound connections (branches 1001 and 999, 1000)

source
Phylo.nodeheightsFunction
nodeheights(tree::Phylo.AbstractTree; onlyleaves = false, noleaves = false)

Returns an AxisArray of the height of all nodes in tree over the root node. onlyleaves and noleaves filter the nodes for leaves and internal nodes, respectively

source
Phylo.getleafnamesFunction
getleafnames(::AbstractTree[, ::TraversalOrder])

Retrieve the leaf names from the tree (in some specific order).

source
Phylo.nnodesFunction
nnodes(::AbstractTree)

Returns the number of nodes of a single tree, or a Dict of numbers of nodes for multiple trees.

source
Phylo.nbranchesFunction
nbranches(::AbstractTree)

Returns the number of branches of a single tree, or a Dict of numbers of branches for multiple trees.

source

### Methods on Nodes

Phylo.isleafFunction
isleaf(tree::AbstractTree, node)

Is the node (referenced by name or node object) a leaf of the tree?

source
Phylo.isrootFunction
isroot(tree::AbstractTree, node)

Is the node (referenced by name or node object) a root of the tree?

source
Phylo.isinternalFunction
isinternal(tree::AbstractTree, node)

Is the node (referenced by name or node object) internal to the tree (neither root nor leaf)?

source
Phylo.isunattachedFunction
isunattached(tree::AbstractTree, node)

Is the node (referenced by name or node object) unattached (i.e. not connected to other nodes)?

source
Phylo.getinboundFunction
getinbound(tree::AbstractTree, node)

return the inbound branch to this node (returns name for node name, branch for node).

source
Phylo.setnodedata!Function
setnodedata!(::AbstractTree, node, label, value)
setnodedata!(::AbstractTree, node, data)

Set the node data for a node of the tree.

source
Phylo.getparentFunction
getparent(tree::AbstractTree, node)

Return [the name of] the parent node for this node [name]. Second method may not be implemented for some node types.

source

### Methods on Branches

Phylo.setbranchdata!Function
setbranchdata!(::AbstractTree, branch, label, value)
setbranchdata!(::AbstractTree, branch, data)

Set the branch data for a branch of the tree.

source
Phylo.getrootFunction
getroot(::AbstractTree)

Returns the root of a single tree (must be only one tree for a ManyTrees tree).

source
Phylo.roottypeFunction
roottype(::Type{AbstractTree})
roottype(::Type{AbstractNode})
roottype(::Type{AbstractBranch})

Returns root type from a tree type.

source
Phylo.nodenametypeFunction
nodenametype(::Type{AbstractTree})
nodenametype(::Type{AbstractNode})
nodenametype(::Type{AbstractBranch})

Returns type of node names from a tree type.

source
Phylo.getnodenamesFunction
getnodenames(::AbstractTree[, ::TraversalOrder])

Return a vector of node names of a single tree (identified by id for a ManyTrees tree), or a Dict of vectors of node names for multiple trees.

source
Phylo.getnodenameFunction
getnodename(::AbstractTree, node)

Returns the node name associated with a node from a tree. For some node types, it will be able to extract the node name without reference to the tree.

source
Phylo.hasnodeFunction
hasnode(tree::AbstractTree, node)

Returns whether a tree has a given node (or node name) or not.

source
Phylo.getnodesFunction
getnodes(::AbstractTree[, ::TraversalOrder])

Returns the vector of nodes of a single tree, or a Dict of vectors of nodes for multiple trees.

source
Phylo.getbranchnamesFunction
getbranchnames(tree::AbstractTree)

Return a vector of branch names of a single tree, or a Dict of vectors of branch names for multiple trees.

source
Phylo.getbranchnameFunction
getbranchname(::AbstractTree, branch)
getbranchname(branch)

Returns the branch name associated with a branch from a tree. For some branch types, it will be able to extract the branch name without reference to the tree.

source
Phylo.hasbranchFunction
hasbranch(tree::AbstractTree, branch)
hasbranch(tree::AbstractTree, source, dest)

Does tree have a branch branch or a branch from source to dest?

source
Phylo.getbranchFunction
getbranch(tree::AbstractTree, branch)
getbranch(tree::AbstractTree, source, dest)

Returns a branch from a tree by name or by source and destination node.

source
Phylo.getbranchesFunction
getbranches(::AbstractTree)

Returns the vector of branches of a single tree, or a Dict of vectors of branches for multiple trees.

source