[Bioperl-l] Turning the tree into bifurcating one

Jason Stajich jason.stajich at duke.edu
Fri Apr 1 13:01:45 EST 2005

Sure just test if a node has more than 2 children, randomly choose 2 of 
the children and insert a new parent for them, insert a pseudo node. 
Walk from the root to the tips.  Works for me for a star phylogeny too. 
  This is somewhat untested though so it may not work in all situations 
but I hope it gets you started.

use Bio::TreeIO;
my $in =Bio::TreeIO->new(-format=> 'newick', -file => $treefile);
my $out = Bio::TreeIO->new(-format => 'newick');
while( my $tree = $in->next_tree ) {
     my @internal = grep { ! $_->is_Leaf } $tree->get_nodes;
     for my $node (  @internal ) {
	my @children = $node->each_Descendent;
	while( @children > 2 ) {
	    my $left = shift @children;
	    my $right = shift @children;
	    my $new_node =Bio::Tree::Node->new();
	    push @children, $new_node;

Jason Stajich
jason.stajich at duke.edu

On Mar 30, 2005, at 12:02 PM, Babenko, Vladimir (NIH/NLM/NCBI) wrote:

>     Greetings,
> Is there any possible solution to insert some pseudo-nodes into the 
> tree to
> make it bufurkating?
>    Some programs can deal only with bifurkating ones...
>   Thank you,
>         Vladimir
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l

More information about the Bioperl-l mailing list