uniprot-kb 0.1.0.0 → 0.1.0.1
raw patch · 6 files changed
+67/−37 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Bio.Uniprot.Type: Record :: ID -> AC -> DT -> DE -> [GN] -> OS -> Maybe OG -> OC -> Maybe OX -> [OH] -> [Reference] -> [CC] -> [DR] -> PE -> KW -> [FT] -> SQ -> Record
+ Bio.Uniprot.Type: Record :: ID -> AC -> DT -> DE -> [GN] -> OS -> Maybe OG -> OC -> OX -> [OH] -> [Reference] -> [CC] -> [DR] -> PE -> Maybe KW -> [FT] -> SQ -> Record
- Bio.Uniprot.Type: [$sel:kw:Record] :: Record -> KW
+ Bio.Uniprot.Type: [$sel:kw:Record] :: Record -> Maybe KW
- Bio.Uniprot.Type: [$sel:ox:Record] :: Record -> Maybe OX
+ Bio.Uniprot.Type: [$sel:ox:Record] :: Record -> OX
Files
- ChangeLog.md +5/−0
- README.md +21/−4
- src/Bio/Uniprot/Parser.hs +35/−27
- src/Bio/Uniprot/Type.hs +2/−2
- test/Spec.hs +2/−2
- uniprot-kb.cabal +2/−2
ChangeLog.md view
@@ -7,5 +7,10 @@ ## [Unreleased] +## 0.1.0.1+* Small fixes in description fields read+* Documentation fixes+* Usage example in README+ ## 0.1.0.0 * Any UniProt-KB file can be parsed
README.md view
@@ -15,12 +15,24 @@ ## Usage example -To use the parser and types import:-```-λ> import Bio.Uniprot+You can use this simple code to parse any UniProt file:++``` haskell+import Bio.Uniprot+import Data.Attoparsec.Text (parseOnly)+import Data.Text (Text)+import qualified Data.Text.IO as TIO+import Text.Pretty.Simple (pPrint)++main :: IO ()+main = do+ uniprot <- TIO.getContents+ case parseOnly parseRecord uniprot of+ Left err -> putStrLn "Error on parse"+ Right obj -> pPrint obj ``` -Than you can parse any `Text` of UniProt by using `parseRecord` function. The result will be presented by+So you can parse any stdin `Text` of UniProt by using `parseRecord` function. The result will be presented by a `Record` datatype: ``` haskell data Record = Record@@ -42,4 +54,9 @@ , ft :: [FT] , sq :: SQ } deriving (Show, Eq, Ord)+```++You can run this to test the implementation:+``` bash+stack runhaskell uniprot.hs < example/LOLA2_DROME.dat ```
src/Bio/Uniprot/Parser.hs view
@@ -3,7 +3,7 @@ {-# LANGUAGE TupleSections #-} module Bio.Uniprot.Parser where -import Prelude hiding (concat, init, null)+import Prelude hiding (init, null) import qualified Prelude as P (concat, id, init) import Bio.Uniprot.Type@@ -16,8 +16,6 @@ splitOn, unpack, unwords) import Data.Void -import Debug.Trace (trace)- -- |Describes possible name type of DE section. data NameType = RecName | AltName | SubName | Flags | None deriving (Show)@@ -212,6 +210,7 @@ char '.' pure OH{..} +-- |Parses RN, RP, RC, RX, RG, RA, RT and RL lines of UniProt-KB text file. parseRef :: Parser Reference parseRef = do rn <- parseRN@@ -225,7 +224,7 @@ rt <- optional (parseRT <* endOfLine) rl <- parseRL pure Reference{..}- where + where parseRN :: Parser Int parseRN = (string "RN [" *> decimal) <* char ']' @@ -260,6 +259,7 @@ string "RL " pack . P.init <$> parseMultiLineComment "RL" 3 +-- |Parses CC lines of UniProt-KB text file. parseCC :: Parser CC parseCC = do string "CC -!- "@@ -269,6 +269,7 @@ comment <- pack <$> parseMultiLineComment "CC" 7 pure CC{..} +-- |Parses DR lines of UniProt-KB text file. parseDR :: Parser DR parseDR = do string "DR "@@ -327,7 +328,7 @@ splitStr n acc ('(':xs) = splitStr (n+1) ('(':acc) xs splitStr n acc (')':xs) = splitStr (n-1) (')':acc) xs splitStr n acc (x:xs) = splitStr n (x:acc) xs- + -- |Parses SQ lines of UniProt-KB text file. parseSQ :: Parser SQ parseSQ = do@@ -352,28 +353,29 @@ -- |Parses whole UniProt-KB record. parseRecord :: Parser Record-parseRecord = Record <$> (parseID <* endOfLine)- <*> (parseAC <* endOfLine)- <*> (parseDT <* endOfLine)- <*> (parseDE <* endOfLine)- <*> (parseGN <* endOfLine)- <*> (parseOS <* endOfLine)- <*> optional (parseOG <* endOfLine)- <*> (parseOC <* endOfLine)- <*> optional (parseOX <* endOfLine)- <*> many' (parseOH <* endOfLine)- <*> many' (parseRef <* endOfLine)- <*> many' (parseCC <* endOfLine)- <*> many' (parseDR <* endOfLine)- <*> (parsePE <* endOfLine)- <*> (parseKW <* endOfLine)- <*> many' (parseFT <* endOfLine)- <*> (parseSQ <* endOfLine)- <* parseEnd+parseRecord = Record <$> (parseID <* endOfLine)+ <*> (parseAC <* endOfLine)+ <*> (parseDT <* endOfLine)+ <*> (parseDE <* endOfLine)+ <*> option [] (parseGN <* endOfLine)+ <*> (parseOS <* endOfLine)+ <*> optional (parseOG <* endOfLine)+ <*> (parseOC <* endOfLine)+ <*> (parseOX <* endOfLine)+ <*> many' (parseOH <* endOfLine)+ <*> many' (parseRef <* endOfLine)+ <*> many' (parseCC <* endOfLine)+ <*> many' (parseDR <* endOfLine)+ <*> (parsePE <* endOfLine)+ <*> optional (parseKW <* endOfLine)+ <*> many' (parseFT <* endOfLine)+ <*> (parseSQ <* endOfLine)+ <* parseEnd -- = Helper parsers -- |Transforms any parser to a parser of maybe value.+-- -- >>> parseOnly (optional digit) "1" -- Right (Just 1) --@@ -411,7 +413,7 @@ comm <- (:) <$> parseTillEnd <*> many' (do endOfLine string start- count (skip - 1) space -- leave one space to separate words+ count (skip - 1) (char ' ') -- leave one space to separate words parseTillEnd) pure $ hyphenConcat comm @@ -429,6 +431,12 @@ hyphenConcat :: [String] -> String hyphenConcat [] = [] hyphenConcat [x] = x-hyphenConcat (x:y:ys) = if last x == '-'- then x ++ tail y ++ hyphenConcat ys- else x ++ y ++ hyphenConcat ys+hyphenConcat (x:y:ys) = x ++ hyphenConcat (sy:ys)+ where+ sy :: String+ sy | last x == '-' = tail y+ | isAA (last x) && isAA (y !! 1) = tail y+ | otherwise = y+ + isAA :: Char -> Bool+ isAA = inClass "ACDEFGHIKLMNPQRSTVWY"
src/Bio/Uniprot/Type.hs view
@@ -246,13 +246,13 @@ , os :: OS , og :: Maybe OG , oc :: OC- , ox :: Maybe OX+ , ox :: OX , oh :: [OH] , refs :: [Reference] , cc :: [CC] , dr :: [DR] , pe :: PE- , kw :: KW+ , kw :: Maybe KW , ft :: [FT] , sq :: SQ } deriving (Show, Eq, Ord)
test/Spec.hs view
@@ -941,6 +941,6 @@ it "parses PD1 example" $ do let record = Record idAns acAns dtAns deAns gnAns osAns Nothing ocAns- (Just oxAns) [] refAns ccAns- drAns peAns kwAns ftAns sqAns+ oxAns [] refAns ccAns+ drAns peAns (Just kwAns) ftAns sqAns parseOnly parseRecord pd1Str `shouldBe` Right record
uniprot-kb.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 35141853a683c97f0604c324c743203061f6bba440e50259a2f29dcc8d8825cc+-- hash: 46801dc834178bde36de5bfcd64e4b397b76da7ac4dbe6f22b7275f5a1661110 name: uniprot-kb-version: 0.1.0.0+version: 0.1.0.1 synopsis: UniProt-KB format parser description: Specification implementation of https://web.expasy.org/docs/userman.html category: Bio