]> git.donarmstrong.com Git - ape.git/blobdiff - R/dist.topo.R
new LTT plot functions + updated reference in yule.time.Rd
[ape.git] / R / dist.topo.R
index e192f4f43b56184fc8a3a6545fd85a2b3b6fb8db..525178f2528ed1ba66321e178d8c79d2cf0c91ed 100644 (file)
@@ -1,4 +1,4 @@
-## dist.topo.R (2011-03-26)
+## dist.topo.R (2011-07-13)
 
 ##      Topological Distances, Tree Bipartitions,
 ##   Consensus Trees, and Bootstrapping Phylogenies
@@ -184,7 +184,8 @@ prop.clades <- function(phy, ..., part = NULL)
     n
 }
 
-boot.phylo <- function(phy, x, FUN, B = 100, block = 1, trees = FALSE)
+boot.phylo <- function(phy, x, FUN, B = 100, block = 1,
+                       trees = FALSE, quiet = FALSE)
 {
     if (is.list(x) && !is.data.frame(x)) {
         if (inherits(x, "DNAbin")) x <- as.matrix(x)
@@ -198,6 +199,7 @@ boot.phylo <- function(phy, x, FUN, B = 100, block = 1, trees = FALSE)
         }
     }
     boot.tree <- vector("list", B)
+    if (!quiet) progbar <- utils::txtProgressBar(style = 3) # suggestion by Alastair Potts
     for (i in 1:B) {
         if (block > 1) {
             y <- seq(block, ncol(x), block)
@@ -208,11 +210,14 @@ boot.phylo <- function(phy, x, FUN, B = 100, block = 1, trees = FALSE)
               boot.samp[y - j] <- boot.i - j
         } else boot.samp <- sample(ncol(x), replace = TRUE)
         boot.tree[[i]] <- FUN(x[, boot.samp])
+        if (!quiet) utils::setTxtProgressBar(progbar, i/B)
     }
+    if (!quiet) close(progbar)
     for (i in 1:B) storage.mode(boot.tree[[i]]$Nnode) <- "integer"
     storage.mode(phy$Nnode) <- "integer"
-    ans <- attr(.Call("prop_part", c(list(phy), boot.tree),
-                      B + 1, FALSE, PACKAGE = "ape"), "number") - 1
+    ans <- prop.clades(phy, boot.tree)
+    ##ans <- attr(.Call("prop_part", c(list(phy), boot.tree),
+    ##                  B + 1, FALSE, PACKAGE = "ape"), "number") - 1
     if (trees) {
         class(boot.tree) <- "multiPhylo"
         ans <- list(BP = ans, trees = boot.tree)
@@ -263,6 +268,7 @@ consensus <- function(..., p = 1, check.labels = TRUE)
     ## Get all observed partitions and their frequencies:
     pp <- prop.part(obj, check.labels = FALSE)
     ## Drop the partitions whose frequency is less than 'p':
+    if (p == 0.5) p <- 0.5000001 # avoid incompatible splits
     pp <- pp[attr(pp, "number") >= p * ntree]
     ## Get the order of the remaining partitions by decreasing size:
     ind <- sort(unlist(lapply(pp, length)), decreasing = TRUE,