Skip to contents

Starting from a star tree, every pair of current OTUs is scored by the total branch length \(S_{ij}\) of the tree joining them (eq. 4 of the paper); the smallest \(S_{ij}\) pair is joined. Branch lengths follow eqs. (6a)-(6b), \(L_i = (D_{ij} + D_{iZ} - D_{jZ})/2\) with \(D_{iZ}\) the average distance to the remaining OTUs, and the combined OTU takes averaged distances \(D_{(ij)k} = (D_{ik} + D_{jk})/2\) (eq. 5). The cycle repeats until three OTUs remain. Ties in \(S_{ij}\) break to the first pair in row-major order, pinned identically in the Python arm. This is the 1987 algorithm as printed (averaged updates), not the later Studier-Keppler variant.

Usage

Phylotr(distance, labels = NULL)

Arguments

distance

Symmetric distance matrix.

labels

Optional OTU names (default "1".."n").

Value

List with joins (per cycle: labels a, b, new, La, Lb, S), s0, final_labels, final_lengths, n, method.

References

Saitou, N. and Nei, M. (1987), The neighbor-joining method: a new method for reconstructing phylogenetic trees, Molecular Biology and Evolution 4(4), 406-425. Equations (1), (4), (5), (6a), (6b), pp. 408-409; worked example Table 1, Table 2 and Figure 3, pp. 410-411.

Examples

# the additive four-taxon example: neighbor-joining recovers the tree
D <- matrix(c(0, 5, 9, 9,
              5, 0, 10, 10,
              9, 10, 0, 8,
              9, 10, 8, 0), 4, byrow = TRUE)
Phylotr(D, labels = c("a", "b", "c", "d"))$joins[[1]]
#> $a
#> [1] "a"
#> 
#> $b
#> [1] "b"
#> 
#> $new
#> [1] "(a-b)"
#> 
#> $La
#> [1] 2
#> 
#> $Lb
#> [1] 3
#> 
#> $S
#> [1] 16
#>