From: paradis Date: Sat, 26 Mar 2011 08:41:35 +0000 (+0000) Subject: final update for ape 2.7-1 X-Git-Url: https://git.donarmstrong.com/?p=ape.git;a=commitdiff_plain;h=80d1c453d63d6aec18f0b731d59918b99e189d86 final update for ape 2.7-1 git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@154 6e262413-ae40-0410-9e79-b911bd7a66b7 --- diff --git a/ChangeLog b/ChangeLog index 5f6172d..40d2a95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,15 +19,22 @@ BUG FIXES o image.DNAbin() did not colour correctly the bases if there were some '-' and no 'N'. + o .compressTipLabel() failed with a list with a single tree. + o identify.phylo() returned a wrong answer when the x- and y-scales are very different. + o write.nexus() failed with lists of trees with compressed labels. + OTHER CHANGES o identify.phylo() now returns NULL if the user right-(instead of left-)clicks (an error was returned previously). + o read.nexus() should be robust to commands inserted in the TREES + block. + CHANGES IN APE VERSION 2.7 diff --git a/DESCRIPTION b/DESCRIPTION index 32054d4..6da064b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ape Version: 2.7-1 -Date: 2011-03-22 +Date: 2011-03-26 Title: Analyses of Phylogenetics and Evolution Author: Emmanuel Paradis, Ben Bolker, Julien Claude, Hoa Sien Cuong, Richard Desper, Benoit Durand, Julien Dutheil, Olivier Gascuel, Christoph Heibl, Daniel Lawson, Vincent Lefort, Pierre Legendre, Jim Lemon, Yvonnick Noel, Johan Nylander, Rainer Opgen-Rhein, Klaus Schliep, Korbinian Strimmer, Damien de Vienne Maintainer: Emmanuel Paradis diff --git a/R/as.phylo.R b/R/as.phylo.R index 8ebd540..5d541bc 100644 --- a/R/as.phylo.R +++ b/R/as.phylo.R @@ -1,4 +1,4 @@ -## as.phylo.R (2011-03-16) +## as.phylo.R (2011-03-25) ## Conversion Among Tree Objects @@ -29,7 +29,8 @@ new2old.phylo <- function(phy) as.phylo <- function (x, ...) { - if (class(x) == "phylo") return(x) + if (length(class(x)) == 1 && class(x) == "phylo") + return(x) UseMethod("as.phylo") } diff --git a/R/dist.topo.R b/R/dist.topo.R index d94866a..e192f4f 100644 --- a/R/dist.topo.R +++ b/R/dist.topo.R @@ -1,4 +1,4 @@ -## dist.topo.R (2011-02-21) +## dist.topo.R (2011-03-26) ## Topological Distances, Tree Bipartitions, ## Consensus Trees, and Bootstrapping Phylogenies @@ -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")) ### the test below does not seem useful anymore ### if (any(tabulate(ilab) > 1)) ### stop(paste("some tip labels are duplicated in tree no.", i)) ### - 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 diff --git a/R/read.nexus.R b/R/read.nexus.R index 117b31f..cdbc291 100644 --- a/R/read.nexus.R +++ b/R/read.nexus.R @@ -1,4 +1,4 @@ -## read.nexus.R (2011-03-18) +## read.nexus.R (2011-03-26) ## Read Tree File in Nexus Format @@ -154,12 +154,13 @@ read.nexus <- function(file, tree.names = NULL) end <- endblock[endblock > i1][1] - 1 tree <- X[start:end] rm(X) - tree <- gsub("^.*= *", "", tree) +### tree <- gsub("^.*= *", "", tree) ## check whether there are empty lines from the above manips: tree <- tree[tree != ""] semico <- grep(";", tree) - Ntree <- length(semico) + Ntree <- length(semico) # provisional -- some ";" may actually mark end of commands ## are some trees on several lines? + ## -- this actually 'packs' all characters ending with a ";" in a single string -- if (Ntree == 1 && length(tree) > 1) STRING <- paste(tree, collapse = "") else { if (any(diff(semico) != 1)) { STRING <- character(Ntree) @@ -175,7 +176,14 @@ read.nexus <- function(file, tree.names = NULL) } else STRING <- tree } rm(tree) - STRING <- gsub(" ", "", STRING) + ## exclude the possible command lines ending with ";": + STRING <- STRING[grep("^[[:blank:]]*tree.*= *", STRING, ignore.case = TRUE)] + Ntree <- length(STRING) # update Ntree + ## get the tree names: + nms.trees <- sub(" *= *.*", "", STRING) # only the first occurence of "=" + nms.trees <- sub("^ *tree *", "", nms.trees, ignore.case = TRUE) + STRING <- sub("^.*= *", "", STRING) # delete title and 'TREE' command with 'sub' + STRING <- gsub(" ", "", STRING) # delete all white spaces colon <- grep(":", STRING) if (!length(colon)) { trees <- lapply(STRING, clado.build) @@ -237,6 +245,7 @@ read.nexus <- function(file, tree.names = NULL) } } class(trees) <- "multiPhylo" + if (!all(nms.trees == "")) names(trees) <- nms.trees } if (length(grep("[\\/]", file)) == 1) if (!file.exists(file)) # suggestion by Francois Michonneau diff --git a/R/write.nexus.R b/R/write.nexus.R index 2a3c32a..1db2252 100644 --- a/R/write.nexus.R +++ b/R/write.nexus.R @@ -1,8 +1,8 @@ -## write.nexus.R (2011-02-26) +## write.nexus.R (2011-03-26) ## Write Tree File in Nexus Format -## Copyright 2003-2011x Emmanuel Paradis +## Copyright 2003-2011 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -57,26 +57,24 @@ the original data won't be written with the tree.")) } cat("BEGIN TREES;\n", file = file, append = TRUE) if (translate) { - ## We take arbitrarily the labels of the first tree, and - ## translate them as "1", "2", "3", ... cat("\tTRANSLATE\n", file = file, append = TRUE) - tmp <- checkLabel(obj[[1]]$tip.label) - X <- paste("\t\t", 1:N, "\t", tmp, ",", sep = "") + obj <- .compressTipLabel(obj) + X <- paste("\t\t", 1:N, "\t", attr(obj, "TipLabel"), ",", sep = "") ## We remove the last comma: X[length(X)] <- gsub(",", "", X[length(X)]) cat(X, file = file, append = TRUE, sep = "\n") cat("\t;\n", file = file, append = TRUE) - token <- as.character(1:N) - names(token) <- obj[[1]]$tip.label - obj[[1]]$tip.label <- token - if (ntree > 1) { - for (i in 2:ntree) - obj[[i]]$tip.label <- token[obj[[i]]$tip.label] - class(obj) <- NULL - } - } else { + class(obj) <- NULL for (i in 1:ntree) - obj[[i]]$tip.label <- checkLabel(obj[[i]]$tip.label) + obj[[i]]$tip.label <- as.character(1:N) + } else { + if (is.null(attr(obj, "TipLabel"))) { + for (i in 1:ntree) + obj[[i]]$tip.label <- checkLabel(obj[[i]]$tip.label) + } else { + attr(obj, "TipLabel") <- checkLabel(attr(obj, "TipLabel")) + obj <- .uncompressTipLabel(obj) + } } title <- names(obj) diff --git a/man/ace.Rd b/man/ace.Rd index f440027..126a216 100644 --- a/man/ace.Rd +++ b/man/ace.Rd @@ -71,7 +71,17 @@ ace(x, phy, type = "continuous", method = "ML", CI = TRUE, generalized least squares (\code{method = "GLS"}, Martins and Hansen 1997, Cunningham et al. 1998). In the latter case, the specification of \code{phy} and \code{model} are actually ignored: it is instead - given through a correlation structure with the option \code{corStruct}. + given through a correlation structure with the option + \code{corStruct}. + + In the default setting (i.e., \code{method = "ML"} and \code{model = + "BM"}) the maximum likelihood estimation is done simultaneously on + the ancestral values and the variance of the Brownian motion process; + these estimates are then used to compute the confidence intervals in + the standard way (see the package \pkg{geiger} for a different + implementation). If \code{method = "pic"} or \code{"GLS"}, the + confidence intervals are computed using the expected variances under + the model, so they depend only on the tree. For discrete characters (\code{type = "discrete"}), only maximum likelihood estimation is available (Pagel 1994). The model is diff --git a/man/plot.phylo.Rd b/man/plot.phylo.Rd index 614ce62..f6a137c 100644 --- a/man/plot.phylo.Rd +++ b/man/plot.phylo.Rd @@ -162,10 +162,10 @@ } \author{Emmanuel Paradis} \seealso{ - \code{\link{read.tree}}, \code{\link{add.scale.bar}}, - \code{\link{axisPhylo}}, \code{\link{nodelabels}}, - \code{\link{edges}}, \code{\link[graphics]{plot}} for the basic - plotting function in R + \code{\link{read.tree}}, \code{\link{trex}}, \code{\link{kronoviz}}, + \code{\link{add.scale.bar}}, \code{\link{axisPhylo}}, + \code{\link{nodelabels}}, \code{\link{edges}}, + \code{\link[graphics]{plot}} for the basic plotting function in R } \examples{ ### An extract from Sibley and Ahlquist (1990) diff --git a/man/richness.yule.test.Rd b/man/richness.yule.test.Rd index b9ba898..21df590 100644 --- a/man/richness.yule.test.Rd +++ b/man/richness.yule.test.Rd @@ -17,8 +17,6 @@ richness.yule.test(x, t) \item{t}{a numeric vector giving the divergence times of each pair of clades in \code{x}.} } -\details{ -} \value{ a data frame with the \eqn{\chi^2}{chi2}, the number of degrees of freedom (= 1), and the \emph{P}-value.