Moves
There are several operations to change the topology or any of the branch lengths of a tree. The different functions which are available in MCPhyloTree are listed here.
While the tree building methods in this package are generally built in a way that ensures that the nodes of the tree are fully initialized, i.e. they have a unique number, binary representation and a height, the move methods listed here do not automatically update these fields. After using these methods you might want 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.
Edge Length
MCPhyloTree.change_edge_length!
— Methodchange_edge_length!(root::T) where T <:AbstractNode
Pick a random node and increase or decrease its length randomly.
root
: root node of tree.
MCPhyloTree.move!
— Methodmove!(node1::T, node2::T, proportion::Float64) where T <:AbstractNode
Change the incoming length of node1 and node2 while keeping their combined length constant.
node1
: Node whose inc_length will be modified; this node's inc_length will be the total inc_length of both nodes, times proportion.node2
: Node whose inc_length will be modified; this node's inc_length will be the remainder of total - the new inc_length value of node1.proportion
: Float64, determines proportion of the inc_length of both nodes assigned to node1.
MCPhyloTree.slide!
— Methodslide!(root::T) where T<:AbstractNode
This function performs a slide move on an intermediate node. The node is moved upwards or downwards on the path specified by its mother and one of its daughters.
root
: root Node of tree.
MCPhyloTree.slide
— Methodslide(root::T)::T where T<:AbstractNode
This function performs a slide move on an intermediate node. The node is moved upwards or downwards on the path specified by its mother and one of its daughters.
Returns root Node of new tree.
root
: root Node of tree.
MCPhyloTree.swing!
— Methodswing!(root::T) where T<:AbstractNode
This function performs a swing node. A random non-leave node is selected and moved along the path specified by its two children.
root
: root Node of tree.
MCPhyloTree.swing
— Methodswing(root::T)::T where T<:AbstractNode
This function performs a swing node. A random non-leave node is selected and moved along the path specified by its two children.
Returns root Node of new tree.
root
: root Node of tree.
NNI
MCPhyloTree.NNI!
— MethodNNI!(root::T)::Int64 where T<:AbstractNode
This function does a nearest neighbour interchange (NNI) move on the tree specified by root
. The target is identified by the number of the target node.
The function returns 1 if the move was successful and 0 else.
root
: root node of tree on which to perform the NNI.
MCPhyloTree.NNI!
— MethodNNI!(root::T, target::Int64)::Int64 where T<:AbstractNode
This function does a nearest neighbour interchange (NNI) move on the tree specified by root
. The target is identified by the number of the target node.
The function returns 1 if the move was successful and 0 else.
root
: root node of tree on which to perform the NNI.target
: specific node of tree to interchange.
MCPhyloTree.NNI!
— MethodNNI!(root::T, target::Int64)::Int64 where T<:AbstractNode
This function does a nearest neighbour interchange (NNI) move on the tree specified by root
. The target is identified by the number of the target node. The function returns 1 if the move was successfull and 0 else.
MCPhyloTree.NNI!
— MethodNNI(root::T, target::T, lor::Bool)::Int64 where T<:AbstractNode
This function does a nearest neighbour interchange (NNI) move on the tree specified by root
. The parameter target
specifies the node which performs the interchange move using the left or right child of the target node. If the left child should be used lor=true
.
The function returns 1 if the move was successful and 0 else.
root
: root node of tree on which to perform the NNI.target
: specific node of tree to interchange.lor
: Bool; "true" uses the left child oftarget,
"false," the right child.
MCPhyloTree.NNI
— MethodNNI(root::T)::T where T<:AbstractNode
This function does a nearest neighbour interchange (NNI) move on the tree specified by root.
Returns a mutated copy while leaving the original tree intact.
root
: root node of tree on which to perform the NNI.
Randomize
MCPhyloTree.randomize!
— Methodrandomize!(root::T, num::Int64=100)::Nothing where T <:AbstractNode
This function randomizes the tree by performing a number of nearest neighbour interchange (NNI) moves and a randomization of the branch lengths. The number of NNI moves is specified in the parameter num.
root
: root node of tree to be edited.num
: amount of NNI moves to perform.
MCPhyloTree.randomize
— Methodrandomize(root::T, num::Int64=100)::T where T <:AbstractNode
This function returns a randomized copy of the tree by performing a number of nearest neighbour interchange (NNI) moves and a randomization of the branch lengths. The number of NNI moves is specified in the parameter num.
root
: root node of tree to be edited.num
: amount of NNI moves to perform.
Rerooting
SPR
MCPhyloTree.SPR!
— MethodSPR!(root::T)::T where T <:AbstractNode
Performs SPR on tree in place. Takes reference to root of tree; Returns reference to root of altered tree. Throws error if tree is improperly formatted.
MCPhyloTree.SPR
— Methodfunction SPR(original_root<:AbstractNode)
Performs SPR on tree. Takes a copy of root of the tree; Returns a copy of root of altered tree. Throws error if tree is improperly formatted.
MCPhyloTree.perform_spr
— Methodperform_spr(root::T) where T <: GeneralNode
performs SPR on binary tree. Returns root of tree post-SPR.
root
: Node of tree on which to perform SPR.
MCPhyloTree.perform_spr
— Methodperform_spr(root::T,subtree::T,target::T) where T <: GeneralNode
performs SPR on binary tree. Returns root of tree post-SPR.
root
: Node of tree on which to perform SPR.subtree
: Root of subtree to be moved.target
: Target of SPR.
MCPhyloTree.perform_spr
— Methodperform_spr(root::T,subtree::T) where T <: GeneralNode
performs SPR on binary tree. Returns root of tree post-SPR.
root
: Node of tree on which to perform SPR.subtree
: Root of subtree to be moved.
MCPhyloTree.risky_SPR!
— Method risky_SPR!(root<:AbstractNode)
Performs SPR on tree in place. Returns reference to root of altered tree. Does not check for correct formatting of tree.
root
: root node of tree.
MCPhyloTree.risky_SPR
— Methodfunction risky_SPR(original_root::T)::T where T<:AbstractNode
Performs SPR on tree in place. Takes reference to root of tree Returns copy of root of altered tree. Does not check for correct formatting of tree.