revcomp

#!/usr/bin/perl

# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# Contributed by Bradford Powell
# Fixed slow print substr-solution, by Kjetil Skotheim


use strict;

sub print_revcomp {
    my ($desc, $s) = @_;
    return if not $desc;
    print $desc, "\n";
    $s =  reverse $s;
    $s =~ tr{wsatugcyrkmbdhvnATUGCYRKMBDHVN}
            {WSTAACGRYMKVHDBNTAACGRYMKVHDBN};
    my($i,$stop)=(0,length($s)/60);
    print substr($s,$i++*60,60),"\n"  while $i<$stop;
}

my($desc,$seq);
while (<STDIN>) {
    chomp;
    if (/^>/) {
        print_revcomp($desc, $seq);
        $desc = $_;
        $seq = '';
    } else {
        $seq .= $_;
    }
}
print_revcomp($desc, $seq);


See Also

fasta.p5.pl

fasta.p6

Generate and write random DNA sequences

k-nucleotide.p5.pl

k-nucleotide.p6

Repeatedly update hashtables and k-nucleotide strings

mandelbrot.p6

Generates the Mandelbrot Set fractal

n-body-v2.p6

Perform an N-body simulation of the Jovian planets

n-body.p5.pl

n-body.p6

Perform an N-body simulation of the Jovian planets

regex-dna.p5.pl

regex-dna.p6

Match DNA 8-mers and substitute nucleotides for IUB code

revcomp-v2.p6

Read DNA sequences and write their reverse-complement

revcomp.p6

Read DNA sequences and write their reverse-complement

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.