Bioperl: relative-majority consensus, fast code sought

Gustavo Glusman
Tue, 30 Mar 1999 13:07:37 +0200

At 23:04 +0000 1/3/99, James Gilbert wrote:
>You might like to try using the tr/// operator to
>count the characters in a string, which may be
>faster than splitting into an array (but you may
>already have it in an array):
>$temp{'A'} = ($string =~ tr/A/A/);
>$temp{'C'} = ($string =~ tr/C/C/);
>$temp{'G'} = ($string =~ tr/G/G/);
>$temp{'T'} = ($string =~ tr/T/T/);

Shouldn't this be faster?

$_ = $string;
foreach $letter (qw/A T C G/) { $count{$letter} = tr/$letter//; }

The idea being that the string studied gets shorter every time. Added bonus
is being left with the non-ACGT letters in $_ at the end.

     Gustavo Glusman              Founder/administrator of BioMOO    (public PGP key available)
        Visit BioMOO, the biologists' virtual meeting place, at
     ___________ ___________

=========== Bioperl Project Mailing List Message Footer =======
Project URL:
For info about how to (un)subscribe, where messages are archived, etc: