From 0d2caf41f13f7a3e8a313274cf819147940eac69 Mon Sep 17 00:00:00 2001 From: paradis Date: Thu, 31 Jan 2013 11:58:31 +0000 Subject: [PATCH] some modifs for ape 3.0-8 git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@206 6e262413-ae40-0410-9e79-b911bd7a66b7 --- DESCRIPTION | 8 ++++---- NAMESPACE | 1 + NEWS | 15 +++++++++++++++ R/ace.R | 13 ++++++++----- R/read.dna.R | 10 ++++------ man/ace.Rd | 15 ++++++++++++++- man/read.dna.Rd | 6 +++--- 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bed8b3d..925db38 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,12 +1,12 @@ Package: ape -Version: 3.0-7 -Date: 2013-01-19 +Version: 3.0-8 +Date: 2013-01-31 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, Andrei-Alin Popescu, Klaus Schliep, Korbinian Strimmer, Damien de Vienne Maintainer: Emmanuel Paradis Depends: R (>= 2.6.0) -Suggests: gee -Imports: gee, nlme, lattice +Suggests: gee, expm +Imports: gee, nlme, lattice, expm ZipData: no Description: ape provides functions for reading, writing, plotting, and manipulating phylogenetic trees, analyses of comparative data in a phylogenetic framework, ancestral character analyses, analyses of diversification and macroevolution, computing distances from allelic and nucleotide data, reading and writing nucleotide sequences, and several tools such as Mantel's test, minimum spanning tree, generalized skyline plots, graphical exploration of phylogenetic data (alex, trex, kronoviz), estimation of absolute evolutionary rates and clock-like trees using mean path lengths and penalized likelihood. Phylogeny estimation can be done with the NJ, BIONJ, ME, MVR, SDM, and triangle methods, and several methods handling incomplete distance matrices (NJ*, BIONJ*, MVR*, and the corresponding triangle method). Some functions call external applications (PhyML, Clustal, T-Coffee, Muscle) whose results are returned into R. License: GPL (>= 2) diff --git a/NAMESPACE b/NAMESPACE index 6951d42..08f0899 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ exportPattern(".+") import(gee, nlme) importFrom(lattice, xyplot, panel.lines, panel.points) importFrom(stats, as.hclust, cophenetic, reorder) +importFrom(expm, expm) S3method(print, phylo) S3method(plot, phylo) diff --git a/NEWS b/NEWS index 6ca4ae5..5f1d758 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,18 @@ + CHANGES IN APE VERSION 3.0-8 + + +NEW FEATURES + + o ace() gains a new option 'use.expm' to use expm() from the + package of the same name in place of matexpo(). + + +BUG FIXES + + o read.dna(, "fasta") may add '\r' in labels: this is fixed. + + + CHANGES IN APE VERSION 3.0-7 diff --git a/R/ace.R b/R/ace.R index 55e32c3..2b9230e 100644 --- a/R/ace.R +++ b/R/ace.R @@ -1,8 +1,8 @@ -## ace.R (2012-06-25) +## ace.R (2013-01-31) ## Ancestral Character Estimation -## Copyright 2005-2012 Emmanuel Paradis and Ben Bolker +## Copyright 2005-2013 Emmanuel Paradis and Ben Bolker ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -21,7 +21,8 @@ ace <- function(x, phy, type = "continuous", method = "ML", CI = TRUE, model = if (type == "continuous") "BM" else "ER", - scaled = TRUE, kappa = 1, corStruct = NULL, ip = 0.1) + scaled = TRUE, kappa = 1, corStruct = NULL, ip = 0.1, + use.expm = FALSE) { if (!inherits(phy, "phylo")) stop('object "phy" is not of class "phylo"') @@ -190,6 +191,8 @@ ace <- function(x, phy, type = "continuous", method = "ML", CI = TRUE, liks[cbind(TIPS, x)] <- 1 phy <- reorder(phy, "pruningwise") + E <- if (use.expm) expm::expm else ape::matexpo + Q <- matrix(0, nl, nl) dev <- function(p, output.liks = FALSE) { if (any(is.nan(p)) || any(is.infinite(p))) return(1e50) @@ -202,8 +205,8 @@ ace <- function(x, phy, type = "continuous", method = "ML", CI = TRUE, anc <- phy$edge[i, 1] des1 <- phy$edge[i, 2] des2 <- phy$edge[j, 2] - v.l <- matexpo(Q * phy$edge.length[i]) %*% liks[des1, ] - v.r <- matexpo(Q * phy$edge.length[j]) %*% liks[des2, ] + v.l <- E(Q * phy$edge.length[i]) %*% liks[des1, ] + v.r <- E(Q * phy$edge.length[j]) %*% liks[des2, ] v <- v.l * v.r comp[anc] <- sum(v) liks[anc, ] <- v/comp[anc] diff --git a/R/read.dna.R b/R/read.dna.R index f898f3b..fb8b54b 100644 --- a/R/read.dna.R +++ b/R/read.dna.R @@ -1,8 +1,8 @@ -## read.dna.R (2013-01-04) +## read.dna.R (2013-01-31) ## Read DNA Sequences in a File -## Copyright 2003-2012 Emmanuel Paradis +## Copyright 2003-2013 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -11,10 +11,8 @@ read.FASTA <- function(file) { sz <- file.info(file)$size x <- readBin(file, "raw", sz) - if (Sys.info()[1] == "Windows") { - icr <- which(x == as.raw(0x0d)) # CR - x <- x[-icr] - } + icr <- which(x == as.raw(0x0d)) # CR + x <- x[-icr] res <- .Call("rawStreamToDNAbin", x, PACKAGE = "ape") names(res) <- sub("^ +", "", names(res)) # to permit phylosim class(res) <- "DNAbin" diff --git a/man/ace.Rd b/man/ace.Rd index 15bd387..101aebf 100644 --- a/man/ace.Rd +++ b/man/ace.Rd @@ -25,7 +25,8 @@ \usage{ ace(x, phy, type = "continuous", method = "ML", CI = TRUE, model = if (type == "continuous") "BM" else "ER", - scaled = TRUE, kappa = 1, corStruct = NULL, ip = 0.1) + scaled = TRUE, kappa = 1, corStruct = NULL, ip = 0.1, + use.expm = FALSE) \method{print}{ace}(x, digits = 4, ...) \method{logLik}{ace}(object, ...) \method{deviance}{ace}(object, ...) @@ -56,6 +57,10 @@ ace(x, phy, type = "continuous", method = "ML", CI = TRUE, structure to be used (this also gives the assumed model).} \item{ip}{the initial value(s) used for the ML estimation procedure when \code{type == "discrete"} (possibly recycled).} + \item{use.expm}{a logical specifying whether to use the package + \pkg{expm} to compute the matrix exponential (relevant only if + \code{type = "d"}). The default is to use the function + \code{matexpo} from \pkg{ape} (see details).} \item{digits}{the number of digits to be printed.} \item{object}{an object of class \code{"ace"}.} \item{k}{a numeric value giving the penalty per estimated parameter; @@ -108,6 +113,14 @@ ace(x, phy, type = "continuous", method = "ML", CI = TRUE, \code{"SYM"} is a symmetrical model (e.g., \code{matrix(c(0, 1, 2, 1, 0, 3, 2, 3, 0), 3)}). If a short-cut is used, the number of states is determined from the data. + + With discrete characters it is necessary to compute the exponential of + the rate matrix. By default (and the only possible choice until + \pkg{ape} 3.0-7) the function \code{\link{matexpo}} in \pkg{ape} is + used. If \code{use.expm = TRUE}, the function + \code{\link[expm]{expm}}, in the package of the same name, is + used. \code{matexpo} is faster but quite inaccurate for large and/or + asymmetric matrices. In case of doubt, use the latter. } \value{ an object of class \code{"ace"} with the following elements: diff --git a/man/read.dna.Rd b/man/read.dna.Rd index 4cf664e..ca0a5c0 100644 --- a/man/read.dna.Rd +++ b/man/read.dna.Rd @@ -129,11 +129,11 @@ cat("CLUSTAL (ape) multiple sequence alignment", "", file = "exdna.txt", sep = "\n") ex.dna3 <- read.dna("exdna.txt", format = "clustal") ### ... and in FASTA format -cat("> No305", +cat(">No305", "NTTCGAAAAACACACCCACTACTAAAANTTATCAGTCACT", -"> No304", +">No304", "ATTCGAAAAACACACCCACTACTAAAAATTATCAACCACT", -"> No306", +">No306", "ATTCGAAAAACACACCCACTACTAAAAATTATCAATCACT", file = "exdna.txt", sep = "\n") ex.dna4 <- read.dna("exdna.txt", format = "fasta") -- 2.39.2