in reply to Re^4: Listing occurence of all residues
in thread Listing occurence of all residues

I hope this little piece of code help. I supposed that the residues are marked with letters A-Z.
#!/usr/bin/perl -w use strict; open FILE1, "<e.txt" or die "can't open file for reading: $!\n"; my %Fasta_split; my $id; while (<FILE1>) { chomp; next if(/^\s*$/); my $FastaLine = $_; if ( $FastaLine =~ /^>sp\|(\w+\S+)\|/ ) { $id = $1; } else { $Fasta_split{$id} .= $FastaLine; } } # print header my @header = qw/A B C D E F G H I J K L M N O P Q R S T U V W X Y Z/; print "ID " . join(' ', @header) . "\n"; # print data foreach my $id (sort keys %Fasta_split) { my %words; # count letters $words{$_}++ for split('', $Fasta_split{$id}); printf "%8s ", $id; # print counts foreach my $w (@header) { if (defined $words{$w}) { printf "%2d ", $words{$w}; } else { print ' - '; } } print "\n"; }