免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2000 | 回复: 3
打印 上一主题 下一主题

一个脚本,请大神帮忙看看是什么问题! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-05-12 16:29 |只看该作者 |倒序浏览
本帖最后由 conan_swu 于 2015-05-12 16:31 编辑
  1. #!/usr/local/bin/perl -w
  2. #This progrem transfer the BLAST result include the Query sites and Sbject sites to the excel file.
  3. $vision="Vision: 2.0"; #nipx 2001-7-20
  4. $vision="Vision: 3.0"; #nipx 2002-4-11
  5. use Getopt::Std;
  6. getopts "o:i:e:a:l:s:";

  7. print "*************\n*$vision*\n*************\n";
  8. if ((!defined $opt_i)|| (!defined $opt_o) ) {
  9.         die "************************************************************************
  10.         Usage:transferall.pl -i filename -o outfile.
  11.           -h : help and usage.
  12.           -v : vision.
  13.           -e : expect value(default 10)
  14.           -a : identity% (default 0)
  15.           -l : alignment length (default 0)
  16.           -s : score (default 0)
  17. ************************************************************************\n";
  18. }
  19. $Expect = (defined $opt_e) ? $opt_e : 10;
  20. $Length = (defined $opt_l) ? $opt_l : 0;
  21. $Identity = (defined $opt_a) ? $opt_a : 0;
  22. $Score = (defined $opt_s) ? $opt_s : 0;
  23. open(Ofile,">$opt_o.ext");print "Running.....\n";
  24. open (F,$opt_i) || die"can't open $opt_i:$!\n";
  25. $i=$q=$s=$a=0;
  26. printf Ofile "%8s %8s %8s %8s %8s %8s %8s %8s %10s %8s %5s %8s %8s\n", "Letter","QueryX","QueryY","SbjctX", "SbjctY","Length","Score","E value","Overlap/total","Identity","Fram","Query name","Sbject Name";
  27. while (<F>)
  28. {
  29.         if (/Query= (\S+)/)
  30.         {
  31.                 if($i==1)
  32.                 {
  33.                         #print Ofile "$query^$letter^Query:$qbegin----$qend^Sbject:$sbegin----$send^$name^$annotation^$length^$score^$expect^$identity^$over\n";
  34.                         if($score >$Score && $expect<=$Expect && $over>=$Identity && $identity2 >= $Length)
  35.                         {
  36.                                 $ovalap_total = "$identity1/$identity2";
  37.                                 printf Ofile "%8s %8s %8s %8s %8s %8s %8s %8s %10s %8s %5s %8s %8s %20s\n",$letter,$qbegin,$qend,$sbegin,$send,$length,$score,$expect,$ovalap_total,$over,$fram,$query,$name,$annotation;
  38.                         }
  39.                         $i=$q=$s=0;
  40.                         $query=$letter=$qbegin=$qend=$sbegin=$send=$name=$annotation=$length=$score=$expect=$identity=$over=0;
  41.                 }
  42.                 $query=$1;
  43.         }
  44.         elsif (/\((\S+)\s+letters\)/)
  45.         {
  46.                 $letter=$1;$letter=~s/,//;
  47.         }
  48.         elsif (/^>(\S*)\s+(.*)/)
  49.         {
  50.                 if($i==1)
  51.                 {
  52.                         if($score >$Score && $expect<=$Expect && $over>=$Identity && $identity2 >= $Length)
  53.                         {
  54.                                 $ovalap_total = "$identity1/$identity2";
  55.                                 printf Ofile "%8s %8s %8s %8s %8s %8s %8s %8s %10s %8s %5s %8s %8s %20s\n",$letter,$qbegin,$qend,$sbegin,$send,$length,$score,$expect,$ovalap_total,$over,$fram,$query,$name,$annotation;
  56.                         }
  57.                         $i=$q=$s=0;
  58.                         $qbegin=$qend=$sbegin=$send=$name=$annotation=$length=$score=$expect=$identity=$over=0;
  59.                 }
  60.                 $name=$1;
  61.                 $annotation=$2;
  62.                 $a=1;
  63.         }
  64.         elsif (/Length = (\d+)/)
  65.         {
  66.                 $length=$1;
  67.                 $a=0;
  68.         }
  69.         elsif ($a==1)
  70.         {
  71.                 chomp;
  72.                 $annotation.=$_;
  73.                 $annotation=~s/\s+/ /g;
  74.         } #This sentence could get the very long annotation that is longer than one line;
  75.         elsif (/Score = (.+) bits.+Expect\S* =\s+(\S+)\s*/)
  76.         {
  77.                 if($i==1)
  78.                 {
  79.                         if($score >$Score && $expect<=$Expect && $over>=$Identity && $identity2 >= $Length)
  80.                         {
  81.                                 $ovalap_total = "$identity1/$identity2";
  82.                                 printf Ofile "%8s %8s %8s %8s %8s %8s %8s %8s %10s %8s %5s %8s %8s %20s\n",$letter,$qbegin,$qend,$sbegin,$send,$length,$score,$expect,$ovalap_total,$over,$fram,$query,$name,$annotation;
  83.                         }
  84.                         $i=$q=$s=0;
  85.                         $qbegin=$qend=$sbegin=$send=$score=$expect=$identity=$over=0;
  86.                 }
  87.         $score=$1;$expect=$2;$expect=~s/^e/1e/;
  88.         }
  89.         elsif (/Identities = (\d+)\/(\d+)\s+\((.{0,4})%\)/)
  90.         {
  91.                 $identity1=$1;
  92.                 $identity2=$2;
  93.                 $over=$3;
  94.         }
  95.         elsif (/Frame = (\S+)/)
  96.         {
  97.                 $fram = $1;
  98.         }
  99.         elsif (/Query\:\s+(\d+)\s+\S+\s+(\d+)/)
  100.         {
  101.                 if($q==0)
  102.                 {
  103.                         $qbegin=$1;
  104.                 }
  105.                 $qend=$2;
  106.                 $q=1;
  107.         }
  108.         elsif (/Sbjct\:\s+(\d+)\s+\S+\s+(\d+)/)
  109.         {
  110.                 if($s==0)
  111.                 {
  112.                         $sbegin=$1;
  113.                 }
  114.                 $send=$2;
  115.                 $s=$i=1;
  116.         }
  117. }
  118. if(($score>$Score && $Expect<=$Expect && $over>=$Identity && $identity2 >= $Length)&&($i==1))
  119. {
  120.    $ovalap_total = "$identity1/$identity2";
  121.         printf Ofile "%8s %8s %8s %8s %8s %8s %8s %8s %10s %8s %5s %8s %8s %20s\n",$letter,$qbegin,$qend,$sbegin,$send,$length,$score,$expect,$ovalap_total,$over,$fram,$query,$name,$annotation;
  122. }
  123. close(F);
  124. close(Ofile);
