Basics

This section provides an overview over the basic functionalities offered.

When building / modifying trees with methods like add_child! or insert_node!, it might be necessarry to run initialize_tree! or update_tree! to ensure the nodes remain /are initialized.

WARNING: Do not run initialize_tree! after changing a tree, if you rely on the num field of the nodes to identify them. The same applies to the method number_nodes that is called in initalize_tree.

Basic Tree Functionalities

MCPhyloTree.add_child!Method
function add_child!(mother_node::N, child::N, child_position::Int64)::Nothing where N <: GeneralNode

This function adds a child to the mother node. The arity of the mother node is increased by 1 and the root status of the child is set to False.

  • mother_node : Node to add a child to.

  • child : Node to add to mother_node.children.

  • child_position : index at which to add the new child node.

source
MCPhyloTree.add_child!Method
add_child!(mother_node::N, child::N)::Nothing where N <: GeneralNode

This function adds a child to the mother node. The arity of the mother node is increased by 1 and the root status of the child is set to False.

  • mother_node : Node to add a child to.

  • child : Node to add to mother_node.children.

source
MCPhyloTree.check_binaryMethod
check_binary(root::AbstractNode)::Bool

checks to see if given tree is binary; returns true if properly formatted and false otherwise

source
MCPhyloTree.check_leafsetsMethod
check_leafsets(trees::Vector{T})::Nothing where T<:AbstractNode

Checks if an array of trees shares the same leafset (based on the leaf names)

source
MCPhyloTree.delete_node!Method
delete_node!(node::T)::Nothing where T<:AbstractNode

This functions deletes node from a tree and assigns all its children to its mother node.

  • node : Node to be deleted.
source
MCPhyloTree.get_motherMethod
get_mother(node::T)::T  where T<:AbstractNode

This function gets the mother of node. It does so by looking for the respective binary representation of the mother node.

source
MCPhyloTree.get_sisterMethod
get_sister(node::T)::T  where T<:AbstractNode

This function gets the sister of node. It does so by looking for the respective binary representation of the sister.

source
MCPhyloTree.get_sum_seperate_length!Method
get_sum_seperate_length!(post_order::Vector{T})::Vector{Float64}  where T<:AbstractNode

This function gets the sum of the branch lengths of the internal branches and the branches leading to the leave nodes.

source
MCPhyloTree.initialize_tree!Method
initialize_tree!(root::GeneralNode; height::Bool=true)

This function initializes a tree, i.e. numbers its nodes and sets the binary + height fields.

source
MCPhyloTree.insert_node!Method
insert_node!(mother::T, children::Vector{T})::T where T<:AbstractNode

This function inserts a node into a tree after a mother node and gains a subset of the mother's children as its children.

Returns the inserted node.

  • mother : Node under which to add the newly-inserted node.

  • children : Children of node referenced by "mother" to reassign as children of the newly-inserted node.

source
MCPhyloTree.node_ageMethod
function node_age(node<:AbstractNode)::Float64

Calculates the age of a node. If the tree is ultrametric then the node age is identical to the node height. It is calculated by subtracting the path length between the node & the root from the height of the root. This represents the age of the node, assuming the leaf farthest from the root has a node age of 0, and the root node is the 'oldest' node.

source
MCPhyloTree.number_nodes!Method
number_nodes!(root::T)::Nothing  where T<:AbstractNode

This function assigns a unique, sequential number to each node. Leaves are numbered first in alphabetical order.

source
MCPhyloTree.path_lengthMethod
path_length(ancestor::T, descendant::T)::Float64  where T<:AbstractNode

Note: The function assumes there is an ancestral relationship between the two nodes.

This function calculates the length of the path separating the ancestor from the offspring node. The function follows the path specified through the binary description of the node.

source
MCPhyloTree.remove_child!Method
remove_child!(mother_node::N, left::Bool)::N where N <: GeneralNode

This function removes a child from the list of nodes which are daughters of this node. An input of "True" removes the left child, while "False" removes the right child.

Returns the removed node.

  • mother_node : Node from which to remove a child.

  • left : boolean value determining which child of mother_node to remove.

source
MCPhyloTree.remove_child!Method
remove_child!(mother_node::N, child::N)::N where N<:AbstractNode

This function removes a child from the list of nodes which are daughters of this node.

The removed node is returned.

  • mother_node : Node from which to remove a child.

  • child : specific Node to remove. This node has to be a child of mother_node.

source
MCPhyloTree.set_binary!Method
set_binary!(root::T)  where T <: GeneralNode

Assign a binary representation to each node, which specifies the path from the root to this node via the binary representation of the node. A left turn is a 1 in binary and a right turn a 0.

