perl - 什么意思 "Can' t locate object method.."在这个使用 P

我正在使用 Perl 对我的数据进行一些分析,使用特定的 BioPerl 包。

我在另一篇文章中阅读了一些关于此问题的建议,但我真的不明白这如何适用于我的脚本。

这是我的脚本:

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$

我认为问题可能与“=> 而不是 ->”有关。我只是想。

最佳答案

您收到的消息,Can't locate object method... (来自 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.

所以调用的对象有些不对。 要么这样的类不存在,如上面引用的文档所说,要么方法所在的对象调用不好(之前失败了)...让我们通过代码和文档来跟踪调用。

链开始于 Bio::Align::DNAStatistics::distance方法,返回类 Bio::Matrix::PhylipDist 的对象.语法是正确的,所以我们期待一个好的矩阵对象(或者如果细节有误,希望是一个彻底的错误)。

但是,错误消息的部分是

... via package "0" ...

clearly means that something is in fact wrong with the matrix object (it's 0 -- not an object at all), and so with the call that was supposed to return that object,

my $matrix = $stats->distance(-align => $aln, -method => 'Tajima-Nei');

根据文档下方列出的距离方法之一判断,D_TajimaNei ,您可能需要说 -method => 'TajimaNei'(无连字符)。人们可能希望方法 croak 出现这样的错误,因为我没有看到返回 0 的意义,但由于情况并非如此在使用此类时添加额外检查可能是个好主意。

还要注意方法get_entry只能在没有参数的情况下调用 get_entry(),并且尝试的 get_entry($aaa, $baa) 方法(需要两个参数)不存在。 这会引出脚注 中提到的其他相关错误。


请注意,此方法在 perldiag 中的条目中的括号说明指定错误与对象本身有关,而 previous entry in perldiag , 除了括号注释外,语法完全相同,当调用方法有问题时会引发。我建议始终检查违规陈述的所有部分。

根据发布时的最新文档

关于perl - 什么意思 "Can' t locate object method.."在这个使用 Perl 的具体例子中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67248904/

相关文章:

asp.net-core - 如何在 ASP.NET Core 3.1 中为 Swagger 指定默

r - 从数据框中的前一列中减去每一列

awk - Unix 提取两行之间的行并将它们存储在各自的文件中

python - 导入错误 : No module named 'typing' when tryi

javascript - 尝试调试 javascript : "vscode listen eacc

javascript - 类型错误:无法在 React 项目中读取 null 的属性 'length

reactjs - "Redundant alt attribute. Screen-readers

r - 使向量的所有元素都不同

azure - 如何删除被不属于我的域锁定的 Front Door 资源

r - 使用 gsub() 从 R 中的数组中提取数字