复制代码
使用的时候会报错: use of uninitialized value $score in numeric gt (> at d:\perl\eblastp.pl line 119, <F> line 6389.

果断小白,不知道哪里的问题,跪求指点。

求职 : 软件工程师
论坛徽章:
3
程序设计版块每日发帖之星
日期:2015-10-07 06:20:00程序设计版块每日发帖之星
日期:2015-12-13 06:20:00程序设计版块每日发帖之星
日期:2016-05-05 06:20:00
2 [报告]
发表于 2015-05-12 17:19 |只看该作者
单独运行脚本,没发现什么问题,既然是命令行,在传入什么参数的时候,出的问题?

论坛徽章:
0
3 [报告]
发表于 2015-05-12 17:23 |只看该作者
本帖最后由 tmp 于 2015-05-12 17:24 编辑

这事不好说啊,
可以在开头的某个地方写上$score = 0;就不会报错了,
但是未必合你的逻辑,

最好能在文件输入的文件里有匹配/Score = (.+) bits.+Expect\S* =\s+(\S+)\s*/的行数据.

而且119行业写错了$Expect<=$Expect (大小写)

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
4 [报告]
发表于 2015-05-12 17:36 |只看该作者
0. always add below:
  use strict;
  use warnings;

1. don't use the same name for variable
Note: It's hard to check ...
   $score>$Score && $Expect<=$Expect

2. don't forget to use sub for subroutine
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP