Performs a single iteration of the nearest-neighbour interchange algorithm.
Based on the corresponding phangorn
function, but re-coded to improve speed.
NNI(tree, edgeToBreak = 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)
A tree of class phylo
.
(optional) integer specifying the index of an edge to bisect/prune,
generated randomly if not specified.
Alternatively, set to -1
to return a complete list
of all trees one step from the input tree.
the first column of the edge matrix of a tree of class
phylo
, i.e. tree$edge[, 1]
the second column of the edge matrix of a tree of class
phylo
, i.e. tree$edge[, 2]
(optional) Number of tips.
Returns a tree with class phylo
(if returnAll = FALSE
) or
a set of trees, with class multiPhylo
(if returnAll = TRUE
).
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
Branch lengths are not supported.
All nodes in a tree must be bifurcating; ape::collapse.singles and ape::multi2di may help.
The algorithm is summarized in Felsenstein2004TreeSearch
# NOT RUN {
tree <- ape::rtree(20, br=NULL)
NNI(tree)
NNI(tree, edgeToBreak = -1)
# }
Run the code above in your browser using DataLab