This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Traverse A Newick Tree Bottom-Up?

Hi,

I have a sequence phylogenetic tree in Newick format (with branch lengths). I want to traverse the tree bottom-up in a Perl program and edit merging/splitting of nodes based on additional information. I have not done tree traversal before, hence I need some help/advice. This part of the code will give me a cluster representation of the nodes:

use Bio::TreeIO;
use Bio::Tree::Node;
use Bio::Tree::Tree;
use Bio::Tree::Compatible;
my $input = new Bio::TreeIO(-file   => "tree.fasttree",
                        -format => "newick");
my $tree = $input->next_tree;
map { print "(",join(',',@{$_}),")\n" } values %{Bio::Tree::Compatible::cluster_representation( $tree ) };

I want to know how to use information from the cluster_representation ( Bio::Tree::Compatible::cluster_representation code in http://doc.bioperl.org/bioperl-live/Bio/Tree/Compatible.html ) to traverse the tree bottom_up.

Am I in the right track at all?

phylogenetics tree perl

1 answer

It is not obvious what "bottom-up" traversal means.

Some people call the postorder traversal as "bottom-up", is that what you mean? If so you are in luck as the class offers a postorder_traversal method.

http://doc.bioperl.org/bioperl-live/Bio/Tree/Compatible.html#CODE1

Log in to answer this question.