[Bioperl-l] Bio::TreeIO problems parsing bootstrap values in newick format trees

Jason Stajich jason at cgt.duhs.duke.edu
Tue Mar 30 12:03:19 EST 2004


This is because bootstrap values is not an explicit type for newick
format the bootstrap value gets mapped to the id on the subsequence
re-read in.  This won't happen for nhx format.


#!/usr/bin/perl -w
use strict;
use Bio::TreeIO;
use IO::String;

my $in = new Bio::TreeIO(-fh => \*DATA, -format => 'newick');
my $tree = $in->next_tree();
foreach my $n ($tree->get_nodes()) {
    if (!($n->is_Leaf())) {
        $n->bootstrap(int(rand(100)));
    }
}
my $str = IO::String->new();
my $out = new Bio::TreeIO(-format => 'newick', -fh => $str);
$out->write_tree($tree);
print ${$str->string_ref}, "\n";
my $is = IO::String->new(${$str->string_ref});
$in = new Bio::TreeIO(-fh => $is, -format => 'newick');
$tree = $in->next_tree();
foreach my $n ($tree->get_nodes()) {
    if (!($n->is_Leaf()) && $n->id) {
        print "id=",$n->id, " blen=", $n->branch_length || '', " bs=",
	$n->bootstrap || '',"\n";
    }
}

__DATA__
(a:1,(b:1,c:1):1);

$ perl test_newick_bootstrap.pl
((a:1,(b:1,c:1)11:1)32);

id=11 blen=1 bs=
id=32 blen= bs=

I realize there an extra set of parens - this has to do with the
explicit rooting of these trees - I need to work on that at some point so
that trees can be stored as unrooted.

-j

On Tue, 30 Mar 2004, Vamsi wrote:

> Hi,
>
> I am using the Bio::TreeIO module to parse trees but have some
> problems with the bootstrap values. I used the following code to
> place arbitrary bootstrap values at interior nodes of the tree
>
> (a:1,(b:1,c:1):1);
>
> Code used:
> ----------------------------------------------------------------
> use Bio::TreeIO;
>
> my $in = new Bio::TreeIO(-file => $ARGV[0], -format => 'newick');
> my $tree = $in->next_tree();
> foreach my $n ($tree->get_nodes()) {
>     if (!($n->is_Leaf())) {
>         $n->bootstrap(int(rand(100)));
>     }
> }
> my $out = new Bio::TreeIO(-format => 'newick');
> $out->write_tree($tree);
> ----------------------------------------------------------------
>
> The tree created was:
>
> ((a:1,(b:1,c:1)56:1)93);
>
> I then read the tree in again and tried to print the bootstrap values
> using the code:
>
> ----------------------------------------------------------------
> use Bio::TreeIO;
>
> my $in = new Bio::TreeIO(-file => $ARGV[0], -format => 'newick');
> my $tree = $in->next_tree();
> foreach my $n ($tree->get_nodes()) {
>     if (!($n->is_Leaf())) {
>         print $n->bootstrap(),"\n";
>     }
> }
> ----------------------------------------------------------------
>
> and it printed blank lines ...
>
> I guess, it is either printing wrong format trees or parsing them incorrectly.
> Any suggestions?
>
> Thanks,
> Vamsi
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
>

--
Jason Stajich
Duke University
jason at cgt.mc.duke.edu


More information about the Bioperl-l mailing list