[Bioperl-l] How to show branch length value in tree

Roy Chaudhuri roy.chaudhuri at gmail.com
Wed Aug 3 09:58:22 EDT 2011


Hi Shachi,

I don't think you can draw labels on branches using 
Bio::Tree::Draw::Cladogram. However, it will draw node labels, so you 
could copy the branch lengths over to the node ids:

my $obj1 = Bio::Tree::Draw::Cladogram->new(-bootstrap => 1,
                                            -tree    => $t1,
                                            -compact => 0);
for my $node ($tree->get_nodes) {
     $node->id($node->branch_length) if defined $node->branch_length;
}
$obj1->print(-file => "$dir/$stem.eps")

Incidentally, in your script you write the tree out to a file, then read 
it back in using TreeIO. This is unnecessary, you can use $tree directly 
as input to Bio::Tree::Draw::Cladogram.

Alternatively, you could write out a newick file and use non-Bioperl 
software such as njplot or MEGA to draw your tree with labelled branch 
lengths.

Cheers,
Roy.

On 03/08/2011 07:00, Shachi Gahoi wrote:
> Dear All
>
> I am using Bio::Tree modules for constructing and drawing tree. *I am unable
> to show branch length value in tree.
> *
> Please tell me How can I do this, if anybody knows.
>
> Here is my script which i am using...and i also attached generated tree.
>
> Thanks in advance
>
> ################################################################################################
>
> use Bio::AlignIO;
> use Bio::Align::ProteinStatistics;
> use Bio::Tree::DistanceFactory;
> use Bio::TreeIO;
> use Bio::Tree::Draw::Cladogram;
>
> # for a dna alignment
> # can also use ProteinStatistics
>
> my $alnio = Bio::AlignIO->new(-file =>  'ADP.aln', -format=>'clustalw');
>
> my $dfactory = Bio::Tree::DistanceFactory->new(-method =>  'UPGMA');
>
> my $stats = Bio::Align::ProteinStatistics->new;
>
> my $treeout = Bio::TreeIO->new(-format =>  'newick', -file =>'>ADP1.dnd');
>
> while( my $aln = $alnio->next_aln )
> {
>   my $mat = $stats->distance(-method =>  'Kimura', -align  =>  $aln);
>
>   my $tree = $dfactory->make_tree($mat);
>   $treeout->write_tree($tree);
> }
>
> my $dir = shift || '.';
>
> opendir(DIR, $dir) || die $!;
> for my $file ( readdir(DIR) )
> {
>      next unless $file =~ /(\S+)\.dnd$/;
>      my $stem = $1;
>      my $treeio = Bio::TreeIO->new('-format' =>  'newick',
>                                    '-file'   =>  "$dir/$file");
>
>      if( my $t1 = $treeio->next_tree )
> {
>          my $obj1 = Bio::Tree::Draw::Cladogram->new(-bootstrap =>  1,
>                                                     -tree    =>  $t1,
>                                                     -compact =>  0);
>          $obj1->print(-file =>  "$dir/$stem.eps");
>      }
> }
>
> ########################################################################################################
>
>
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l



More information about the Bioperl-l mailing list