lenti220 [~/perltest]>more count2.pl #!/usr/bin/perl -w # # assign keys and values to a hash # keys = 1 letter codes, values = aa names %aa_codes = ("A" => "alanine", "R" => "arginine", "D" => "aspartate", "N" => "asparagine", "C" => "cysteine", "E" => "glutamate", "Q" => "glutamine", "G" => "glycine", "H" => "histidine", "I" => "isoleucine", "L" => "leucine", "K" => "lysine", "M" => "methionine", "F" => "phenylalanine", "P" => "proline", "S" => "serine", "T" => "threonine", "Y" => "tyrosine", "W" => "tryptophan", "V" => "valine"); # assign keys and values to a hash # keys = 1 letter codes, values = codes for aa properties %aa_props = ("A" => "tsn", "R" => "pc+", "D" => "scp-", "N" => "sp", "C" => "stap", "E" => "cp-", "Q" => "p", "G" => "st", "H" => "n+cpr", "I" => "an", "L" => "an", "K" => "+cpn", "M" => "n", "F" => "rn", "P" => "s", "S" => "tsp", "T" => "tsp", "Y" => "rnp", "W" => "rnp", "V" => "ans"); # keys = aa property codes, values = long name for properties %prop_names = ("a" => "aliphatic", "s" => " small", "t" => " tiny", "r" => " aromatic", "n" => "non-polar", "p" => " polar", "+" => " positive", "-" => " negative", "c" => " charged"); # create two new arrays, one with all aa property codes, # one with all aa one letter codes @propcodes = keys (%prop_names); @aa1codes = keys (%aa_codes); # initialize a counter array to hold property code counts for $i (0..(scalar(@propcodes)-1)) { $sum[$i] = 0; } # start loop through each amino acid foreach $i (@aa1codes) { # expand every single character property code into an array element @props = split('',$aa_props{$i}); # count how often each property occurs foreach $prop (@props) { $j=0; while (defined ($propcodes[$j]) and $propcodes[$j] ne $prop) { $j++; } if (defined ($propcodes[$j]) ) { $sum[$j]++; } } #end of loop for one amino acid } #end of loop for all amino acids # print table heading print "\n"; print "property\tnumber\n"; print "--------\t------\n"; #print table rows $j = 0; foreach $i (@propcodes) { print $prop_names {$i}, "\t", $sum[$j], "\n"; $j++; } exit; lenti221 [~/perltest]>perl count2.pl property number -------- ------ non-polar 10 polar 12 positive 3 aliphatic 4 aromatic 4 charged 5 negative 2 small 9 tiny 5 lenti222 [~/perltest]>