[Bioperl-l] Strange behavior of $node->height for scientific notation format branch length

longbow leo longbow0 at gmail.com
Tue Apr 10 00:40:16 EDT 2012

Hi all,

I have encountered a strange behavior while calculating the tree height at
root node.

If the branch length of the tree was in scientific notation format, such as
MrBayes created trees, it is unable to give correct results.

For example,

Tree 1:


Tree 2:


These two trees are identical besides the expression of branch length.

The Perl script:

# ============================================================


use 5.010;
use strict;
use warnings;

use Bio::TreeIO;

my $usage = << "EOS";
Display branch lengths for leave nodes.
  t_branchlen.pl <ftree> [<fmt>]
  <ftree>:  Tree file.
  <fmt>:    Tree format. Optional. Default "newick".

my ($ftre, $fmt) = @ARGV;

die $usage unless ( defined $ftre );

$fmt = 'newick' unless ( defined $fmt);

my $o_treei = Bio::TreeIO->new(
    -file   => $ftre,
    -format => $fmt,

my $o_tree = $o_treei->next_tree;

my @o_leaves = $o_tree->get_leaf_nodes();

say join("\t", ("Node", "Branch Length", "Depth"));

for my $o_node ( @o_leaves ) {
    say $o_node->id, "\t", $o_node->branch_length, "\t", $o_node->depth;

my $o_root = $o_tree->get_root_node;

# say;

say "Root height:\t", $o_root->height;

exit 0;

# ============================================================

For tree 1, the output is:

Node    Branch Length    Depth
A    0.02    0.48
B    0.025    0.485
C    0.071    0.411
D    0.6    0.6
*Root height:    0.6*

For tree 2,

Node    Branch Length    Depth
A    2e-2    0.48
B    2.5e-2    0.485
C    7.1e-2    0.411
D    6e-1    0.6
*Root height:    3*

The interesting thing is, the node depth values are correct, but I have no
idea how the root height calculated.

Are there any ideas to resolve this problem?



More information about the Bioperl-l mailing list