in reply to Re: Counting using transliteration
in thread Counting using transliteration

Thanq for the help guys. I don't think I've explained what I'm wanting to do properly. I am wanting to count the number of each type of character in a line, and then (eventually) find a way to print what the most common character was. This should generate a consensus sequence for my multiple alignments. (Im a bioinformatician)

So for example, say the line is ---ADGRCMNAAAPPRS I want the program to count the number of the different characters: $Acount, $Dcount, $gapcount (which is -) etc. and store the most common letter in my consensus sequence array. Think this is possible ?! Then the program should move onto the next line of the file and repeat the process... Thanks for pointing out I don't need to put $line, I realise now that the line information is stored in $_

basm100

Replies are listed 'Best First'.
Re: Re: Re: Counting using transliteration
by zengargoyle (Deacon) on Feb 26, 2002 at 01:33 UTC
    while ($l=<DATA>) { %count = (); $count{$1}++ while ($l =~ /(.)/g); $max = 0; $max_key; foreach (keys %count) { $max = $count{$_}, $max_key = $_ if ($count{$_} > $max +); } push @consensus, $max_key; } print "@consensus\n"; __END__ ---ADGRCMNAAAPPRS ASAMNP-PRCM--MWQZ TYYCYLCKLKDUEAOLE $ perl cons.pl A - Y