X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2Fdist.topo.R;h=f82dd65193695e63301d706ac71bd63395212a5c;hb=3ad385892d75db5c646c92f0f631ae9c5e3da4f6;hp=88110c59c8c7304444b06395cc4645eec33cabf9;hpb=155d31f088ad9bd4074e5545c6a2dd48ab178788;p=ape.git diff --git a/R/dist.topo.R b/R/dist.topo.R index 88110c5..f82dd65 100644 --- a/R/dist.topo.R +++ b/R/dist.topo.R @@ -1,9 +1,9 @@ -## dist.topo.R (2008-06-28) +## dist.topo.R (2009-07-06) ## Topological Distances, Tree Bipartitions, ## Consensus Trees, and Bootstrapping Phylogenies -## Copyright 2005-2008 Emmanuel Paradis +## Copyright 2005-2009 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -11,25 +11,31 @@ dist.topo <- function(x, y, method = "PH85") { if (method == "BHV01" && (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 Billera et al.'s distance.") n <- length(x$tip.label) bp1 <- .Call("bipartition", x$edge, n, x$Nnode, PACKAGE = "ape") bp1 <- lapply(bp1, function(xx) sort(x$tip.label[xx])) - bp2 <- .Call("bipartition", y$edge, n, y$Nnode, PACKAGE = "ape") - bp2 <- lapply(bp2, function(xx) sort(y$tip.label[xx])) + ## fix by Tim Wallstrom: + bp2.tmp <- .Call("bipartition", y$edge, n, y$Nnode, PACKAGE = "ape") + bp2 <- lapply(bp2.tmp, function(xx) sort(y$tip.label[xx])) + bp2.comp <- lapply(bp2.tmp, function(xx) setdiff(1:n, xx)) + bp2.comp <- lapply(bp2.comp, function(xx) sort(y$tip.label[xx])) + ## End q1 <- length(bp1) q2 <- length(bp2) if (method == "PH85") { p <- 0 for (i in 1:q1) { for (j in 1:q2) { - if (identical(all.equal(bp1[[i]], bp2[[j]]), TRUE)) { + if (identical(bp1[[i]], bp2[[j]]) | + identical(bp1[[i]], bp2.comp[[j]])) { p <- p + 1 break } } } - dT <- if (q1 == q2) 2*(q1 - p) else 2*(min(q1, q2) - p) + abs(q1 - q2) + dT <- q1 + q2 - 2 * p # same than: + ##dT <- if (q1 == q2) 2*(q1 - p) else 2*(min(q1, q2) - p) + abs(q1 - q2) } if (method == "BHV01") { dT <- 0 @@ -87,6 +93,7 @@ prop.part <- function(..., check.labels = TRUE) ## class(obj) <- NULL # needed? ## ntree <- length(obj) + if (ntree == 1) check.labels <- FALSE if (check.labels) obj <- .compressTipLabel(obj) for (i in 1:ntree) storage.mode(obj[[i]]$Nnode) <- "integer" ## @@ -167,8 +174,8 @@ prop.clades <- function(phy, ..., part = NULL) boot.phylo <- function(phy, x, FUN, B = 100, block = 1, trees = FALSE) { - if (is.list(x)) { - if (class(x) == "DNAbin") x <- as.matrix(x) + if (is.list(x) && !is.data.frame(x)) { + if (inherits(x, "DNAbin")) x <- as.matrix(x) else { nm <- names(x) n <- length(x)