[Bioperl-l] scale branch lengths of a tree to sum 1

Albert Vilella avilella at gmail.com
Fri Oct 27 13:39:41 UTC 2006


I respond to myself: I think I found the way:

my $tree = $treeio->next_tree;
my $total_branch_length = 0;
foreach my $node ($tree->get_nodes) {
    $total_branch_length += $node->branch_length;
}
foreach my $node ($tree->get_nodes) {
    my $branch_length = $node->branch_length;
    next unless (defined($branch_length));
    $node->branch_length($branch_length/$total_branch_length);
    1;
}

my $new_branch_length;
foreach my $node ($tree->get_nodes) {
    $new_branch_length += $node->branch_length;
}
1;

On 10/27/06, Albert Vilella <avilella at gmail.com> wrote:
> Hi all,
>
> I am in need of a method that would scale the different branch lengths
> of a tree so that after the scaling they all sum up to exactly 1.
>
> Any pointers? Has anyone done that before?
>
> Thanks in advance,
>
>     Albert.
>



More information about the Bioperl-l mailing list