[Shootout-list] Perl reverse-complement benchmark
Joel Hoffman
hoffmanj@pacifier.com
Thu, 24 Mar 2005 23:36:54 -0800
This is a multi-part message in MIME format.
--------------040501030205040902080500
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Here is a Perl implementation of the reverse-complement benchmark, attached.
Joel
--------------040501030205040902080500
Content-Type: application/x-perl;
name="reverse-complement.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="reverse-complement.pl"
#!/usr/bin/perl
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
# reverse-complement benchmark
# contributed by Joel Hoffman, 2005-03-24
use POSIX qw<ceil>;
use strict;
$/=">";
while (defined(my $l = <>)) {
chomp $l;
next unless $l;
my $rv = "";
for ( split /\n/, '>'.$l ) {
if (/^[;>]/) {
print $_,"\n";
} else {
$rv = (reverse uc $_) . $rv;
}
}
$rv =~ tr/ACGTUMRWSYKVHDBN/TGCAAKYWSRMBDHVN/;
print substr($rv,$_*60,60),"\n" for 0..ceil(length($rv) / 60 - 1);
}
--------------040501030205040902080500--