Created
March 21, 2011 10:04
-
-
Save antoinevg/879246 to your computer and use it in GitHub Desktop.
Minimal Parsec parser for FASTA sequence data
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 Text.ParserCombinators.Parsec | |
| fasta :: Parser [[String]] | |
| fasta = do a <- many record | |
| eof | |
| return a | |
| record :: Parser [String] | |
| record = do a <- header | |
| b <- dna | |
| return [a, b] | |
| header :: Parser String | |
| header = do char '>' | |
| a <- many anyChar | |
| newline | |
| return a | |
| dna :: Parser String | |
| dna = many nucleotide | |
| nucleotide :: Parser Char | |
| nucleotide = do a <- oneOf "ATCGN" | |
| skipMany newline | |
| return a | |
| main :: IO () | |
| main = do | |
| a <- getContents | |
| case parse fasta "stdin" a of | |
| Left error -> putStr "Error: " >> print error | |
| Right ast -> print ast |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment