]> git.donarmstrong.com Git - ape.git/blob - R/njs.R
some news for ape 3.0-8
[ape.git] / R / njs.R
1 ## njs.R (2012-03-30)
2
3 ## Tree Reconstruction from Incomplete Distances With NJ* or bio-NJ*
4
5 ## Copyright 2011 Andrei-Alin Popescu
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 .NJS_BIONJS <- function(libs, X, fs = 15)
11 {
12     if (fs < 1)
13         stop("argument 'fs' must be a non-zero positive integer")
14     if (is.matrix(X)) X <- as.dist(X)
15     X[is.na(X)] <- -1
16     X[X < 0] <- -1
17     X[is.nan(X)] <- -1
18     N <- attr(X, "Size")
19     labels <- attr(X, "Labels")
20     if (is.null(labels)) labels <- as.character(1:N)
21     ans <- .C(libs, as.double(X), as.integer(N), integer(2*N - 3),
22               integer(2*N - 3), double(2*N - 3), as.integer(fs),
23               DUP = FALSE, NAOK = TRUE, PACKAGE = "ape")
24     obj <- list(edge = cbind(ans[[3]], ans[[4]]), edge.length = ans[[5]],
25                 tip.label = labels, Nnode = N - 2L)
26     class(obj) <- "phylo"
27     reorder(obj)
28 }
29
30
31 njs <- function(X, fs = 15) .NJS_BIONJS("njs", X = X, fs = fs)
32
33 bionjs <- function(X, fs = 15) .NJS_BIONJS("bionjs", X = X, fs = fs)