在这个使用 Perl 的特定示例中,"Can't locate object method.." 是什么意思?
What means "Can't locate object method.." in this specific example using Perl?
我正在使用 Perl 对我的数据进行一些分析,使用特定的 BioPerl 包。
我在另一个 post 中阅读了有关此问题的一些建议,但我真的不明白这如何适用于我的脚本。
这是我的脚本:
use strict;
use warnings;
use Bio::AlignIO;
use Bio::Align::DNAStatistics;
my $file = $ARGV[0];
my $idfile = $ARGV[1];
if ($file eq "" ) {
$file = "NT_MSA_S_protein.fasta";
} elsif ($idfile eq "" ) {
$idfile = "NT_ID_S_protein.csv";
}
my @contentIDS;
open (LIST, $idfile) or die;
while (my $l = <LIST>) {
$l =~ s/\n//g; # delete newline
$l =~ s/\r//g; # delete CR
next if (length($l) < 1);
push @contentIDS, $l;
}
close LIST;
my $stats = Bio::Align::DNAStatistics->new();
my $alignin = Bio::AlignIO->new(-format => 'fasta', -file => $file); # MSA file
while (my $aln = $alignin->next_aln) {
my $matrix = $stats->distance(-align => $aln, -method => 'Tajima-Nei');
WL1:
foreach my $aaa (@contentIDS) { ### ID #1
WL2:
foreach my $baa (@contentIDS) { ### ID #2
next (WL2) if ($aaa eq $baa);
my $data = $matrix->get_entry($aaa, $baa);
print "DISTANCE\t$aaa\t$baa\t$data\n";
} # END WL2
} # END WL1
}
这是消息错误:
Can't locate object method "get_entry" via package "0" (perhaps you forgot to load "0"?) at Tajima-Nei_Distance_NV.pl lin$
我认为问题可能与“=> 而不是 ->”有关。我只是想。
它告诉您 $matrix 的值为 0。Perl 将 0 解释为 class 名称。您对 $matrix 的分配有问题。
my $matrix = $stats->distance(-align => $aln, -method => 'Tajima-Nei');
我想你想要 -method => 'TajimaNei'
。检查 $stats->available_distance_methods.
通常你不能有一个名为 0 的 class,但是 with enough thrust pigs fly just fine.
*{"0::hello"} = sub { "Hello\n" };
package main;
my $matrix = 0;
print $matrix->hello;
您收到的消息,Can't locate object method... (from perldiag),表示
(F) You called a method on a class that did not exist, and the method could not be found in UNIVERSAL. This often means that a method requires a package that has not been loaded.
所以调用的对象有些不对劲。† 要么 class 不存在,正如上面引用的文档所说,或者调用该方法的对象不好(之前失败了)...让我们通过代码和文档来跟踪该调用。
链从 Bio::Align::DNAStatistics::distance method, which returns an object of the class Bio::Matrix::PhylipDist 开始。语法是正确的,所以我们期待一个好的矩阵对象(或者如果细节有误,希望是一个彻底的错误)。
但是,错误消息的部分显示
... via package "0" ...
显然意味着矩阵对象实际上有问题(它是 0
-- 根本不是一个对象),因此对于应该 return 该对象的调用,
my $matrix = $stats->distance(-align => $aln, -method => 'Tajima-Nei');
根据文档下方列出的一种距离方法 D_TajimaNei 判断,您可能需要说 -method => 'TajimaNei'
(无连字符)。人们可能希望方法 croak
s 出现这样的错误,因为我在 returning a 0
中看不到任何意义,但由于情况并非如此,它可能使用此 class.
时添加额外检查是个好主意
另请注意,方法 get_entry 只能在没有参数的情况下调用,get_entry()
,并且尝试的 get_entry($aaa, $baa)
方法(需要两个参数)不存在。 ‡ 这会引出脚注 †.
中提到的另一个相关错误
† 请注意,perldiag
中此方法条目中的括号注释指定错误与对象本身有关,而 previous entry in perldiag
, 除了括号注释外,语法完全相同,当调用方法有问题时会引发。我建议始终检查违规声明的所有部分。
‡ 根据发帖时的最新文档
我正在使用 Perl 对我的数据进行一些分析,使用特定的 BioPerl 包。
我在另一个 post 中阅读了有关此问题的一些建议,但我真的不明白这如何适用于我的脚本。
这是我的脚本:
use strict;
use warnings;
use Bio::AlignIO;
use Bio::Align::DNAStatistics;
my $file = $ARGV[0];
my $idfile = $ARGV[1];
if ($file eq "" ) {
$file = "NT_MSA_S_protein.fasta";
} elsif ($idfile eq "" ) {
$idfile = "NT_ID_S_protein.csv";
}
my @contentIDS;
open (LIST, $idfile) or die;
while (my $l = <LIST>) {
$l =~ s/\n//g; # delete newline
$l =~ s/\r//g; # delete CR
next if (length($l) < 1);
push @contentIDS, $l;
}
close LIST;
my $stats = Bio::Align::DNAStatistics->new();
my $alignin = Bio::AlignIO->new(-format => 'fasta', -file => $file); # MSA file
while (my $aln = $alignin->next_aln) {
my $matrix = $stats->distance(-align => $aln, -method => 'Tajima-Nei');
WL1:
foreach my $aaa (@contentIDS) { ### ID #1
WL2:
foreach my $baa (@contentIDS) { ### ID #2
next (WL2) if ($aaa eq $baa);
my $data = $matrix->get_entry($aaa, $baa);
print "DISTANCE\t$aaa\t$baa\t$data\n";
} # END WL2
} # END WL1
}
这是消息错误:
Can't locate object method "get_entry" via package "0" (perhaps you forgot to load "0"?) at Tajima-Nei_Distance_NV.pl lin$
我认为问题可能与“=> 而不是 ->”有关。我只是想。
它告诉您 $matrix 的值为 0。Perl 将 0 解释为 class 名称。您对 $matrix 的分配有问题。
my $matrix = $stats->distance(-align => $aln, -method => 'Tajima-Nei');
我想你想要 -method => 'TajimaNei'
。检查 $stats->available_distance_methods.
通常你不能有一个名为 0 的 class,但是 with enough thrust pigs fly just fine.
*{"0::hello"} = sub { "Hello\n" };
package main;
my $matrix = 0;
print $matrix->hello;
您收到的消息,Can't locate object method... (from perldiag),表示
(F) You called a method on a class that did not exist, and the method could not be found in UNIVERSAL. This often means that a method requires a package that has not been loaded.
所以调用的对象有些不对劲。† 要么 class 不存在,正如上面引用的文档所说,或者调用该方法的对象不好(之前失败了)...让我们通过代码和文档来跟踪该调用。
链从 Bio::Align::DNAStatistics::distance method, which returns an object of the class Bio::Matrix::PhylipDist 开始。语法是正确的,所以我们期待一个好的矩阵对象(或者如果细节有误,希望是一个彻底的错误)。
但是,错误消息的部分显示
... via package "0" ...
显然意味着矩阵对象实际上有问题(它是 0
-- 根本不是一个对象),因此对于应该 return 该对象的调用,
my $matrix = $stats->distance(-align => $aln, -method => 'Tajima-Nei');
根据文档下方列出的一种距离方法 D_TajimaNei 判断,您可能需要说 -method => 'TajimaNei'
(无连字符)。人们可能希望方法 croak
s 出现这样的错误,因为我在 returning a 0
中看不到任何意义,但由于情况并非如此,它可能使用此 class.
另请注意,方法 get_entry 只能在没有参数的情况下调用,get_entry()
,并且尝试的 get_entry($aaa, $baa)
方法(需要两个参数)不存在。 ‡ 这会引出脚注 †.
† 请注意,perldiag
中此方法条目中的括号注释指定错误与对象本身有关,而 previous entry in perldiag
, 除了括号注释外,语法完全相同,当调用方法有问题时会引发。我建议始终检查违规声明的所有部分。
‡ 根据发帖时的最新文档