[Phylobase-devl] reorder in ape and phylobase

Klaus Schliep kpschlie at pop3.massey.ac.nz
Fri Aug 1 09:11:49 CEST 2008


Hi all, hi Peter,

I think reorder in ape works slightly different than you expect. 'reorder' 
does not change the
numbering of the nodes and I think this is a desirable property. It only 
changes the order of
the rows of edge matrix to make it easy to traverse the tree.
For a tree bar with 5 taxa, node i has label bar$node.label[i - 5],
the same is done with the tip.label, but you do not have to substract the 
number of taxa.

A problem with this approach is, that you can not easily delete edges or 
taxa, without changing all
the node/tip labels of the tree, or it will be difficult to keep track of 
the labels.
A solution is to assign a label to each node or tip seperately. This will 
also work
if you have a bunch of trees which have tip labels overlapping but not 
necessary the same for all
trees (e.g. for supertree methods). (Having common node labels in this case 
is less likely)

You can easily combine the tip and nodelabels, but you can't put them in 
the same order as the edge
matrix, as you always have one node more than you have edges on a tree.

Some other remarks:
I think there should be another slot in phylo4, which indicates if the edge 
matrix is
in pruningwise order, cladewise order or unordered. The ape 'reorder' seem 
to work only for the first two,
otherwise it can crash R. phylo has such a slot, but only after it got 
reordered.
An unordered edge matrix is common, especially if you perform tree 
rearrangements like NNI, SPR or TBR.

Generally I think the phylo4 and phylo objects are good for traversing the 
trees for plotting,
parsimony or likelihood computations. If you want to add taxa, or subtrees 
or tree walking in my opinion
it would be much better to have a representation on a (preferably sparse) 
incident matrix,
or some table where can look up fast the children or parents of a node.

I have some function which do the reordering for phylo objects which you 
can reuse from
my phangorn package (version 0.0-2). They are hidden by the namespace 
(that's why you need :::),
these are the functions if you want to have a look:
phangorn:::phyloPruning, phangorn:::phyloClade, 
phangorn:::as.phylo.phyloNode, phangorn:::as.phyloNode.phylo

These two functions will do the reordering for a phylo object:

as.phylo.phyloNode(as.phyloNode.phylo(tree), order = "pruningwise")
as.phylo.phyloNode(as.phyloNode.phylo(tree), order = "cladewise")

They will also work if the edge matrix is out of order (that's the reason 
why I programmed them).
The reordered trees can have a different order than the one from reorder of 
ape, since the (circular) ordering
is not unique for a tree.
It should be straight forward to make it work for phylo4. I will upload 
some code the next days.

Cheers,
Klaus






>Hi all,
>
>I'm trying to write some reorder functions for phylo4 and phylo4d
>objects, similar to what ape already has.  Unfortunately, I've found
>that it is difficult to keep the names straight.  Particularly the
>node names.
>
>Right now there are two different label slots, one for tips and one
>for nodes, this follows the ape convention.  I recommend combining
>them into one slot that is in the same order as the edge matrix.  Any
>objections to this?  Any volunteers to do it?
>
>Otherwise it's difficult to track where a particular node label
>belongs, see the following example from ape.
>
>Peter
>
># get a tree
>foo <- rcoal(5)
>
># reorder in two different ways
>bar <- reorder.phylo(foo, order = 'cladewise')
>xan <- reorder.phylo(foo, order = 'pruningwise')
>
># add node labels
>bar$node.label <- letters[1:4]
>xan$node.label <- letters[1:4]
>
># the labels plot in the same places, even though they should
># have referenced different nodes, as the two trees were in different order
># either that ape has an undocumented required node order
>plot(bar, show.node.label = T)
>plot(xan, show.node.label = T)

Klaus Schliep
Doctoral Student
Allan Wilson Centre for Molecular Ecology and Evolution, and
Institute of Molecular BioSciences
Massey University
Palmerston North
New Zealand
Ph: +64 6 350 5515 ext. 2569



More information about the Phylobase-devl mailing list