0

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

Mariya
  • 847
  • 1
  • 9
  • 25
  • yes I used Bio::TreeIO, I get the same errror if I print dumper.. – Mariya Sep 04 '13 at 23:01
  • 1
    I'm pretty sure there's nothing called `Bio::Tree:Tree`, but `Bio::Tree::Tree` exists :) – memowe Sep 04 '13 at 23:02
  • yes you r right it's a typo only here.. – Mariya Sep 04 '13 at 23:03
  • I can confirm that using an older version of BioPerl will generate the error message you describe. You need to upgrade BioPerl if you want access to this method (there are many other benefits of upgrading). – SES Sep 07 '13 at 10:04

1 Answers1

1

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.

SES
  • 850
  • 1
  • 9
  • 21
  • What version of BioPerl do you have? It is hard to imagine why the code above wouldn't work unless there is something wrong with your tree file, or you have an older BioPerl installed. – SES Sep 06 '13 at 07:41
  • My version of Bioperl is 1.6.0 – Mariya Sep 06 '13 at 12:22
  • the problem is not from the tree because I used this data from inside the code file (((A:5,B:5)90:2,C:4)25:3,D:10); and get the same error – Mariya Sep 06 '13 at 12:38
  • See my updated answer. I think the short answer is that you need up upgrade your BioPerl installation to the latest version. – SES Sep 06 '13 at 14:19