-- Converts DNA sequences into amino acid sequences -- by Scot Drysdale on 9/26/07 -- Converts a sequence of bases in DNA to a sequence of amino acids dna2proteins :: [Char] -> [Char] dna2proteins (b1:b2:b3:rest) = lookupSure [b1, b2, b3] codes : dna2proteins rest where codes :: [([Char], Char)] codes = [("ATA", 'I'), ("ATC", 'I'), ("ATT", 'I'), ("ATG", 'M'), ("ACA", 'T'), ("ACC", 'T'), ("ACG", 'T'), ("ACT", 'T'), ("AAC", 'N'), ("AAT", 'N'), ("AAA", 'K'), ("AAG", 'K'), ("AGC", 'S'), ("AGT", 'S'), ("AGA", 'R'), ("AGG", 'R'), ("CTA", 'L'), ("CTC", 'L'), ("CTG", 'L'), ("CTT", 'L'), ("CCA", 'P'), ("CCC", 'P'), ("CCG", 'P'), ("CCT", 'P'), ("CAC", 'H'), ("CAT", 'H'), ("CAA", 'Q'), ("CAG", 'Q'), ("CGA", 'R'), ("CGC", 'R'), ("CGG", 'R'), ("CGT", 'R'), ("GTA", 'V'), ("GTC", 'V'), ("GTG", 'V'), ("GTT", 'V'), ("GCA", 'A'), ("GCC", 'A'), ("GCG", 'A'), ("GCT", 'A'), ("GAC", 'D'), ("GAT", 'D'), ("GAA", 'E'), ("GAG", 'E'), ("GGA", 'G'), ("GGC", 'G'), ("GGG", 'G'), ("GGT", 'G'), ("TCA", 'S'), ("TCC", 'S'), ("TCG", 'S'), ("TCT", 'S'), ("TTC", 'F'), ("TTT", 'F'), ("TTA", 'L'), ("TTG", 'L'), ("TAC", 'Y'), ("TAT", 'Y'), ("TAA", '_'), ("TAG", '_'), ("TGC", 'C'), ("TGT", 'C'), ("TGA", '_'), ("TGG", 'W')] dna2proteins _ = [] -- Note 1 or 2 bases at end not converted. -- Looks up a key in a list of (key, datum) pairs. -- Throws an exception if the key is not found. lookupSure :: [Char] -> [([Char], Char)] -> Char lookupSure str ((key, datum) : rest) = if str == key then datum else lookupSure str rest lookupSure str _ = error (str ++ " not found")