From fab4946bb5d41cd408dffd4b66aae8a697690cfa Mon Sep 17 00:00:00 2001 From: paradis Date: Tue, 14 Feb 2012 04:15:37 +0000 Subject: [PATCH] a fix in cophyloplot() git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@178 6e262413-ae40-0410-9e79-b911bd7a66b7 --- DESCRIPTION | 4 ++-- NEWS | 17 ++++++++++++++++ R/bind.tree.R | 12 +++++++----- R/cophyloplot.R | 8 ++------ R/plotPhyloCoor.R | 5 +++-- R/root.R | 4 ++-- man/bind.tree.Rd | 11 +++++++++++ src/dist_dna.c | 50 +++++++++++++++++++++++++---------------------- 8 files changed, 71 insertions(+), 40 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9f97add..6ad0dbc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ape -Version: 3.0 -Date: 2012-02-10 +Version: 3.0-1 +Date: 2012-02-14 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 diff --git a/NEWS b/NEWS index 0a4293e..53eb924 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,20 @@ + CHANGES IN APE VERSION 3.0-1 + + +NEW FEATURES + + o bind.tree() now accepts 'position' > 0 when the trees have no + banch lengths permitting to create a node in 'x' when grafting + 'y' (see ?bind.tree for details). + + +BUG FIXES + + o cophyloplot( , rotate = TRUE) made R hanged after a few clicks. + Also the tree is no more plotted twice. + + + CHANGES IN APE VERSION 3.0 diff --git a/R/bind.tree.R b/R/bind.tree.R index cc7ee1f..b43ce90 100644 --- a/R/bind.tree.R +++ b/R/bind.tree.R @@ -1,8 +1,8 @@ -## bind.tree.R (2011-06-21) +## bind.tree.R (2012-02-13) ## Bind Trees -## Copyright 2003-2011 Emmanuel Paradis +## Copyright 2003-2012 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -63,9 +63,11 @@ bind.tree <- function(x, y, where = "root", position = 0, interactive = FALSE) ## case = 3 -> y is bound on a node of x ## check that 'position' is correct - if (position) { - if (!wbl) - stop("'position' is non-null but trees have no branch lengths") + if (position && wbl) { +### New in ape 3.0-1: this makes possible binding 'y' below +### a node of 'x' thus creating a new node in 'x' +### if (!wbl) +### stop("'position' is non-null but trees have no branch lengths") if (case == 1) { if (xHasNoRootEdge) stop("tree 'x' has no root edge") diff --git a/R/cophyloplot.R b/R/cophyloplot.R index faf9e34..85f091f 100644 --- a/R/cophyloplot.R +++ b/R/cophyloplot.R @@ -1,4 +1,4 @@ -## cophyloplot.R (2010-03-18) +## cophyloplot.R (2012-02-14) ## Plots two phylogenetic trees face to ## face with the links between the tips @@ -29,14 +29,10 @@ cophyloplot <- if (click < length(res$a[, 1]) + 1) { if (click > res$N.tip.x) x <- rotate(x, click) - } - else if (click < length(res$c[, 1]) + 1) { + } else if (click < length(res$c[, 1]) + 1) { if (click > length(res$a[, 1]) + res$N.tip.y) y <- rotate(y, click - length(res$a[, 1])) } - plotCophylo2(x, y, assoc = assoc, use.edge.length = use.edge.length, - space = space, length.line = length.line, gap = gap, - type = type, return = TRUE, col = col, lwd=lwd, lty=lty, show.tip.label = show.tip.label, font = font) } on.exit(print("done")) } diff --git a/R/plotPhyloCoor.R b/R/plotPhyloCoor.R index 8ede4df..35f9ae4 100644 --- a/R/plotPhyloCoor.R +++ b/R/plotPhyloCoor.R @@ -1,4 +1,4 @@ -## plotPhyloCoor.R (2008-04-30) +## plotPhyloCoor.R (2012-02-14) ## Coordinates of a Tree Plot @@ -32,7 +32,8 @@ plotPhyloCoor <- } xe <- x$edge - x <- reorder(x, order = "pruningwise") + ## first reorder the tree in cladewise order to avoid cophyloplot() hanging: + x <- reorder(reorder(x), order = "pruningwise") ereorder <- match(x$edge[, 2], xe[, 2]) if (phyloORclado) { diff --git a/R/root.R b/R/root.R index 8526b8f..8c1d9b2 100644 --- a/R/root.R +++ b/R/root.R @@ -31,7 +31,7 @@ unroot <- function(phy) ## eventually adding the branch length to the other one ## also coming from the root. ## In all cases, the node deleted is the 2nd one (numbered - ## nb.tip+2 in `edge'), so we simply need to renumber the + ## nb.tip+2 in 'edge'), so we simply need to renumber the ## nodes by adding 1, except the root (this remains the ## origin of the tree). nb.tip <- length(phy$tip.label) @@ -57,7 +57,7 @@ unroot <- function(phy) } phy$Nnode <- phy$Nnode - 1L if (!is.null(phy$node.label)) - phy$node.label <- phy$node.label[-2] + phy$node.label <- phy$node.label[-2] phy } diff --git a/man/bind.tree.Rd b/man/bind.tree.Rd index f7de459..b1e9908 100644 --- a/man/bind.tree.Rd +++ b/man/bind.tree.Rd @@ -35,6 +35,17 @@ bind.tree(x, y, where = "root", position = 0, interactive = FALSE) bind.tree(x, y, position = if (is.null(x$root.edge)) 0 else x$root.edge) } + + If only one of the trees has no branch length, the branch lengths of + the other one are ignored with a warning. + + If one (or both) of the trees has no branch length, it is possible to + specify a value of 'position' to graft 'y' below the node of 'x' + specified by 'where'. In this case, the exact value of 'position' is + not important as long as it is greater than zero. The new node will be + multichotomous if 'y' has no root edge. This can be solved by giving + an arbitrary root edge to 'y' beforehand (e.g., \code{y$root.edge <- + 1}): it will be deleted during the binding operation. } \value{ an object of class \code{"phylo"}. diff --git a/src/dist_dna.c b/src/dist_dna.c index 7174af6..61f32d2 100644 --- a/src/dist_dna.c +++ b/src/dist_dna.c @@ -1,4 +1,4 @@ -/* dist_dna.c 2012-01-10 */ +/* dist_dna.c 2012-02-13 */ /* Copyright 2005-2012 Emmanuel Paradis @@ -73,6 +73,9 @@ double detFourByFour(double *x) }\ if (IsPyrimidine(x[s1]) && IsPyrimidine(x[s2])) Ns++; + + + void distDNA_TsTv(unsigned char *x, int *n, int *s, double *d, int Ts, int pairdel) { int i1, i2, s1, s2, target, Nd, Ns; @@ -81,7 +84,7 @@ void distDNA_TsTv(unsigned char *x, int *n, int *s, double *d, int Ts, int paird for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Ns = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { if (pairdel && !(KnownBase(x[s1]) && KnownBase(x[s2]))) continue; COUNT_TS_TV } @@ -100,7 +103,7 @@ void distDNA_raw(unsigned char *x, int *n, int *s, double *d, int scaled) for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) if (DifferentBase(x[s1], x[s2])) Nd++; if (scaled) d[target] = ((double) Nd / *s); else d[target] = ((double) Nd); @@ -117,7 +120,7 @@ void distDNA_raw_pairdel(unsigned char *x, int *n, int *s, double *d, int scaled for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = L = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { CHECK_PAIRWISE_DELETION if (DifferentBase(x[s1], x[s2])) Nd++; } @@ -150,7 +153,7 @@ void distDNA_JC69(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) if (DifferentBase(x[s1], x[s2])) Nd++; COMPUTE_DIST_JC69 target++; @@ -233,7 +236,7 @@ void distDNA_K80_pairdel(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Ns = L = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { CHECK_PAIRWISE_DELETION COUNT_TS_TV } @@ -285,7 +288,7 @@ void distDNA_F81_pairdel(unsigned char *x, int *n, int *s, double *d, double *BF for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = L = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { CHECK_PAIRWISE_DELETION if (DifferentBase(x[s1], x[s2])) Nd++; } @@ -332,7 +335,7 @@ void distDNA_K81(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Nv1 = Nv2 = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { COUNT_TS_TV1_TV2 } COMPUTE_DIST_K81 @@ -351,7 +354,7 @@ void distDNA_K81_pairdel(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Nv1 = Nv2 = L = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { CHECK_PAIRWISE_DELETION COUNT_TS_TV1_TV2 } @@ -392,7 +395,7 @@ void distDNA_F84(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Ns = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { COUNT_TS_TV } COMPUTE_DIST_F84 @@ -413,7 +416,7 @@ void distDNA_F84_pairdel(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Ns = L = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { CHECK_PAIRWISE_DELETION COUNT_TS_TV } @@ -449,7 +452,7 @@ void distDNA_T92(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Ns = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { COUNT_TS_TV } COMPUTE_DIST_T92 @@ -470,7 +473,7 @@ void distDNA_T92_pairdel(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Ns = L = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { CHECK_PAIRWISE_DELETION COUNT_TS_TV } @@ -546,7 +549,7 @@ void distDNA_TN93(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Ns1 = Ns2 = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { COUNT_TS1_TS2_TV } COMPUTE_DIST_TN93 @@ -568,7 +571,7 @@ void distDNA_TN93_pairdel(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Ns1 = Ns2 = L = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { CHECK_PAIRWISE_DELETION COUNT_TS1_TS2_TV } @@ -610,7 +613,7 @@ void distDNA_GG95(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Ns = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { COUNT_TS_TV } P[target] = ((double) Ns / *s); @@ -686,7 +689,7 @@ void distDNA_GG95_pairdel(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { Nd = Ns = L[target] = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { if (KnownBase(x[s1]) && KnownBase(x[s2])) L[target]++; else continue; COUNT_TS_TV @@ -772,7 +775,7 @@ void distDNA_LogDet(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { for (k = 0; k < 16; k++) Ntab[k] = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { DO_CONTINGENCY_NUCLEOTIDES } COMPUTE_DIST_LogDet @@ -792,7 +795,7 @@ void distDNA_LogDet_pairdel(unsigned char *x, int *n, int *s, double *d, for (i2 = i1 + 1; i2 <= *n; i2++) { for (k = 0; k < 16; k++) Ntab[k] = 0; L = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { CHECK_PAIRWISE_DELETION DO_CONTINGENCY_NUCLEOTIDES } @@ -818,7 +821,7 @@ void distDNA_BH87(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { for (k = 0; k < 16; k++) Ntab[k] = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { DO_CONTINGENCY_NUCLEOTIDES } @@ -916,7 +919,7 @@ void distDNA_ParaLin(unsigned char *x, int *n, int *s, double *d, for (i1 = 1; i1 < *n; i1++) { for (i2 = i1 + 1; i2 <= *n; i2++) { for (k = 0; k < 16; k++) Ntab[k] = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { DO_CONTINGENCY_NUCLEOTIDES } COMPUTE_DIST_ParaLin @@ -960,7 +963,7 @@ void distDNA_ParaLin_pairdel(unsigned char *x, int *n, int *s, double *d, for (i2 = i1 + 1; i2 <= *n; i2++) { L = 0; for (k = 0; k < 16; k++) Ntab[k] = 0; - for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1+= *n, s2 += *n) { + for (s1 = i1 - 1, s2 = i2 - 1; s1 < i1 + *n*(*s - 1); s1 += *n, s2 += *n) { CHECK_PAIRWISE_DELETION DO_CONTINGENCY_NUCLEOTIDES } @@ -1115,6 +1118,7 @@ void dist_dna(unsigned char *x, int *n, int *s, int *model, double *d, else distDNA_TsTv(x, n, s, d, 1, 0); break; case 15 : if (pairdel) distDNA_TsTv(x, n, s, d, 0, 1); else distDNA_TsTv(x, n, s, d, 0, 0); break; - + case 16 : distDNA_indel(x, n, s, d); break; + case 17 : distDNA_indelblock(x, n, s, d); break; } } -- 2.39.2