我有一个perl脚本,在每0到200个碱基对中计数ATGC,最多1000个,即0-200,1-201,2-202,最多1000个。我还想计算这些0-200中的G + C基数, 1-201 ...高达1000,并且还计算这些区域的GC%。我怎么能这样做。
Perl脚本是:
#! perl -slw
use strict;
my $dna = do{ local $/; <DATA> };
$dna =~ tr[\n][]d;
my %counts;
++$counts{ substr $dna, $_, 1 } for 0 .. 199;
for my $offset ( 0 .. length( $dna )-200 ) {
printf "range: %d .. %d A:%d C:%d G:%d T:%d\n", $offset, $offset+199, @counts{ qw[ A C G T ] };
--$counts{ substr $dna, $offset, 1 };
++$counts{ substr $dna, $offset+200, 1 };
}
__DATA__
TGCCATCGCGCCAGGAGGGAAGACCAGTTGCTCTGGGTAAATCAGCCGTGAGCGTATCTGTCCCTCTTATAATTAGGAGTTTAAACTCTACGATGTTACC
ATCCTTGAATCAGGTATATACCGCACTGAAACATCGTCGGCTTTGGGCTCATTCGCTACCCTGTCGCTGATATGCGATCTATTCTACATATGCGGGGCCA
CCCAATGTCGATTGTCATGAGGAGGGGGTCATAACGACTCACTATAGGACCAGCACGTCCGGTTGCGCTGAGTAAAATAGAGCTACAAAAGACACAGTAC
TCCAAGATGTAAAGGGGAAGACGGGACCTGGGTCGGGGGCGCAACTTCACTGAGCTTTTAACCTTGCGCGCATGCGAGAGCCTTTCCGCTTAGGAAATGC
TGTAAGATCAAGTGGTAGGACTATTGAGAGGTCTTACCTTGCCGCAGCAACGTGGACGGCGACCGGATAATTTAAGGCCGACATTCAATATAGAATGTCA
GGGAGCAGAACTGTATCCCAAATGCTAGTTGTAGGTGTACGAGCGCACCTGGGGACCTATCGCTCCGACGGGGTCTGCGTAGCCCATACATCCTGCCAGC
ACTGGGGCTATTGAACGGTCAATCCGTAATGTACTCGCTGAATGCTCAGGGATTCCTTAATCTTTGAGCACGCGGCTTCTCTCACTTTTCTCACGTCAAC
CCTGACTCATAACGGAGTTCGGCAGTCCCGGAACGGCTTATAGAAGCAATGCCTGAGTAGATAGCGTCAGGGATCGGCCCTACGTCGAGTCCAGTACGCC
ATTGGATGGAGGTCTCAGCCGTCGGTGGAGTGCGGCTCCACCCCCACATGAACGAGGTTGTTCCTGACCACCCCTGAAACTGTGAGAACCATTGTGTCGA
AACCAAGAGGCTTGCGTCGCGCTATAGGTCGATTGCCCCCTAGTTTCCCTATATTGAACGTGTTTCCATTAAAGACTCTCGGTAAATCTCACGTATTGCA
输出:
C:\test>junk77
range: 0 .. 199 A:46 C:51 G:47 T:56
range: 1 .. 200 A:46 C:52 G:47 T:55
range: 2 .. 201 A:46 C:53 G:46 T:55
range: 3 .. 202 A:46 C:53 G:46 T:55
range: 4 .. 203 A:47 C:52 G:46 T:55
range: 5 .. 204 A:47 C:52 G:46 T:55
range: 6 .. 205 A:47 C:52 G:46 T:55
range: 7 .. 206 A:47 C:51 G:47 T:55
range: 8 .. 207 A:47 C:51 G:46 T:56
range: 9 .. 208 A:47 C:51 G:46 T:56
range: 10 .. 209 A:47 C:51 G:46 T:56
range: 11 .. 210 A:48 C:50 G:46 T:56
range: 12 .. 211 A:48 C:49 G:46 T:57
range: 13 .. 212 A:47 C:49 G:46 T:58
range: 14 .. 213 A:47 C:49 G:46 T:58
range: 15 .. 214 A:47 C:49 G:45 T:59
range: 16 .. 215 A:46 C:50 G:45 T:59
range: 17 .. 216 A:47 C:50 G:44 T:59
...
答案 0 :(得分:0)
如上所述,你的问题很简单;让我想知道我是否错过了什么。
用以下内容替换您的印刷品:
printf "range: %d .. %d A:%d C:%d G:%d T:%d G+C:%d GC%%:%.1f\n", $offset, $offset+199, @counts{ qw[ A C G T ] }, $counts{'G'}+$counts{'C'}, ($counts{'G'}+$counts{'C'})/200*100;