Biologists are using Haskell?

I find Haskell interesting, I’ve tried to work my way through Real World Haskell and failed miserably. I then tried Learn You a Haskell, it’s a really great book, the author does a great job of introducing new concepts at the right speed for me … until chapter 11. However, some biologists are using it to do some interesting work.

So I figured why not try doing something with it, something I won’t use, that isn’t complicated.

import System.IO
import Data.List

parseFasta :: [(String,String)] -> [String] -> [(String, String)]
parseFasta acc [] = acc
parseFasta acc (x:xs)
    | isPrefixOf ">" x == True = parseFasta ((x, "") : acc) xs
    | otherwise = parseFasta (appendString acc x) xs

appendString :: [(String,String)] -> String -> [(String, String)]
appendString acc newstring = case acc of (name,seq):xs -> (name,seq++newstring):xs
                                         _ -> [(newstring, "")]

main = do
        content <- readFile "1HNN.fasta"
        let fasta = parseFasta [] (lines content)
        mapM print fasta

For the stuff I am doing at the moment I can’t justify learning Haskell – shame.

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.