NNI | R Documentation |
NNI()
performs a single iteration of the nearest-neighbour interchange
algorithm; RootedNNI()
retains the position of the root.
These functions are based on equivalents in the phangorn package.
cNNI()
is an equivalent function coded in C, that runs much faster.
NNI(tree, edgeToBreak = NULL)
cNNI(tree, edgeToBreak = NULL, whichSwitch = NULL)
NNISwap(parent, child, nTips = (length(parent)/2L) + 1L, edgeToBreak = NULL)
RootedNNI(tree, edgeToBreak = NULL)
RootedNNISwap(
parent,
child,
nTips = (length(parent)/2L) + 1L,
edgeToBreak = NULL
)
tree |
A tree of class |
edgeToBreak |
In ( |
whichSwitch |
Integer from zero to one, specifying which way to re-build the broken internal edge. |
parent |
Integer vector corresponding to the first column of the edge
matrix of a tree of class |
child |
Integer vector corresponding to the second column of the edge
matrix of a tree of class |
nTips |
(optional) Number of tips. |
Branch lengths are not supported.
All nodes in a tree must be bifurcating; ape::collapse.singles()
and
ape::multi2di()
may help.
Returns a tree with class phylo
(if returnAll = FALSE
) or
a set of trees, with class multiPhylo
(if returnAll = TRUE
).
cNNI()
returns a tree of class phylo
, rooted on the same leaf,
on which the specified rearrangement has been conducted.
NNISwap()
returns a list containing two elements, corresponding in
turn to the rearranged parent and child parameters.
a list containing two elements, corresponding in turn to the rearranged parent and child parameters
NNISwap()
: faster version that takes and returns parent and child parameters
RootedNNI()
: Perform NNI rearrangement, retaining position of root
RootedNNISwap()
: faster version that takes and returns parent and child parameters
Martin R. Smith (martin.smith@durham.ac.uk)
The algorithm is summarized in \insertRefFelsenstein2004TreeSearch
Other tree rearrangement functions:
SPR()
,
TBR()
tree <- TreeTools::BalancedTree(8)
# A random rearrangement
NNI(tree)
cNNI(tree)
# All trees one NNI rearrangement away
NNI(tree, edgeToBreak = -1)
# Manual random sampling
cNNI(tree, sample.int(14 - 8 - 1, 1), sample.int(2, 1))
# A specified rearrangement
cNNI(tree, 0, 0)
# If a tree may not be binary, collapse nodes with
tree <- TreeTools::MakeTreeBinary(tree)
# If a tree may be improperly rooted, use
tree <- TreeTools::RootTree(tree, 1)
# If a tree may exhibit unusual node ordering, this can be addressed with
tree <- TreeTools::Preorder(tree)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.