TreeSearch (version 0.4.0)

NNI: Nearest Neighbour Interchange (NNI)

Description

Performs a single iteration of the nearest-neighbour interchange algorithm. Based on the corresponding phangorn function, but re-coded to improve speed.

Usage

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)

Arguments

tree

A tree of class phylo.

edgeToBreak

(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.

parent

Integer vector corresponding to the first column of the edge matrix of a tree of class phylo, i.e. tree$edge[, 1].

child

Integer vector corresponding to the second column of the edge matrix of a tree of class phylo, i.e. tree$edge[, 2].

nTips

(optional) Number of tips.

Value

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

Functions

  • 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

Details

Branch lengths are not supported.

All nodes in a tree must be bifurcating; ape::collapse.singles and ape::multi2di may help.

References

The algorithm is summarized in Felsenstein2004TreeSearch

See Also

Other tree rearrangement functions: SPR, TBR

Examples

Run this code
# NOT RUN {
tree <- ape::rtree(20, br = NULL)
NNI(tree)
NNI(tree, edgeToBreak = -1)

# }

Run the code above in your browser using DataLab