|
| 1 | +-- | This module contains parsing functions for Infernal programs |
| 2 | + |
| 3 | +module Biobase.RNAlien.CMstatParser ( |
| 4 | + module Biobase.RNAlien.Types, |
| 5 | + parseCMstat, |
| 6 | + readCMstat |
| 7 | + ) |
| 8 | +where |
| 9 | + |
| 10 | +import Text.ParserCombinators.Parsec |
| 11 | +import Biobase.RNAlien.Types |
| 12 | + |
| 13 | +-- | parse from input filePath |
| 14 | +parseCMstat :: String -> Either ParseError CMstat |
| 15 | +parseCMstat = parse genParserCMstat "parseCMstat" |
| 16 | + |
| 17 | +-- | parse from input filePath |
| 18 | +readCMstat :: String -> IO (Either ParseError CMstat) |
| 19 | +readCMstat filePath = do |
| 20 | + parsedFile <- parseFromFile genParserCMstat filePath |
| 21 | + return parsedFile |
| 22 | + |
| 23 | +genParserCMstat :: GenParser Char st CMstat |
| 24 | +genParserCMstat = do |
| 25 | + manyTill anyChar (try (string "rel entropy")) |
| 26 | + _ <- newline |
| 27 | + _ <- char '#' |
| 28 | + skipMany1 (char ' ') |
| 29 | + skipMany1 (char '-') |
| 30 | + _ <- newline |
| 31 | + _ <- char '#' |
| 32 | + _ <- manyTill anyChar (try (string "#")) |
| 33 | + _ <- many1 (try (oneOf " -")) |
| 34 | + _ <- newline |
| 35 | + skipMany1 space |
| 36 | + _statIndex <- many1 digit |
| 37 | + skipMany1 space |
| 38 | + _statName <- many1 letter |
| 39 | + skipMany1 space |
| 40 | + _statAccession <- many1 (noneOf " ") |
| 41 | + skipMany1 space |
| 42 | + _statSequenceNumber <- many1 digit |
| 43 | + skipMany1 space |
| 44 | + _statEffectiveSequences <- many1 (oneOf "0123456789.e-") |
| 45 | + skipMany1 space |
| 46 | + _statConsensusLength <- many digit |
| 47 | + skipMany1 space |
| 48 | + _statW <- many1 digit |
| 49 | + skipMany1 space |
| 50 | + _statBasepaires <- many1 digit |
| 51 | + skipMany1 space |
| 52 | + _statBifurcations <- many1 digit |
| 53 | + skipMany1 space |
| 54 | + _statModel <- many1 letter |
| 55 | + skipMany1 space |
| 56 | + _relativeEntropyCM <- many1 (oneOf "0123456789.e-") |
| 57 | + skipMany1 space |
| 58 | + _relativeEntropyHMM <- many1 (oneOf "0123456789.e-") |
| 59 | + _ <- newline |
| 60 | + _ <- char '#' |
| 61 | + _ <- newline |
| 62 | + _ <- eof |
| 63 | + return $ CMstat (readInt _statIndex) _statName _statAccession (readInt _statSequenceNumber) (readDouble _statEffectiveSequences) (readInt _statConsensusLength) (readInt _statW) (readInt _statBasepaires) (readInt _statBifurcations) _statModel (readDouble _relativeEntropyCM) (readDouble _relativeEntropyHMM) |
| 64 | +-- |
| 65 | +readInt :: String -> Int |
| 66 | +readInt = read |
| 67 | + |
| 68 | +readDouble :: String -> Double |
| 69 | +readDouble = read |
0 commit comments