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

longbow leo longbow0 at gmail.com
Tue Apr 10 04:40:16 UTC 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:

(((A:0.02,B:0.025):0.12,C:0.071):0.34,D:0.6);

Tree 2:

(((A:2e-2,B:2.5e-2):1.2e-1,C:7.1e-2):3.4e-1,D:6e-1);

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

The Perl script:

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

#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

use Bio::TreeIO;

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

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?

Thanks!

Haizhou



More information about the Bioperl-l mailing list