Skip to content

Commit

Permalink
Version 0.1.3.24. GB parser made more verbose. (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
vks4git authored Sep 10, 2021
1 parent 6d8cecb commit 1e2a1e7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

## [0.1.3.23] - 2021-07-06
### Changed
- GB parser made more verbose.

## [0.1.3.23] - 2021-07-06
### Added
Added ASN hydrogen names sometimes set by Scho
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cobot-io
version: 0.1.3.23
version: 0.1.3.24
github: "biocad/cobot-io"
license: BSD3
category: Bio
Expand Down
36 changes: 20 additions & 16 deletions src/Bio/GB/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import Bio.GB.Type (Feature (..), Form (..), GenBankSequence (..)
Meta (..), Reference (..), Source (..), Version (..))
import Bio.Sequence (MarkedSequence, Range, markedSequence)
import Control.Applicative ((<|>))
import Control.Monad.Fail (fail)
import Data.Attoparsec.Combinator (manyTill)
import Data.Attoparsec.Text (Parser, char, decimal, digit, endOfInput, endOfLine, letter,
many', many1', satisfy, string, takeWhile, takeWhile1)
many', many1', satisfy, string, takeWhile, takeWhile1, try,
(<?>))
import Data.Bifunctor (bimap)
import Data.Char (isAlphaNum, isSpace, isUpper)
import Data.Functor (($>))
Expand All @@ -21,8 +23,8 @@ import Prelude hiding (takeWhile)
--
genBankP :: Parser GenBankSequence
genBankP = GenBankSequence
<$> metaP
<*> gbSeqP
<$> (metaP <?> "Meta parser")
<*> (gbSeqP <?> "GB sequence parser")
<* string "//" <* eolSpaceP <* endOfInput

--------------------------------------------------------------------------------
Expand All @@ -31,15 +33,15 @@ genBankP = GenBankSequence

metaP :: Parser Meta
metaP = do
locus' <- locusP
locus' <- locusP <?> "Locus parser"

definitionM <- wrapMP definitionP
accessionM <- wrapMP accessionP
versionM <- wrapMP versionP
keywordsM <- wrapMP keywordsP
sourceM <- wrapMP sourceP
referencesL <- many' referenceP
commentsL <- many' commentP
definitionM <- wrapMP definitionP <?> "Definition parser"
accessionM <- wrapMP accessionP <?> "Accession parser"
versionM <- wrapMP versionP <?> "Version parser"
keywordsM <- wrapMP keywordsP <?> "Keywords parser"
sourceM <- wrapMP sourceP <?> "Source parser"
referencesL <- many' referenceP <?> "References parser"
commentsL <- many' commentP <?> "Comments parser"

pure $ Meta locus' definitionM accessionM versionM keywordsM sourceM referencesL commentsL

Expand Down Expand Up @@ -108,7 +110,7 @@ featuresP :: Parser [(Feature, Range)]
featuresP = -- skip unknown fields and stop on line with "FEATURES"
manyTill (textWithSpacesP <* eolSpaceP) (string "FEATURES") *> space
*> textWithSpacesP <* eolSpaceP
*> many1' featureP
*> many1' (featureP <?> "Single feature parser")

featureP :: Parser (Feature, Range)
featureP = do
Expand All @@ -122,7 +124,9 @@ featureP = do
pure (Feature featureName' strand53 props, range)

rangeP :: Parser (Bool, Range)
rangeP = (string "complement(" *> rP False <* char ')') <|> rP True
rangeP = (string "join" *> fail "Unsupported range with join(..)")
<|> (string "complement(" *> rP False <* char ')')
<|> rP True
where
rP :: Bool -> Parser (Bool, Range)
rP b = fmap (bimap pred id)
Expand Down Expand Up @@ -159,7 +163,7 @@ featureIndent2 = pack $ replicate 21 ' '
--------------------------------------------------------------------------------

originP :: Parser String
originP = string "ORIGIN" *> eolSpaceP
originP = (string "ORIGIN" <?> "String ORIGIN") *> eolSpaceP
*> pure toText
<*> many1' (space *> many1' digit *> space1
*> many1' (many1' letter <* (space1 <|> eolSpaceP)))
Expand All @@ -172,8 +176,8 @@ originP = string "ORIGIN" *> eolSpaceP
--------------------------------------------------------------------------------
gbSeqP :: Parser (MarkedSequence Feature Char)
gbSeqP = do
features <- featuresP
origin <- originP
features <- (featuresP <?> "Features parser")
origin <- (originP <?> "Origin parser")

either (fail . unpack) pure (markedSequence origin features)

Expand Down

0 comments on commit 1e2a1e7

Please sign in to comment.