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.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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