Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

masak (6289)

masak
  (email not shown publicly)
http://masak.org/carl

Been programming Perl since 2001. Found Perl 6 somewhere around 2004, and fell in love. Now developing November (a Perl 6 wiki), Druid (a Perl 6 board game), pls (a Perl 6 project installer), GGE (a regex engine), and Yapsi (a Perl 6 implementation). Heavy user of and irregular committer to Rakudo.

Journal of masak (6289)

Monday July 06, 2009
11:16 AM

The Genetic Code one-liner in Perl 6

[ #39238 ]

Today on #perl6:

<masak> rakudo: subset DNA of Str where { all(.uc.comb) eq any <A C G T> }; my DNA $dna = "gattaca"; say $dna;
<p6eval> rakudo 0e8a86: OUTPUT«gattaca␤»
<jnthn> rakudo: subset DNA of Str where { all(.uc.comb) eq any <A C G T>}; my DNA $dna = "lolnotdna"; say $dna;
<p6eval> rakudo 0e8a86: OUTPUT«Assignment type check failed [...]
<jnthn> (just checking :-))
<TimToady> course, where not /<-[ACGTactg]>/ might beat all those
<moritz_> but it involves no junction, so it can't be any good :-)
<TimToady> ttaggg &
<masak> halp, TimToady is speaking in DNA bases!
<masak> is my hunch right, and that actually means something as amino acids?
* masak checks
<pyrimidine> yes
<masak> TimToady++
<masak> rakudo: my $dna = "ttaagg"; sub translate($dna) { "FFLLSSSSYY!!CC!WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG".comb[map { :4($_) }, $dna.trans("tcag" => "0123").comb(/.../)] }; say translate($dna)
<p6eval> rakudo 0e8a86: OUTPUT«LR␤»
<masak> that's what I got too.
<pyrimidine> masak: nice!
<masak> I know! :)
<masak> I should blog about it.
<masak> "The Genetic Code one-liner in Perl 6"

A hyper-short summary of what that one-liner does:

  • Convert each base into an integer. $dna.trans("tcag" => "0123")
  • Break up the DNA numbers in triplets. .comb(/.../)
  • Interpret each three-digit number as a quaternary integer between 0 and 63. map { :4($_) }
  • Use these numbers as indexes into an array of 64 one-character strings, each with the character of one amino acid.

Perl 6 feels more like a power tool every day.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.