From 304bb23683e7606ad96a7cad5609515c77be2e54 Mon Sep 17 00:00:00 2001 From: paradis Date: Thu, 14 May 2009 08:19:05 +0000 Subject: [PATCH] faster rcoal... at last! git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@73 6e262413-ae40-0410-9e79-b911bd7a66b7 --- ChangeLog | 2 ++ DESCRIPTION | 2 +- R/rtree.R | 17 +++++++++-------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index d76cb8d..9191a65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,8 @@ OTHER CHANGES o Instances of the form class(phy) == "phylo" have been replaced by inherits(phy, "phylo"). + o rcoal() should be faster. + CHANGES IN APE VERSION 2.3 diff --git a/DESCRIPTION b/DESCRIPTION index eeb4b87..54665c2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ape Version: 2.3-1 -Date: 2009-05-10 +Date: 2009-05-13 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 diff --git a/R/rtree.R b/R/rtree.R index 9425dad..f331ca3 100644 --- a/R/rtree.R +++ b/R/rtree.R @@ -1,8 +1,8 @@ -## rtree.R (2008-05-07) +## rtree.R (2000-05-13) ## Generates Random 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. @@ -113,7 +113,7 @@ rcoal <- function(n, tip.label = NULL, br = "coalescent", ...) edge.length <- rep(x, 2) } else if (n == 3) { edge[] <- c(4L, 5L, 5L, 4L, 5L, 1:3) - edge.length <- c(x[2], x[1], x[1], sum(x)) + edge.length <- c(x[c(2, 1, 1)], sum(x)) } else { edge.length <- numeric(nbr) h <- numeric(2*n - 1) # initialized with 0's @@ -132,14 +132,15 @@ rcoal <- function(n, tip.label = NULL, br = "coalescent", ...) } } phy <- list(edge = edge, edge.length = edge.length) - phy$tip.label <- - if (is.null(tip.label)) paste("t", 1:n, sep = "") - else tip.label + if (is.null(tip.label)) + tip.label <- paste("t", 1:n, sep = "") + phy$tip.label <- sample(tip.label) phy$Nnode <- n - 1L class(phy) <- "phylo" - ##reorder(phy) + phy <- reorder(phy) ## to avoid crossings when converting with as.hclust: - read.tree(text = write.tree(phy)) + phy$edge[phy$edge[, 2] <= n, 2] <- 1:n + phy } rmtree <- function(N, n, rooted = TRUE, tip.label = NULL, br = runif, ...) -- 2.39.5