如何解决了解打印中途输出中的 Perl 错误
我在使用 Perl 脚本时遇到了很多问题。 此脚本计算我的数据集之间的距离。
(如果您想使用真实数据重现示例,请访问此处:https://github.com/MauriAndresMU1313/Example_Tajima-Nei_Distance_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.fasta";
} elsif ($idfile eq "" ) {
$idfile = "NT_ID_S.csv";
}
#### Considerando un archivo
my @contentIDS;
open (LIST,$idfile) or die;
while (my $l = <LIST>) {
$l =~ s/\n//g; # eliminar newline
$l =~ s/\r//g; # eliminar retorno de carro
next if (length($l) < 1);
push @contentIDS,$l;
}
close LIST;
#### .... colocar la lista de ids del fasta de forma ordenada y no redundante en el array
my $stats = Bio::Align::DNAStatistics->new();
my $alignin = Bio::AlignIO->new(-format => 'fasta',-file => $file); ### $file es el alineamiento # probar con alphabet
while (my $aln = $alignin->next_aln) {
#print "reading...A\n"; ### DIAG
my $matrix = $stats->distance(-align => $aln,-method => 'TajimaNei');
#print "reading...B\n"; ### DIAG
### Obtaining values for each pair (DISTANCE!)
WL1:
foreach my $aaa (@contentIDS) { ### identificador #1
WL2:
foreach my $baa (@contentIDS) { ### identificador #2
next (WL2) if ($aaa eq $baa);
my $data = $matrix->get_entry($aaa,$baa);
#($data = 0) if ($data < 0);
print "DISTANCE\t$aaa\t$baa\t$data\n";
} # END WL2
} # END WL1
}
exit;
#
我的输出有 98282 行,我的问题是第 1 行到 314 的距离是空的,但是后来计算了距离:
Calculation
(1) DISTANCE AVP78031.1 AVP78042.1
(2) DISTANCE AVP78031.1 ATO98108.1
(3) DISTANCE AVP78031.1 ATO98120.1
...
(315) DISTANCE AVP78042.1 ATO98108.1 0.29731
(316) DISTANCE AVP78042.1 ATO98120.1 0.29281
...
(98282) DISTANCE QNB17852.1 QNB17840.1 0.00026
当我看到输出消息错误时:
Use of uninitialized value $data in concatenation (.) or string at Tajima-Nei_Distance_NV.pl line 43,<GEN0> line 22294.
Use of uninitialized value $data in concatenation (.) or string at Tajima-Nei_Distance_NV.pl line 43,<GEN0> line 22294.
...
这个错误行是一样的:626 次。 我不明白为什么 Perl 脚本中的第 43 行是错误的。此外,当我在输出文件中看到第 22294 行时:
(22294) DISTANCE ALR69641.1 ALT66880.1 0.00222
在输出的这一行中计算了距离。我真的不明白。
有谁知道这是为什么?是脚本有问题吗?
解决方法
有时 $matrix->get_entry($aaa,$baa)
返回 undef。任何时候你试图让 perl 用一个未定义的变量插入一个字符串并启用警告,然后你就会得到那个警告。
线
print "DISTANCE\t$aaa\t$baa\t$data\n";
被插值并且 $data
是 undef,所以你会得到你提到的警告。
$ cat x.pl
use warnings;
my $x = undef;
print "$x\n";
$ perl x.pl
Use of uninitialized value $x in concatenation (.) or string at x.pl line 3.
$
您每次都打印 $aaa
和 $baa
的值,并且只有 3 次打印 $data
的空字符串。这些是没有“得到”的输入。这三个元组的矩阵未定义。您需要调查这 3 个特定的元组,因为您尚未共享该特定输入,因此只有您可以这样做。
更新 1
使用 perl 5.20.2、Bio::AlignIO 1.7.8 版以及您在 github 项目中包含的数据,我无法重现您的问题:
$ time perl "Bioperl Script" "Fasta file" "ID list" > perl.out 2>&1
相反,我在重定向的输出中看到了 $stats->distance
在执行时发出的这些警告:
MSG: ti_index not defined for R (359 times)
MSG: ti_index not defined for Y (209 times)
MSG: ti_index not defined for N (69123 times)
然后我看到您的代码输出(我取消了您的两个诊断打印语句的注释):
---------------------------------------------------
reading...A (this is printed only once)
reading...B (this is printed only once)
DISTANCE AVP78031.1 AVP78042.1 0.03064
DISTANCE AVP78031.1 ATO98108.1 0.30081
DISTANCE AVP78031.1 ATO98120.1 0.29663
... thousands of lines elided
DISTANCE QNB17852.1 QNB17759.1 -1.00000
DISTANCE QNB17852.1 QNB17771.1 0.00052
DISTANCE QNB17852.1 QNB17783.1 -1.00000
DISTANCE QNB17852.1 QNB17840.1 0.00026
我的输出中的前 3 个 (a,b) 元组与您的匹配,除了我的 $data
值是已定义而您的未定义。
这个 perl 脚本在我的 2019 款 MacBook Pro 上执行了超过 12 分钟。 “读取”行在输出中仅出现一次这一事实表明 while
循环仅迭代一次。
我的猜测是您使用的是此模块的旧版本,该版本以不同的方式处理其警告。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。