免费注册 查看新帖 |

Chinaunix

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

紧急求助一个perl 多行匹配的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-10-09 10:45 |只看该作者 |倒序浏览
本帖最后由 qianyemlf 于 2014-10-09 10:46 编辑

需要从中提取#start gene 到###之间的部分,感觉写的脚本很有问题,贴出来请大家指教啊
  1. open IN, "C:/Users/john/Desktop/augustus_out.gff3";
  2. open OUT, ">C:/Users/john/Desktop/augustus_out_c.gff3";

  3.   while (<IN>) {
  4.     if(/^(start)(.*)(###)$/sm){
  5.     print OUT "$_\n";

  6.      }
  7.   }
复制代码
  1. # Predicted genes for sequence number 16416 on both strands
  2. # (none)
  3. #
  4. # ----- prediction on sequence number 16417 (length = 195, name = 32833) -----
  5. #
  6. # Constraints/Hints:
  7. # (none)
  8. # Predicted genes for sequence number 16417 on both strands
  9. # (none)
  10. #
  11. # ----- prediction on sequence number 16418 (length = 195, name = 32835) -----
  12. #
  13. # Constraints/Hints:
  14. # (none)
  15. # Predicted genes for sequence number 16418 on both strands
  16. # start gene g327
  17. 32835        AUGUSTUS        gene        1        195        0.59        -        .        g327
  18. 32835        AUGUSTUS        transcript        1        195        0.59        -        .        g327.t1
  19. 32835        AUGUSTUS        internal        1        195        0.59        -        0        transcript_id "g327.t1"; gene_id "g327";
  20. 32835        AUGUSTUS        CDS        1        195        0.59        -        0        transcript_id "g327.t1"; gene_id "g327";
  21. 32835        AUGUSTUS        exon        1        195        .        -        .        transcript_id "g327.t1"; gene_id "g327";
  22. # coding sequence = [cgggcgcggcatggtggtccacgggtgcgcgccgcagctggccgtgctggcccacccgtcggtgggcgccttcgtgtcg
  23. # cactgcgggtggagctcggtgctggaggcggcgtccgccggcgtgccggtgctggcgtggccgctggtgttcgagcagttcatcaacgagcggctggt
  24. # caccgaggtggtggcgtt]
  25. # protein sequence = [RARHGGPRVRAAAGRAGPPVGGRLRVALRVELGAGGGVRRRAGAGVAAGVRAVHQRAAGHRGGGV]
  26. # end gene g327
  27. ###
  28. #
  29. # ----- prediction on sequence number 16419 (length = 195, name = 32837) -----
  30. #
  31. # Constraints/Hints:
  32. # (none)
  33. # Predicted genes for sequence number 16419 on both strands
  34. # (none)
复制代码

论坛徽章:
7
巳蛇
日期:2013-11-28 09:22:59天秤座
日期:2014-10-25 15:40:452015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:53:172015亚冠之德黑兰石油
日期:2015-07-15 08:46:452015亚冠之平阳省
日期:2015-11-08 16:27:53白银圣斗士
日期:2015-11-14 09:58:12
2 [报告]
发表于 2014-10-09 12:43 |只看该作者
  1. #!/usr/bin/perl
  2. use strict;

  3. open (OUT,">out.gff3");
  4. my $flag=0;
  5. my $out=undef;

  6. while(my $line=<DATA>){
  7.         if($line=~/^# start/){
  8.                 $out.=$line;
  9.                 $flag=1;
  10.         }elsif($line=~/^###/){
  11.                 $flag=0;
  12.         }elsif($flag){
  13.                 $out.=$line;
  14.         }
  15. }

  16. print  OUT "$out";

  17. __DATA__
  18. # Predicted genes for sequence number 16416 on both strands
  19. # (none)
  20. #
  21. # ----- prediction on sequence number 16417 (length = 195, name = 32833) -----
  22. #
  23. # Constraints/Hints:
  24. # (none)
  25. # Predicted genes for sequence number 16417 on both strands
  26. # (none)
  27. #
  28. # ----- prediction on sequence number 16418 (length = 195, name = 32835) -----
  29. #
  30. # Constraints/Hints:
  31. # (none)
  32. # Predicted genes for sequence number 16418 on both strands
  33. # start gene g327
  34. 32835        AUGUSTUS        gene        1        195        0.59        -        .        g327
  35. 32835        AUGUSTUS        transcript        1        195        0.59        -        .        g327.t1
  36. 32835        AUGUSTUS        internal        1        195        0.59        -        0        transcript_id "g327.t1"; gene_id "g327";
  37. 32835        AUGUSTUS        CDS        1        195        0.59        -        0        transcript_id "g327.t1"; gene_id "g327";
  38. 32835        AUGUSTUS        exon        1        195        .        -        .        transcript_id "g327.t1"; gene_id "g327";
  39. # coding sequence = [cgggcgcggcatggtggtccacgggtgcgcgccgcagctggccgtgctggcccacccgtcggtgggcgccttcgtgtcg
  40. # cactgcgggtggagctcggtgctggaggcggcgtccgccggcgtgccggtgctggcgtggccgctggtgttcgagcagttcatcaacgagcggctggt
  41. # caccgaggtggtggcgtt]
  42. # protein sequence = [RARHGGPRVRAAAGRAGPPVGGRLRVALRVELGAGGGVRRRAGAGVAAGVRAVHQRAAGHRGGGV]
  43. # end gene g327
  44. ###
  45. #
  46. # ----- prediction on sequence number 16419 (length = 195, name = 32837) -----
  47. #
  48. # Constraints/Hints:
  49. # (none)
  50. # Predicted genes for sequence number 16419 on both strands
  51. # (none)
复制代码
  1. # start gene g327
  2. 32835        AUGUSTUS        gene        1        195        0.59        -        .        g327
  3. 32835        AUGUSTUS        transcript        1        195        0.59        -        .        g327.t1
  4. 32835        AUGUSTUS        internal        1        195        0.59        -        0        transcript_id "g327.t1"; gene_id "g327";
  5. 32835        AUGUSTUS        CDS        1        195        0.59        -        0        transcript_id "g327.t1"; gene_id "g327";
  6. 32835        AUGUSTUS        exon        1        195        .        -        .        transcript_id "g327.t1"; gene_id "g327";
  7. # coding sequence = [cgggcgcggcatggtggtccacgggtgcgcgccgcagctggccgtgctggcccacccgtcggtgggcgccttcgtgtcg
  8. # cactgcgggtggagctcggtgctggaggcggcgtccgccggcgtgccggtgctggcgtggccgctggtgttcgagcagttcatcaacgagcggctggt
  9. # caccgaggtggtggcgtt]
  10. # protein sequence = [RARHGGPRVRAAAGRAGPPVGGRLRVALRVELGAGGGVRRRAGAGVAAGVRAVHQRAAGHRGGGV]
  11. # end gene g327
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP