]> git.donarmstrong.com Git - ape.git/blobdiff - R/dist.topo.R
fixing drop.tip and bionj
[ape.git] / R / dist.topo.R
index fa9e869d7b0eb7b9d4925bd2538f640ea2a8a03f..e192f4f43b56184fc8a3a6545fd85a2b3b6fb8db 100644 (file)
@@ -1,9 +1,9 @@
-## dist.topo.R (2010-11-18)
+## dist.topo.R (2011-03-26)
 
 ##      Topological Distances, Tree Bipartitions,
 ##   Consensus Trees, and Bootstrapping Phylogenies
 
-## Copyright 2005-2010 Emmanuel Paradis
+## Copyright 2005-2011 Emmanuel Paradis
 
 ## This file is part of the R-package `ape'.
 ## See the file ../COPYING for licensing issues.
@@ -71,23 +71,26 @@ dist.topo <- function(x, y, method = "PH85")
     if (any(table(ref) != 1))
         stop("some tip labels are duplicated in tree no. 1")
     n <- length(ref)
-    for (i in 2:length(x)) {
-        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"))
+    Ntree <- length(x)
+    if (Ntree > 1) {
+        for (i in 2:Ntree) {
+            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
+                ie <- match(1:n, x[[i]]$edge[, 2])
+                x[[i]]$edge[ie, 2] <- ilab
+            }
+            x[[i]]$tip.label <- NULL
         }
-        x[[i]]$tip.label <- NULL
     }
     x[[1]]$tip.label <- NULL
     attr(x, "TipLabel") <- ref
@@ -104,7 +107,7 @@ prop.part <- function(..., check.labels = TRUE)
     ## </FIXME>
     ntree <- length(obj)
     if (ntree == 1) check.labels <- FALSE
-    if (check.labels) .compressTipLabel(obj) # no need to store cause uncompress later
+    if (check.labels) obj <- .compressTipLabel(obj) # fix by Klaus Schliep (2011-02-21)
     for (i in 1:ntree) storage.mode(obj[[i]]$Nnode) <- "integer"
     ## <FIXME>
     ## The 1st must have tip labels