X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2Fme.R;h=7dca6c020cec10ad3425358756fee5bb480212f0;hb=f3426364b40c7c0e6aadf6ea2690716425abdfc9;hp=93cebd378303e1b2bfee2f70a941a38e7cbfa2f4;hpb=3f528bd2c47301b64ed03bd28039bbf22a7510ad;p=ape.git diff --git a/R/me.R b/R/me.R index 93cebd3..7dca6c0 100644 --- a/R/me.R +++ b/R/me.R @@ -1,20 +1,40 @@ -## me.R (2008-01-12) +## me.R (2009-01-07) ## Tree Estimation Based on Minimum Evolution Algorithm ## Copyright 2007 Vincent Lefort with modifications by -## Emmanuel Paradis (2008) +## Emmanuel Paradis (2008-2009) ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. -.fastme <- function(X, nni, lib) +fastme.bal <- function(X, nni = TRUE, spr = TRUE, tbr = TRUE) { if (is.matrix(X)) X <- as.dist(X) N <- as.integer(attr(X, "Size")) labels <- sprintf("%6s", 1:N) edge1 <- edge2 <- integer(2*N - 3) - ans <- .C(lib, as.double(X), N, labels, as.integer(nni), + + ans <- .C("me_b", as.double(X), N, labels, as.integer(nni), + as.integer(spr), as.integer(tbr), edge1, edge2, + double(2*N - 3), character(N), PACKAGE = "ape") + + labels <- substr(ans[[10]], 1, 6) + LABS <- attr(X, "Labels") + labels <- if (!is.null(LABS)) LABS[as.numeric(labels)] + else gsub("^ ", "", labels) + structure(list(edge = cbind(ans[[7]], ans[[8]]), edge.length = ans[[9]], + tip.label = labels, Nnode = N - 2L), + class = "phylo") +} + +fastme.ols <- function(X, nni = TRUE) +{ + if (is.matrix(X)) X <- as.dist(X) + N <- as.integer(attr(X, "Size")) + labels <- sprintf("%6s", 1:N) + edge1 <- edge2 <- integer(2*N - 3) + ans <- .C("me_o", as.double(X), N, labels, as.integer(nni), edge1, edge2, double(2*N - 3), character(N), PACKAGE = "ape") labels <- substr(ans[[8]], 1, 6) @@ -22,14 +42,10 @@ labels <- if (!is.null(LABS)) LABS[as.numeric(labels)] else gsub("^ ", "", labels) structure(list(edge = cbind(ans[[5]], ans[[6]]), edge.length = ans[[7]], - tip.label = labels, Nnode = N - 2), + tip.label = labels, Nnode = N - 2L), class = "phylo") } -fastme.bal <- function(X, nni = TRUE) .fastme(X, nni, "me_b") - -fastme.ols <- function(X, nni = TRUE) .fastme(X, nni, "me_o") - bionj <- function(X) { if (is.matrix(X)) X <- as.dist(X) @@ -43,6 +59,6 @@ bionj <- function(X) labels <- if (!is.null(LABS)) LABS[as.numeric(labels)] else gsub("^ ", "", labels) structure(list(edge = cbind(ans[[4]], ans[[5]]), edge.length = ans[[6]], - tip.label = labels, Nnode = N - 2), + tip.label = labels, Nnode = N - 2L), class = "phylo") }