Input file:
#read_1
AWEAWQQRZZZQWQQWZ
#read_2
ZZAQWRQTWQQQWADSADZZZ
#read_3
POGZZZZZZADWRR
.
.
Desired output file:
#read_1 3
#read_1 1
#read_2 2
#read_2 3
#read_3 6
.
.
Perl script that I have tried:
#!/usr/bin/perl
$/ = ">";
while (<>) {
next if $. == 1;
chomp;
my($header,@other) = split(/\n/,$_);
$sequence = join"",@other;
my @letters = split"",$sequence;
$seqlength = length $sequence;
$counter = 0;
foreach $base (@letters) {
$counter++ if $base eq 'Z';
}
print ">$header\t$counter\n";
}
Command I have tried:
[home@user]perl count.pl input_file.txt > input_file.stats
[home@user]cat input_file.stats
#read_1 4
#read_2 5
#read_3 6
.
.
My purpose is to calculate the frequency of "Z" at each string in detail.
However, I only able to total sum all the frequency of "Z" in each string.
Thanks for any advice.