]> git.donarmstrong.com Git - ape.git/blobdiff - R/dist.topo.R
adding bd.time
[ape.git] / R / dist.topo.R
index 779db02b2f579e83277afd38fd0d72aab3a2c260..86b396b9aa9814abade98b2c5bd86c3f75fe25ee 100644 (file)
@@ -1,4 +1,4 @@
-## dist.topo.R (2010-05-06)
+## dist.topo.R (2010-05-25)
 
 ##      Topological Distances, Tree Bipartitions,
 ##   Consensus Trees, and Bootstrapping Phylogenies
@@ -11,7 +11,7 @@
 dist.topo <- function(x, y, method = "PH85")
 {
     if (method == "score" && (is.null(x$edge.length) || is.null(y$edge.length)))
-        stop("trees must have branch lengths for Billera et al.'s distance.")
+        stop("trees must have branch lengths for branch score distance.")
     nx <- length(x$tip.label)
     x <- unroot(x)
     y <- unroot(y)
@@ -72,15 +72,21 @@ dist.topo <- function(x, y, method = "PH85")
         stop("some tip labels are duplicated in tree no. 1")
     n <- length(ref)
     for (i in 2:length(x)) {
-        if (identical(x[[i]]$tip.label, ref)) next
-        ilab <- match(x[[i]]$tip.label, ref)
-        ## can use tabulate here because 'ilab' contains integers
-        if (any(tabulate(ilab) > 1))
-            stop(paste("some tip labels are duplicated in tree no.", i))
-        if (any(is.na(ilab)))
-            stop(paste("tree no.", i, "has different tip labels"))
-        ie <- match(1:n, x[[i]]$edge[, 2])
-        x[[i]]$edge[ie, 2] <- ilab
+        label <- x[[i]]$tip.label
+        if (!identical(label, ref)) {
+            if (length(label) != length(ref))
+                stop(paste("tree no.", i, "has a different number of tips"))
+            ilab <- match(label, ref)
+            ## can use tabulate here because 'ilab' contains integers
+            if (any(is.na(ilab)))
+                stop(paste("tree no.", i, "has different tip labels"))
+### <FIXME> the test below does not seem useful anymore
+###            if (any(tabulate(ilab) > 1))
+###                stop(paste("some tip labels are duplicated in tree no.", i))
+### </FIXME>
+            ie <- match(1:n, x[[i]]$edge[, 2])
+            x[[i]]$edge[ie, 2] <- ilab
+        }
         x[[i]]$tip.label <- NULL
     }
     x[[1]]$tip.label <- NULL
@@ -205,7 +211,10 @@ boot.phylo <- function(phy, x, FUN, B = 100, block = 1, trees = FALSE)
     storage.mode(phy$Nnode) <- "integer"
     ans <- attr(.Call("prop_part", c(list(phy), boot.tree),
                       B + 1, FALSE, PACKAGE = "ape"), "number") - 1
-    if (trees) ans <- list(BP = ans, trees = boot.tree)
+    if (trees) {
+        class(boot.tree) <- "multiPhylo"
+        ans <- list(BP = ans, trees = boot.tree)
+    }
     ans
 }