[Phylobase-devl] edge matrix ordering in phylobase and ape

Emmanuel Paradis Emmanuel.Paradis at mpl.ird.fr
Mon Jan 5 15:53:49 CET 2009


Ben,

I suggest solution "a." in all cases.

Currently the attr(, "order") is not enforced in ape, but in practice I 
found only "cladewise" and "pruningwise" to be useful. Thus the likely 
evolution is that this attribute will be generalised and set whenever 
possible, but still leaving the possibility of it being NULL or another 
value.

Yes, "pruningwise" order is not postorder but 'bottom-up order'; it 
seems that both orders are suitable for pruning calculations. It's not 
excluded to change in the future, but bottom-up order works well for the 
moment. So if "postorder" in "phylo4" is a genuine postorder, then 
setting "unknown" when importing an object of class "phylo" in 
"pruningwise" order seems safer.

About the bug you mention below, it's because the code of reorder.phylo 
needs to be improved. reorder(x, "cladewise") seems pretty robust, but 
not so for "pruningwise" (which is called by plot.phylo). So you may fix 
your permtree() with:

permtree <- function(phy) {
   phy$edge <- phy$edge[sample(nrow(phy$edge)),]
   reorder(phy)
}

AFAIK, this is not much a problem in practice, but I'll fix the problem 
in reorder.phylo().

Best wishes for 2009.

Emmanuel

Le 30.12.2008 21:40, Ben Bolker a écrit :
>   Emmanuel, [cc'd to phylobase devel list]
> 
>   we (the phylobase group) are having some discussions about
> edge matrix ordering.  The parts about what is safe (and not
> safe) to import from/export to ape would benefit from your
> input.
> 
>    At the moment our rules for edge matrix ordering
> in phylobase are that any order is allowed (nominally the
> same as in ape, although see below).  Node ID numbers must
> follow the same rule as in ape (1:m are tips, m+1 is the
> root if there is one, m+2 ... m+n are internal).
> The phylo4[d] object also has an additional slot describing
> the order, which (at the moment) can be "unknown" (default),
> "preorder" (="cladewise" in ape) or "postorder" (almost="pruningwise"
> in ape).  We are somewhat divided about what to do on import from/
> export to ape.
> 
>   import:
>    if $order is NULL in the phylo object (i.e., not explicitly
> specified):
>      a. set @order to "unknown" (most conservative)
>      b. set @order to "cladewise" (probably true by default
>           since things break in ape otherwise?  see below)
> 
>   if $order=="cladewise"
>      set @order to "preorder" (a no-brainer)
> 
>   if $order=="pruningwise"
>      a. set to "unknown" (at the moment we don't allow "pruningwise")
>         [this loses information]
>      b. set to "postorder" (not really true!)
>      c. allow "pruningwise" as an option in phylobase
> 
>   export:
>     if @order is "unknown"
>      a. don't rearrange edge matrix (allows flexibility in edge matrix
> ordering  -- e.g. some packages other than ape might explicitly want
> non-cladewise ordering -- but dangerous since such trees can crash
> plot.tree).  Leave $order NULL
>      b. enforce preorder/cladewise ordering (safer -- but makes
> it hard to export trees in any other order
>         b1. set $order to "cladewise"
>         b2. leave $order NULL
> 
>   b1 will break round-trip capability
> (i.e.  identical(phy,as(as(phy,"phylo4"),"phylo")) will be FALSE) even
> for trees that start out cladewise ordering but with $order NULL
> 
>   What do you think??
> 
> ---------------
>    The ape nodeId rules (which we do follow) are (tips, int.nodes); the
> ape API <ape.mpl.ird.fr/misc/FormatTreeR_28July2008.pdf> says
> "There is no mandatory order for the rows of edge, but they may be
> arranged in a way that is efficient for computation and manipulation.",
> but I have some reason to suspect that's not true.  For example, this code
> 
> library(ape)
> example("read.tree")
> set.seed(1001)
> tt <- tree.owls
> 
> permtree <- function(phy) {
>   phy$edge <- phy$edge[sample(nrow(phy$edge)),]
>   phy
> }
> 
> for (i in 1:40) {
>   cat(i,"\n")
>   ttp <- permtree(tt)
>   plot(ttp)
> }
> 
>   hangs R in an infinite loop on the second try ...
>   I don't know whether pruningwise (or anything other
> than cladewise will do it) ...
> 

-- 
Emmanuel Paradis
IRD, Montpellier, France
   ph: +33 (0)4 67 16 64 47
  fax: +33 (0)4 67 16 64 40
http://ape.mpl.ird.fr/


More information about the Phylobase-devl mailing list