bioperl package Bio::Tree::Tree can't locate object method as_text

417 views Asked by At

I'm trying to use as_text method from Bio::Tree::Tree I get this message: can't locate object method as_text via package Bio::Tree::Tree I'm using the example here

Note that I tried other methods in the same package and they worked normally.

my $input = new Bio::TreeIO(-file   => "bintree.nw",
                            -format => "newick");
my $tree = $input->next_tree;
my $tree_as_string = $tree->as_text($format);
print $tree_as_string;

The print Dumper($input) give this result:

$VAR1 = bless( {
                 '_bootstrap_style' => 'traditional',
                 '_handler' => bless( {
                                        '_treelevel' => 0,
                                        '_currentnodes' => [],
                                        '_lastitem' => {
                                                         'tree' => 0,
                                                         'current' => [],
                                                         'id' => 0,
                                                         'node' => 0,
                                                         'leaf' => 0
                                                       },
                                        'nodetype' => 'Bio::Tree::Node',
                                        '_root_verbose' => 0,
                                        'treetype' => 'Bio::Tree::Tree',
                                        '_currentitems' => [],
                                        '_nodect' => [
                                                       undef,
                                                       2,
                                                       0,
                                                       0,
                                                       0,
                                                       0,
                                                       0,
                                                       0,
                                                       0
                                                     ]
                                      }, 'Bio::TreeIO::TreeEventBuilder' ),
                 '_file' => 'bintree.nw',
                 'newline_each_node' => undef,
                 'internal_node_id' => 'id',
                 '_root_cleanup_methods' => [
                                              sub { "DUMMY" }
                                            ],
                 '_flush_on_write' => 1,
                 '_filehandle' => \*Symbol::GEN0,
                 '_root_verbose' => 0,
                 '_print_tree_count' => 0
               }, 'Bio::TreeIO::newick' );

Here is the Print Dumper ($tree)

is there a mistake ? or it's a bug ? Thanks in advance

1

There are 1 answers

4
SES On BEST ANSWER

Your code is not working because you have not set the variable $format to anything, so the Bio::TreeIO class cannot find a class to load for the format. Try this code (it works for me):

#!/usr/bin/env perl                                                                                                                                                          

use strict;
use warnings;
use Bio::TreeIO;

my $usage  = "$0 treefile\n";
my $infile = shift or die $usage;
my $treeio = Bio::TreeIO->new(-file => $infile, -format => 'newick');
print $treeio->next_tree->as_text('newick');

EDIT: Here is a version using your tree as the input:

#!/usr/bin/env perl                                                                                                                                                          

use strict;
use warnings;
use Bio::TreeIO;

my $treeio = Bio::TreeIO->new(-fh => \*DATA, -format => 'newick');
print $treeio->next_tree->as_text('newick');

__DATA__
(((A:5,B:5)90:2,C:4)25:3,D:10);

If we run this code, it prints the tree, as expected.

$ perl so18645089.pl                                                                                    
(((A:5,B:5)90:2,C:4)25:3,D:10);

I'm using BioPerl 1.6.901, the latest version (and the version the documentation on CPAN describes). Version 1.6.0 is very old (>5 years) and is not even on CPAN anymore. I bet if you upgrade, your troubles will disappear.