来个小程序perl

问题描述:

来个小程序perl
如下序列:
E078 10 CTACATCCAACA 21 100
E034 10 ATCCACATCAAGGATT 25 100
E012 59 CCAAGTTTT 67 100
E012 62 CAGAATCGGAGGAGGAAA 79 100
E056 39 AAGGTTTACAAGGTTCACCTC 59 100
E012 36 GCTGCCAACACCAA 49 100
E012 24 GACCAAATCGTCAAGATGGCCAA 46 100
E034 21 AACAAGATC 29 100
E012 4 CCGAGAAGCGCGGAAAGCGTCA 25 100
E034 57 AACCTTCCAAACGTC 71 100
目的:1 把有E012开头的行都提出来.2算出E012开头的序列,占总序列的百分比.
结果如下:
E012 59 CCAAGTTTT 67 100
E012 62 CAGAATCGGAGGAGGAAA 79 100
E012 36 GCTGCCAACACCAA 49 100
E012 24 GACCAAATCGTCAAGATGGCCAA 46 100
E012 4 CCGAGAAGCGCGGAAAGCGTCA 25 100
占据率:0.5(E012有5个,E开头行有10个,故5/10=0.5)

my $E_num = 0;my $E_total = 0;my $res = 0;while (){if ($_ =~m/^E012.*?/g){$E_num = $E_num + 1;print $_;}if ($_ = ~m/^E.*?/g){$E_total = $E_total +1;}}$r...谢谢你,新年快乐。。#!usr/bin/perl -Wopen IN,"E文件.txt";open OUT,">E结果文件.txt";my $E_num = 0;my $E_total = 0;my $res = 0;while (){if ($_ =~m/^E012.*?/g){$E_num = $E_num + 1;print OUT $_;}if ($_ = ~m/^E.*?/g){$E_total = $E_total +1;}}$res = $E_num/$E_total;printOUT "占据率:$res";这个有点小错误:修改下吧!1.open OUT,">E结果文件.txt";这句改成open OUT,">>E结果文件.txt";2.while (){ 这句改成while (){最后关闭文件:close(IN);close(OUT);