了解打印的中途输出中的 Perl 错误
Understanding Perl´ error in printed midway output
我在使用 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.
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 个元组的矩阵未定义。您需要调查这 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)
然后我看到了你的代码输出(我取消了你的两个 diag print 语句的注释):
---------------------------------------------------
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 分钟。 “reading”行在输出中只出现一次这一事实表明 while
循环只迭代一次。
我猜您使用的是此模块的旧版本,它以不同的方式处理警告。
我在使用 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.
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 个元组的矩阵未定义。您需要调查这 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)
然后我看到了你的代码输出(我取消了你的两个 diag print 语句的注释):
---------------------------------------------------
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 分钟。 “reading”行在输出中只出现一次这一事实表明 while
循环只迭代一次。
我猜您使用的是此模块的旧版本,它以不同的方式处理警告。