了解打印中途输出中的 Perl 错误

如何解决了解打印中途输出中的 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 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-