[Phylobase-devl] reorder in ape and phylobase

Peter Cowan pdc at berkeley.edu
Sat Aug 2 02:21:59 CEST 2008


Klaus,

> 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.

Yes, I think I was misunderstanding a bit.  However, if my
understanding is correct there is code in phylobase which depends on
the edge matrix being in a particular order (e.g. the summary
methods).  So to allow the edge matrix to be reorder these commands
would need to be updated to look up the proper labels.

> 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)

Yes, this appears to be how the problem is handled in the prune
command, assign a set of labels, do the deletions and then match the
labels afterwards.

> 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.

This is an interesting idea, is the idea that one wouldn't have to
reorder a tree that's already in the proper order, saving some
computation, are there other benefits?

> 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 apologize, but I'm ignorant of the incident matrix representation,
could you provide a small example?

> 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.

Thanks!  I've already written a pruningwise ordering, but I'll take a
look at what you have, especially the cladewsise ordering.

Peter

>>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
>
> _______________________________________________
> Phylobase-devl mailing list
> Phylobase-devl at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/phylobase-devl
>


More information about the Phylobase-devl mailing list