0

我正在尝试使用收到此消息的as_text方法: 我正在使用此处的示例Bio::Tree::Treecan't locate object method as_text via package Bio::Tree::Tree

请注意,我在同一个包中尝试了其他方法,它们工作正常。

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;

给出这个print Dumper($input)结果:

$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' );

这里Print Dumper ($tree)

有错误吗?或者这是一个错误?提前致谢

4

1 回答 1

1

您的代码不起作用,因为您没有将变量设置$format为任何值,因此 Bio::TreeIO 类找不到要为该格式加载的类。试试这个代码(它适用于我):

#!/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');

编辑:这是一个使用你的树作为输入的版本:

#!/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);

如果我们运行此代码,它会按预期打印树。

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

我正在使用 BioPerl 1.6.901,最新版本(以及 CPAN 上的文档描述的版本)。版本 1.6.0 非常旧(> 5 年),甚至不再在 CPAN 上。我敢打赌,如果你升级,你的烦恼就会消失。

于 2013-09-05T20:13:18.270 回答