in reply to Listing occurence of all residues
Thanks for the update; it would be good if you could put your sample input and output inside <code> tags as mentioned previously. Note that the regular expression /^>sp\|(\w+\S+)\|/ does not match the sample data you provided, but I'm guessing that's just because the sample data is oversimplified. Some general things you should do:
The code still has a couple of smaller issues, but the two things that are preventing it from working correctly are:
The output can be made to be a bit more organized also using the same method as above: for my $w (sort keys %count) { print "$w:$count{$w}\t"; } - But of course it's possible to get the output to look even more like what you want it to. The following code loops over the letters you want to output, and prints either the number, or a dash if that number is zero (or undefined). The list of letters could be simplified with Perl's qw//.
for my $w ("a","b","c","d","g","u","x","j","k") { print $count{$w}||"-", " "; }
Which gives:
5 4 4 3 - - - - - - - - - 5 - - 3 4
Customizing that is left as an exercise to the reader :-) (one tip: see uc and lc)
|
|---|