o read.tree() failed to read correctly the tree name(s).
+ o boot.phylo() now treats correctly data frames.
+
+
+OTHER CHANGES
+
+ o [.multiPhylo and [.DNAbin now respect the original class.
+
+ o Instances of the form class(phy) == "phylo" have been replaced
+ by inherits(phy, "phylo").
+
CHANGES IN APE VERSION 2.3
Package: ape
Version: 2.3-1
-Date: 2009-04-27
+Date: 2009-05-10
Title: Analyses of Phylogenetics and Evolution
Author: Emmanuel Paradis, Ben Bolker, Julien Claude, Hoa Sien Cuong, Richard Desper, Benoit Durand, Julien Dutheil, Olivier Gascuel, Gangolf Jobb, Christoph Heibl, Daniel Lawson, Vincent Lefort, Pierre Legendre, Jim Lemon, Yvonnick Noel, Johan Nylander, Rainer Opgen-Rhein, Korbinian Strimmer, Damien de Vienne
Maintainer: Emmanuel Paradis <Emmanuel.Paradis@ird.fr>
-## DNA.R (2008-12-22)
+## DNA.R (2009-05-10)
## Manipulations and Comparisons of DNA Sequences
-## Copyright 2002-2008 Emmanuel Paradis
+## Copyright 2002-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
if (length(i)) x[-i] else x
}
- if (class(x) != "DNAbin") x <- as.DNAbin(x)
+ if (!inherits(x, "DNAbin")) x <- as.DNAbin(x)
if (is.matrix(x)) {
n <- dim(x)[1]
y <- vector("list", n)
"[.DNAbin" <- function(x, i, j, drop = TRUE)
{
+ oc <- oldClass(x)
class(x) <- NULL
if (is.matrix(x)) {
if (nargs() == 2 && !missing(i)) ans <- x[i]
if (missing(i)) i <- 1:length(x)
ans <- x[i]
}
- structure(ans, class = "DNAbin")
+ class(ans) <- oc
+ ans
}
as.matrix.DNAbin <- function(x, ...)
{
- if (is.matrix(x)) return(x)
if (is.list(x)) {
if (length(unique(unlist(lapply(x, length)))) != 1)
stop("DNA sequences in list not of the same length.")
-## ace.R (2009-03-22)
+## ace.R (2009-05-10)
-## Ancestral Character Estimation
+## Ancestral Character Estimation
## Copyright 2005-2009 Emmanuel Paradis and Ben Bolker
model = if (type == "continuous") "BM" else "ER",
scaled = TRUE, kappa = 1, corStruct = NULL, ip = 0.1)
{
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo".')
if (is.null(phy$edge.length))
stop("tree has no branch lengths")
-## balance.R (2006-10-04)
+## balance.R (2009-05-10)
## Balance of a Dichotomous Phylogenetic Tree
-## Copyright 2002-2006 Emmanuel Paradis
+## Copyright 2002-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
balance <- function(phy)
{
### the tree must be in cladewise order
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo"')
N <- length(phy$tip.label)
nb.node <- phy$Nnode
-## birthdeath.R (2007-10-30)
+## birthdeath.R (2009-05-10)
## Estimation of Speciation and Extinction Rates
## with Birth-Death Models
## birthdeath: standard model
## bd.ext: extended version
-## Copyright 2002-2007 Emmanuel Paradis
+## Copyright 2002-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
birthdeath <- function(phy)
{
- if (class(phy) != "phylo") stop('object "phy" is not of class "phylo"')
+ if (!inherits(phy, "phylo")) stop('object "phy" is not of class "phylo"')
N <- length(phy$tip.label)
x <- c(NA, branching.times(phy))
dev <- function(a, r) {
bd.ext <- function(phy, S)
{
- if (class(phy) != "phylo") stop('object "phy" is not of class "phylo"')
+ if (!inherits(phy, "phylo")) stop('object "phy" is not of class "phylo"')
if (!is.null(names(S))) {
if (all(names(S) %in% phy$tip.label)) S <- S[phy$tip.label]
else warning('the names of argument "S" and the names of the tip labels
-## branching.times.R (2006-10-04)
+## branching.times.R (2009-05-10)
## Branching Times of a Phylogenetic Tree
-## Copyright 2002-2006 Emmanuel Paradis
+## Copyright 2002-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
branching.times <- function(phy)
{
### the tree must be in cladewise order
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo"')
n <- length(phy$tip.label)
N <- dim(phy$edge)[1]
-## cherry.R (2006-10-03)
+## cherry.R (2009-05-10)
## Number of Cherries and Null Models of Trees
-## Copyright 2002-2006 Emmanuel Paradis
+## Copyright 2002-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
cherry <- function(phy)
{
- if (class(phy) != "phylo") stop("object \"phy\" is not of class \"phylo\"")
+ if (!inherits(phy, "phylo")) stop('object "phy" is not of class "phylo"')
n <- length(phy$tip.label)
nb.node <- phy$Nnode
- if (nb.node != n - 1) stop("\"phy\" is not fully dichotomous")
+ if (nb.node != n - 1) stop('"phy" is not fully dichotomous')
if (n < 4) stop("not enough tips in your phylogeny for this analysis")
cherry <- sum(tabulate(phy$edge[, 1][phy$edge[, 2] <= n]) == 2)
small.n <- n < 20
f.cherry.yule <- function(n, k)
{
- P <- if (k == 0 || k > floor(n/2)) 0 else if (n == 4) if (k == 1) 2/3 else if (k == 2) 1/3 else 0
- else (1 - 2*(k - 1)/(n - 1))*f.cherry.yule(n - 1, k - 1) +
- 2*k/(n - 1)*f.cherry.yule(n - 1, k)
- P
+ if (k == 0 || k > floor(n/2)) 0 else if (n == 4) if (k == 1) 2/3 else if (k == 2) 1/3 else 0
+ else (1 - 2*(k - 1)/(n - 1))*f.cherry.yule(n - 1, k - 1) +
+ 2*k/(n - 1)*f.cherry.yule(n - 1, k)
}
f.cherry.uniform <- function(n, k)
{
- P <- if (k == 0 || k > floor(n/2)) 0 else if (n == 4) if (k == 1) 4/5 else if (k == 2) 1/5 else 0
- else if (k == 1) 0 else (gamma(n + 1)*gamma(n - 2 + 1)*gamma(n - 4 + 1) * 2^(n-2*k)) /
- (gamma(n - 2*k + 1)*gamma(2*n - 4 + 1)*gamma(k + 1)*gamma(k - 2 + 1))
- P
+ if (k == 0 || k > floor(n/2)) 0 else if (n == 4) if (k == 1) 4/5 else if (k == 2) 1/5 else 0
+ else if (k == 1) 0 else (gamma(n + 1)*gamma(n - 2 + 1)*gamma(n - 4 + 1) * 2^(n-2*k)) /
+ (gamma(n - 2*k + 1)*gamma(2*n - 4 + 1)*gamma(k + 1)*gamma(k - 2 + 1))
}
-## compar.ou.R (2006-10-05)
+## compar.ou.R (2009-05-10)
## Ornstein--Uhlenbeck Model for Continuous Characters
-## Copyright 2005-2006 Emmanuel Paradis
+## Copyright 2005-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
compar.ou <- function(x, phy, node = NULL, alpha = NULL)
{
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo".')
if (!is.numeric(x)) stop("'x' must be numeric.")
if (!is.null(names(x))) {
-## dist.topo.R (2008-07-18)
+## dist.topo.R (2009-05-10)
## 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.
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)
-## drop.tip.R (2009-03-22)
+## drop.tip.R (2009-05-10)
## Remove Tips in a Phylogenetic Tree
drop.tip <-
function(phy, tip, trim.internal = TRUE, subtree = FALSE, root.edge = 0)
{
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo"')
phy <- reorder(phy)
Ntip <- length(phy$tip.label)
-## gammaStat.R (2006-10-04)
+## gammaStat.R (2009-05-10)
## Gamma-Statistic of Pybus and Harvey
-## Copyright 2002-2006 Emmanuel Paradis
+## Copyright 2002-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
gammaStat <- function(phy)
{
- if (class(phy) != "phylo") stop('object "phy" is not of class "phylo"')
+ if (!inherits(phy, "phylo")) stop('object "phy" is not of class "phylo"')
N <- length(phy$tip.label)
bt <- sort(branching.times(phy))
g <- rev(c(bt[1], diff(bt))) # internode intervals are from past to present
## is.binary.tree.R (2002-09-12) [modified by EP 2005-05-31, 2005-08-18,
-## 2006-10-04]
+## 2006-10-04, 2009-05-10]
## Tests whether a given phylogenetic tree is binary
is.binary.tree <- function(phy)
{
- if (class(phy) != "phylo") stop('object "phy" is not of class "phylo"')
+ if (!inherits(phy, "phylo")) stop('object "phy" is not of class "phylo"')
## modified by EP so that it works without edge lengths too (2005-05-31):
nb.tip <- length(phy$tip.label)
nb.node <- phy$Nnode
-## is.ultrametric.R (2009-03-09)
+## is.ultrametric.R (2009-05-10)
## Test if a Tree is Ultrametric
is.ultrametric <- function(phy, tol = .Machine$double.eps^0.5)
{
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo".')
if (is.null(phy$edge.length))
stop("the tree has no branch lengths.")
klastorin <- function(phy)
{
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop("object \"phy\" is not of class \"phylo\"")
## added by EP for the new coding of "phylo" (2006-10-04):
phy <- new2old.phylo(phy)
-## ltt.plot.R (2008-12-20)
+## ltt.plot.R (2009-05-10)
## Lineages Through Time Plot
-## Copyright 2002-2008 Emmanuel Paradis
+## Copyright 2002-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
ltt.plot <- function(phy, xlab = "Time", ylab = "N", ...)
{
- if (class(phy) != "phylo") stop('object "phy" is not of class "phylo"')
+ if (!inherits(phy, "phylo")) stop('object "phy" is not of class "phylo"')
if (!is.binary.tree(phy)) phy <- multi2di(phy)
time <- sort(branching.times(phy), decreasing = TRUE)
N <- 1:(length(time) + 1)
y <- 1:length(x)
cbind(x, y)
}
- if (class(phy) == "phylo") {
+ if if (inherits(phy, "phylo")) { # if a tree of class "phylo"
TREES <- list(ltt.xy(phy))
names(TREES) <- deparse(substitute(phy))
} else { # a list of trees
-## mrca.R (2006-10-12)
+## mrca.R (2009-05-10)
## Find Most Recent Common Ancestors Between Pairs
-## Copyright 2005-2006 Emmanuel Paradis
+## Copyright 2005-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
mrca <- function(phy, full = FALSE)
{
- if (class(phy) != "phylo") stop('object "phy" is not of class "phylo"')
+ if (!inherits(phy, "phylo")) stop('object "phy" is not of class "phylo"')
## if (!is.rooted(phy)) stop("the tree must be rooted.")
## Get all clades:
nb.tip <- length(phy$tip.label)
-## pic.R (2006-10-29)
+## pic.R (2009-05-10)
## Phylogenetically Independent Contrasts
-## Copyright 2002-2006 Emmanuel Paradis
+## Copyright 2002-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
pic <- function(x, phy, scaled = TRUE, var.contrasts = FALSE)
{
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop("object 'phy' is not of class \"phylo\"")
if (is.null(phy$edge.length))
stop("your tree has no branch lengths: you may consider setting them equal to one, or using the function `compute.brlen'.")
-## root.R (2008-06-12)
+## root.R (2009-05-10)
## Root of Phylogenetic Trees
-## Copyright 2004-2008 Emmanuel Paradis
+## Copyright 2004-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
is.rooted <- function(phy)
{
- if (!"phylo" %in% class(phy))
+ if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo"')
if (!is.null(phy$root.edge)) return(TRUE)
else
unroot <- function(phy)
{
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo"')
if (dim(phy$edge)[1] < 3)
stop("cannot unroot a tree with two edges.")
root <- function(phy, outgroup, node = NULL, resolve.root = FALSE)
{
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo"')
ord <- attr(phy, "order")
if (!is.null(ord) && ord == "pruningwise") phy <- reorder(phy)
}
# function starts here
# definitions
- if (class(phy) != "phylo") # is phy of class phylo?
+ if (!inherits(phy, "phylo")) # is phy of class phylo?
stop("object \"phy\" is not of class \"phylo\"")
nb.tips <- length(phy$tip.label) # number of tiplabels
max.int.node <- phy$Nnode+nb.tips # number of last internal node
-## summary.phylo.R (2008-04-22)
+## summary.phylo.R (2009-05-10)
## Print Summary of a Phylogeny
-## Copyright 2003-2008 Emmanuel Paradis, and 2006 Ben Bolker
+## Copyright 2003-2009 Emmanuel Paradis, and 2006 Ben Bolker
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
Ntip <- function(phy)
{
- if (class(phy) != "phylo")
- stop('object "phy" is not of class "phylo"')
+ if (!inherits(phy, "phylo"))
+ stop('object "phy" is not of class "phylo"')
length(phy$tip.label)
}
Nnode <- function(phy, internal.only = TRUE)
{
- if (class(phy) != "phylo")
- stop('object "phy" is not of class "phylo"')
+ if (!inherits(phy, "phylo"))
+ stop('object "phy" is not of class "phylo"')
if (internal.only) return(phy$Nnode)
phy$Nnode + length(phy$tip.label)
}
Nedge <- function(phy)
{
- if (class(phy) != "phylo")
- stop('object "phy" is not of class "phylo"')
+ if (!inherits(phy, "phylo"))
+ stop('object "phy" is not of class "phylo"')
dim(phy$edge)[1]
}
"[.multiPhylo" <- function(x, i)
{
+ oc <- oldClass(x)
class(x) <- NULL
structure(x[i], TipLabel = attr(x, "TipLabel"),
- class = "multiPhylo")
+ class = oc)
}
str.multiPhylo <- function(object, ...)
-## vcv.phylo.R (2006-10-04)
+## vcv.phylo.R (2009-05-10)
## Phylogenetic Variance-Covariance or Correlation Matrix
-## Copyright 2002-2006 Emmanuel Paradis
+## Copyright 2002-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
vcv.phylo <- function(phy, model = "Brownian", cor = FALSE)
{
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo"')
if (is.null(phy$edge.length))
stop("the tree has no branch lengths")
-## which.edge.R (2007-09-11)
+## which.edge.R (2009-05-10)
## Identifies Edges of a Tree
-## Copyright 2004-2007 Emmanuel Paradis
+## Copyright 2004-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
which.edge <- function(phy, group)
{
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop('object "phy" is not of class "phylo"')
if (is.character(group))
group <- which(phy$tip.label %in% group)
-## write.dna.R (2008-07-03)
+## write.dna.R (2009-05-10)
## Write DNA Sequences in a File
-## Copyright 2003-2008 Emmanuel Paradis
+## Copyright 2003-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
{
format <- match.arg(format, c("interleaved", "sequential", "fasta"))
phylip <- if (format %in% c("interleaved", "sequential")) TRUE else FALSE
- if (class(x) == "DNAbin") x <- as.character(x)
+ if (inherits(x, "DNAbin")) x <- as.character(x)
aligned <- TRUE
if (is.matrix(x)) {
N <- dim(x)
-## write.tree.R (2009-03-23)
+## write.tree.R (2009-05-10)
## Write Tree File in Parenthetic Format
}
if (output.tree.names)
names(tree) <- checkLabel(names(tree))
- if (class(phy) == "multiPhylo") {
+ if (inherits(phy, "multiPhylo")) {
write.tree(phy[[1]], file = file, append = append,
digits = digits, tree.names = names[1])
if (length(phy) > 1)
append = TRUE, digits = digits, tree.names = names(phy)[i])
return(invisible(NULL))
}
- if (class(phy) != "phylo")
+ if (!inherits(phy, "phylo"))
stop("object \"phy\" is not of class \"phylo\"")
brl <- !is.null(phy$edge.length)
nodelab <- !is.null(phy$node.label)
base.freq = NULL, as.matrix = FALSE)
}
\arguments{
- \item{x}{a matrix or a list containing the DNA sequences.}
+ \item{x}{a matrix or a list containing the DNA sequences; this must be
+ of class \code{"DNAbin"} (use \code{\link{as.DNAbin}} is they are
+ stored as character).}
\item{model}{a character string specifying the evlutionary model to be
used; must be one of \code{"raw"}, \code{"N"}, \code{"JC69"},
\code{"K80"} (the default), \code{"F81"}, \code{"K81"},