Paste: A Perl snippet

Author: dmpk2k
Mode: perl
Date: Wed, 3 Jun 2009 07:42:33
Plain Text |
#!/usr/bin/perl

# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# Contributed by dmpk2k

use POSIX;


$/ = '>';                           # change line delimiter to > instead of \n
<STDIN>;                            # skip first result


while (<STDIN>) {
  s/^(.*?)\n//;                     # chop off description and print it
  print ">", $1, "\n";

  tr{wsatugcyrkmbdhvnATUGCYRKMBDHVN\n>}               # translate sequence
    {WSTAACGRYMKVHDBNTAACGRYMKVHDBN}d;

  my $sequence   = reverse;
  my $iterations = ceil(length($sequence) / 60) - 1;

  for my $count (0 .. $iterations) {                  # print reverse complement
    print substr($sequence, $count * 60, 60), "\n"
  }
}

Annotation: Version using a >=5.10 feature

Author: dmpk2k
Mode: perl
Date: Wed, 3 Jun 2009 07:54:53
Plain Text |
#!/usr/bin/perl

# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# Contributed by dmpk2k

use 5.010;
use POSIX;


$/ = '>';                           # change line delimiter to > instead of \n
<STDIN>;                            # skip first result


while (<STDIN>) {
  s/^(.*?)\n//;                     # chop off description and print it
  say ">", $1;

  tr{wsatugcyrkmbdhvnATUGCYRKMBDHVN\n>}               # translate sequence
    {WSTAACGRYMKVHDBNTAACGRYMKVHDBN}d;

  my $sequence   = reverse;
  my $iterations = ceil(length($sequence) / 60) - 1;

  for my $count (0 .. $iterations) {                  # print reverse complement
    say substr($sequence, $count * 60, 60);
  }
}

New Annotation

Summary:
Author:
Mode:
Body: