Created
January 26, 2015 01:06
-
-
Save amonshiz/733b600d8a2399adf608 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Bioinformatics.RNANucleotide as R | |
main = do | |
rna <- getLine | |
putStrLn $ R.rnaToProtein rna |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Bioinformatics.RNANucleotide ( | |
RNANucleotide (..), | |
charToRNANucleotide, | |
rnaToProtein | |
) where | |
import Data.Char | |
import Data.List | |
import qualified Data.Map as M | |
import qualified Data.Maybe as Mb | |
import qualified Data.List.Split as S | |
data RNANucleotide = A | C | G | U deriving (Show, Eq, Ord, Read) | |
charToRNANucleotide :: Char -> RNANucleotide | |
charToRNANucleotide c = read [toUpper c] :: RNANucleotide | |
rnaCodonTable = M.fromList [([U,U,U], "F"),([C,U,U], "L"),([A,U,U], "I"),([G,U,U], "V"), | |
([U,U,C], "F"),([C,U,C], "L"),([A,U,C], "I"),([G,U,C], "V"), | |
([U,U,A], "L"),([C,U,A], "L"),([A,U,A], "I"),([G,U,A], "V"), | |
([U,U,G], "L"),([C,U,G], "L"),([A,U,G], "M"),([G,U,G], "V"), | |
([U,C,U], "S"),([C,C,U], "P"),([A,C,U], "T"),([G,C,U], "A"), | |
([U,C,C], "S"),([C,C,C], "P"),([A,C,C], "T"),([G,C,C], "A"), | |
([U,C,A], "S"),([C,C,A], "P"),([A,C,A], "T"),([G,C,A], "A"), | |
([U,C,G], "S"),([C,C,G], "P"),([A,C,G], "T"),([G,C,G], "A"), | |
([U,A,U], "Y"),([C,A,U], "H"),([A,A,U], "N"),([G,A,U], "D"), | |
([U,A,C], "Y"),([C,A,C], "H"),([A,A,C], "N"),([G,A,C], "D"), | |
([U,A,A], "Stop"),([C,A,A], "Q"),([A,A,A], "K"),([G,A,A], "E"), | |
([U,A,G], "Stop"),([C,A,G], "Q"),([A,A,G], "K"),([G,A,G], "E"), | |
([U,G,U], "C"),([C,G,U], "R"),([A,G,U], "S"),([G,G,U], "G"), | |
([U,G,C], "C"),([C,G,C], "R"),([A,G,C], "S"),([G,G,C], "G"), | |
([U,G,A], "Stop"),([C,G,A], "R"),([A,G,A], "R"),([G,G,A], "G"), | |
([U,G,G], "W"),([C,G,G], "R"),([A,G,G], "R"),([G,G,G], "G")] | |
stringToRNAChunks :: String -> [[RNANucleotide]] | |
stringToRNAChunks = S.chunksOf 3 . map charToRNANucleotide | |
lookupProteins :: [[RNANucleotide]] -> [String] | |
lookupProteins = foldr (\rs acc -> if Mb.isJust rs then (Mb.fromJust rs):acc else acc) [] . map (\c -> M.lookup c rnaCodonTable) | |
rnaToProtein :: String -> String | |
rnaToProtein = concat . filter (\s -> s /= "Start" && s /= "Stop") . lookupProteins . stringToRNAChunks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment