Generate Codons with Python and Haskell

There are 64 (4**3) dna codons, of which Leder and Nirenberg were able to establish the sequence of 54, they code for the 20 standard amino acids (not the 29 my 3rd year project molecular biology undergrads believe to exist). Using python and itertools it’s simple to create all 64 using a generator, although I have no reason to do so.

from itertools import product
for codon in product('ATCG', repeat=3): print codon

yey, codons, I think.

Let’s do the same with haskell, not that I know how to do anything with them afterwards!
First, take three attempts to type ‘first’, now start GHCi

let bases = ["A", "T", "C", "G"]
let codons = [ (a, b, c) | a <- bases, b <- bases, c <- bases]
length codons

That should yield a list of codons, all I need to do now is learn haskell, someone on hacker news/twitter suggested that to learn scala you had to learn haskell first, ho hum.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s