source
MCPhyloTree.set_branchlength_vector!Method
set_branchlength_vector!(root::N, blenvec::Array{T}) where {N<:AbstractNode, T<:Real}

This function sets the branch lengths of a tree to the values specified in blenvec.

source
MCPhyloTree.tree_lengthMethod
tree_length(root::T, tl::Float64)::Float64 where T<:AbstractNode

This function does the internal tree length recursion

source
MCPhyloTree.update_tree!Method
update_tree!(root::GeneralNode)

This function can be used to recompute the tree's binary and height values. This might be necessary after adding/moving/removing nodes.

source

Tree Pruning

MCPhyloTree.prune_tree!Method
prune_tree!(root::T, node_names::Vector{String})::Nothing where T<:AbstractNode

In-place version of prune_tree.

  • root : root Node of tree to prune.

  • node_names : vector of strings, used to specify nodes to remove.

source
MCPhyloTree.prune_tree!Method
prune_tree!(root::T, node_names::Vector{T})::Nothing where T<:AbstractNode

In-place version of prune_tree.

  • root : root node of tree to prune.

  • node_names: vector of Node objects to be removed from tree.

source
MCPhyloTree.prune_treeMethod
prune_tree(root::T, node_names::Vector{String})::T where T<:AbstractNode

This function removes specific nodes, including their descendants, from a tree.

  • root : root Node of tree to prune.

  • node_names : vector of strings, used to specify nodes to remove.

source
MCPhyloTree.find_binaryMethod
find_binary(root::T, bin::String)::T where T<:AbstractNode

Find a node by its binary representation. The function assumes that the node is present in the tree.

Do not use this function if you are unsure whether the node is in the tree at all.

Returns a reference to the desired Node.

  • root : root Node of tree to search.

  • bin : binary representation of desired Node as a String.

source
MCPhyloTree.find_nameMethod
find_name(root::T, name::S, rn::Vector{T})::Bool where {T<:AbstractNode, S<:AbstractString}

Do a post order traversal to find the node corresponding to the name.

Returns true if node is found, false otherwise. Desired Node is pushed to rn.

  • root : root Node of tree to be searched.

  • name : name of desired Node.

  • rn : Vector of Nodes; desired Node is pushed to this vector when found.

source
MCPhyloTree.find_nameMethod
find_name(root::T, name::S)::T  where {T<:AbstractNode, S<:AbstractString}

Find a node by its name. Returns reference to Node.

  • root : root Node of tree to be searched.

  • name : name of desired Node.

source
MCPhyloTree.find_numMethod
find_num(root::T, num::Int64, rn::Vector{T})::Bool  where T<:AbstractNode

Do a post order traversal to find the node corresponding to the num.

Returns true if node is found, false otherwise. Desired Node is pushed to rn.

  • root : root Node of tree to be searched.

  • num : number of desired Node.

  • rn : Vector of Nodes; desired Node is pushed to this vector when found.

source
MCPhyloTree.find_numMethod
find_num(root::T, num::Int64)  where T<:AbstractNode

Find a node by its number. The function assumes that the node is present in the tree.

Do not use this function if you are unsure whether the node is in the tree at all.

Returns reference to Node.

  • root : root Node of tree to be searched.

  • num : number of desired Node.

source
MCPhyloTree.find_rootMethod
find_root(node::T)::T where T <: GeneralNode

Finds the root of tree indicated by Node.

Returns reference to root Node of the tree.

  • node : Node in Tree of interest.
source

Tree Traversal

MCPhyloTree.get_leavesMethod
get_leaves(root::T) where T<:AbstractNode

This function returns the leaves of a tree. Only the root node needs to be supplied.

Returns an Iterator over leaf Nodes.

  • root : root Node of tree.
source
MCPhyloTree.level_orderMethod
level_order(node::T) where T<:GeneralNode

This function does level order traversal. Only the root node needs to be supplied.

Returns a level order iterator.

  • node : root Node of tree.
source
MCPhyloTree.post_orderMethod
post_order(root::T) where T<:GeneralNode

This function does post order traversal. Only the root node needs to be supplied.

Returns a post order iterator.

  • root : root Node of tree.
source
MCPhyloTree.pre_orderMethod
pre_order(root::T) where T<:GeneralNode

This function does pre order traversal. Only the root node needs to be supplied.

Returns a preoder Iterator.

  • root : root Node of tree.
source

Tree Representations

MCPhyloTree.newickMethod
newick(root::T)::String  where T<:AbstractNode

Creates a newick representation of the tree.

Returns a properly formatted newick String.

  • node : root node of tree used to create the newick string.
source