Adding branch lengths

11 views
Skip to first unread message

Yan Wong

unread,
Jun 26, 2014, 7:26:10 AM6/26/14
to bio-...@googlegroups.com
I'm using Bio::Phylo to read in a Newick tree without branch lengths. If I call ultrametricize(), perhaps unsurprisingly I get errors:

Use of uninitialized value in addition (+) at /Library/Perl/5.16/Bio/Phylo/Forest/TreeRole.pm line 2265.


What's the easiest way to assign a default length to all the branches on the tree, before calling ultrametricize()


p.s. I might also have a hacky Newick tree where only some of the branches have lengths. In this case I'd want to assign a default length to any nodes that don't have a length already.

Rutger Vos

unread,
Jun 26, 2014, 8:15:26 AM6/26/14
to bio-...@googlegroups.com
What default value do you have in mind? E.g.:

$value = 1;

$tree->visit(sub{
    my $node = shift;
    $node->set_branch_length( $value ) if not defined $node->get_branch_length;
});


...now all undefined branch lengths have been set to 1.


--
You received this message because you are subscribed to the Google Groups "bio-phylo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bio-phylo+...@googlegroups.com.
To post to this group, send email to bio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/bio-phylo.
For more options, visit https://groups.google.com/d/optout.

Yan Wong

unread,
Jun 26, 2014, 8:24:44 AM6/26/14
to bio-...@googlegroups.com
On Thursday, 26 June 2014 13:15:26 UTC+1, Rutger Vos wrote:
$tree->visit(...

Ah, tat's what I was missing. Ideal, thanks for the quick reply.

Yan
Reply all
Reply to author
Forward
0 new messages