Bioperl: relative-majority consensus, fast code sought

Gustavo Glusman bmgustav@bioinformatics.weizmann.ac.il
Tue, 30 Mar 1999 13:07:37 +0200


At 23:04 +0000 1/3/99, James Gilbert wrote:
>George,
>
>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
     Gustavo@bioinfo.weizmann.ac.il    (public PGP key available)
     http://bioinfo.weizmann.ac.il/Gustavo
        Visit BioMOO, the biologists' virtual meeting place, at
     ___________ http://bioinfo.weizmann.ac.il/BioMOO ___________


=========== Bioperl Project Mailing List Message Footer =======
Project URL: http://bio.perl.org/
For info about how to (un)subscribe, where messages are archived, etc:
http://www.techfak.uni-bielefeld.de/bcd/Perl/Bio/vsns-bcd-perl.html
====================================================================