Bioperl: relative-majority consensus, fast code sought

James Gilbert jgrg@sanger.ac.uk
Tue, 6 Apr 1999 12:02:24 +0100 (BST)


On Tue, 30 Mar 1999, Andrew Dalke wrote:

> | foreach $letter (qw/A T C G/) { $count{$letter} = tr/$letter/$letter/; }
> 
> (if valid perl; didn't test it) would mean you can support other
> character sets much more easily than the old way, which listed
> every character on a different line embedded in a bunch of code,
> and duplicating the letter several times.

I agree, this is more maintainable.  To get it to
work, however, you need to do:

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

So you wouldn't want to use this if this piece of
code if it was called a large numbers of times,
because you have the overhead of interpretaion and
compilation every time the eval is called.

James G.R. Gilbert
The Sanger Centre
Wellcome Trust Genome Campus
Hinxton
Cambridge                        Tel: 01223 494906
CB10 1SA                         Fax: 01223 494919

=========== 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
====================================================================