]> git.donarmstrong.com Git - ape.git/blob - R/nj.R
some news for ape 3.0-8
[ape.git] / R / nj.R
1 ## nj.R (2009-11-23)
2
3 ##   Neighbor-Joining Tree Estimation
4
5 ## Copyright 2004-2009 Emmanuel Paradis
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 nj <- function(X)
11 {
12     if (is.matrix(X)) X <- as.dist(X)
13     if (any(is.na(X)))
14         stop("missing values are not allowed in the distance matrix\nConsider using njs()")
15     N <- attr(X, "Size")
16     labels <- attr(X, "Labels")
17     if (is.null(labels)) labels <- as.character(1:N)
18     ans <- .C("nj", as.double(X), as.integer(N), integer(2*N - 3),
19               integer(2*N - 3), double(2*N - 3),
20               DUP = FALSE, NAOK = TRUE, PACKAGE = "ape")
21     obj <- list(edge = cbind(ans[[3]], ans[[4]]), edge.length = ans[[5]],
22                 tip.label = labels, Nnode = N - 2L)
23     class(obj) <- "phylo"
24     reorder(obj)
25 }