Re: [R-sig-phylo] post-order tree traversal

2011-09-14 Thread Liam J. Revell

Hi Nick.

If you use the function reorder.phylo(...,order=pruningwise) the 
resultant tree edge matrix is suitable for post-order traversal (i.e., 
the daughters always precede the parents in top-to-bottom matrix 
traversal).  This might be helpful for what you would like to do - for 
instance if you just label the nodes as they are first encountered in 
the matrix this would be in the order of a post-order traversal of the tree.


All the best, Liam

--
Liam J. Revell
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://phytools.blogspot.com

On 9/14/2011 9:23 PM, Nick Matzke wrote:

Hi all,

To display the node reconstructions from another program in APE, I need
to label my internal nodes as they would be labeled in a post-order tree
traversal.

Is there an easy way/function to do this somewhere, or do I have to
write my own tree-traversing functions?

Cheers,
Nick




___
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo


Re: [R-sig-phylo] post-order tree traversal

2011-09-14 Thread Nick Matzke
Thanks...here's the code.  However, it looks like the output 
I am processing does not actually come with post-order 
labeling.


I.e., in the 2nd plot below:

node 1 should be labeled 1
node 10 should be labeled 2
node 2 should be labeled 3
node 14 should be labeled 4
node 3 should be labeled 5
...etc...

What is the name of this sort of ordering?  Or are there 2 
sorts of post-ordering?


Cheers,
Nick



trstr = 
1:61.9979,2:61.9979):10.0994,3:72.0973):30.5957,(4:97.17,5:97.17):5.52294):165.913,(6:45.8837,7:42.7899):90.6427,8:11.748):9.81895,((9:71.9983,10:30.1075):59.5189,(((11:48.3447,12:48.3447):77.8739,(13:86.8531,(14:53.665,15:53.665):33.1881):39.3656):26.0816,((16:94.7537,17:94.7537):44.1509,(18:82.3045,(19:72.9737,20:72.9737):9.33074):56.6002):13.3956):27.9983):10.886):22.824,21:214.009):34.3554,(22:186.877,23:186.877):61.4866):20.2417);


tr = read.tree(file=, text=trstr)
plot(tr)
nodelabels()


tr2 = reorder(tr, order=pruningwise)
plot(tr2)
nodelabels()

internal_nodenums_in_postorder = unique(tr2$edge[,1])
internal_nodenums_in_postorder = 
internal_nodenums_in_postorder - length(tr2$tip.label)


tr3 = tr2
tr3$node.label[internal_nodenums_in_postorder] = 1:tr3$Nnode
plot(tr3)
nodelabels(tr3$node.label)




On 9/14/11 6:36 PM, Liam J. Revell wrote:

Hi Nick.

If you use the function
reorder.phylo(...,order=pruningwise) the resultant tree
edge matrix is suitable for post-order traversal (i.e., the
daughters always precede the parents in top-to-bottom matrix
traversal). This might be helpful for what you would like to
do - for instance if you just label the nodes as they are
first encountered in the matrix this would be in the order
of a post-order traversal of the tree.

All the best, Liam



--

Nicholas J. Matzke
Ph.D. Candidate, Graduate Student Researcher

Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley

Graduate Student Instructor, IB200B
Principles of Phylogenetics: Ecology and Evolution
http://ib.berkeley.edu/courses/ib200b/
http://phylo.wikidot.com/


Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page: 
http://ib.berkeley.edu/people/students/person_detail.php?person=370
Lab personal page: 
http://fisher.berkeley.edu/cteg/members/matzke.html

Lab phone: 510-643-6299
Dept. fax: 510-643-6264

Cell phone: 510-301-0179
Email: mat...@berkeley.edu

Mailing address:
Department of Integrative Biology
3060 VLSB #3140
Berkeley, CA 94720-3140

-
[W]hen people thought the earth was flat, they were wrong. 
When people thought the earth was spherical, they were 
wrong. But if you think that thinking the earth is spherical 
is just as wrong as thinking the earth is flat, then your 
view is wronger than both of them put together.


Isaac Asimov (1989). The Relativity of Wrong. The 
Skeptical Inquirer, 14(1), 35-44. Fall 1989.

http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm

___
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo