cobot-io 0.1.5.3 → 0.1.5.4
raw patch · 7 files changed
+43/−9 lines, 7 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Bio.FASTA: fromFile :: (MonadFail m, MonadIO m) => FilePath -> m (Fasta Char)
+ Bio.FASTA: fromFile :: (MonadFail m, MonadIO m, ParsableFastaToken a) => FilePath -> m (Fasta a)
Files
- ChangeLog.md +3/−0
- cobot-io.cabal +6/−3
- src/Bio/FASTA.hs +1/−1
- src/Bio/FASTA/Parser.hs +7/−1
- test/FASTA/order10.fasta +2/−0
- test/FASTA/order9.fasta +8/−0
- test/FASTASpec.hs +16/−4
ChangeLog.md view
@@ -2,6 +2,9 @@ ## [Unreleased] +## [0.1.5.4] - 2024-05-16+- Fix Fasta parser for unknown modifications on the end of the line.+ ## [0.1.5.3] - 2023-12-08 - Update tests and dependencies.
cobot-io.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: cobot-io-version: 0.1.5.3+version: 0.1.5.4 synopsis: Biological data file formats and IO description: Please see the README on GitHub at <https://github.com/biocad/cobot-io#readme> category: Bio@@ -22,8 +22,9 @@ || ==9.0.2 || ==9.2.8 || ==9.4.8- || ==9.6.3- || ==9.8.1+ || ==9.6.5+ || ==9.8.2+ || ==9.10.1 extra-source-files: README.md@@ -35,6 +36,7 @@ test/GB/pIntA-TRBV.gb test/FASTA/correct.fasta test/FASTA/order1.fasta+ test/FASTA/order10.fasta test/FASTA/order2.fasta test/FASTA/order3.fasta test/FASTA/order4.fasta@@ -42,6 +44,7 @@ test/FASTA/order6.fasta test/FASTA/order7.fasta test/FASTA/order8.fasta+ test/FASTA/order9.fasta test/MAE/Capri.mae test/MAE/docking_1.mae test/MAE/docking_1_2.mae
src/Bio/FASTA.hs view
@@ -28,7 +28,7 @@ -- | Reads 'FastaSequence' from given file. ---fromFile :: (MonadFail m, MonadIO m) => FilePath -> m (Fasta Char)+fromFile :: (MonadFail m, MonadIO m, ParsableFastaToken a) => FilePath -> m (Fasta a) fromFile f = liftIO (readFile f) >>= either (fail . errorBundlePretty) pure . parse fastaP (takeBaseName f) -- | Writes 'FastaSequence' to file.
src/Bio/FASTA/Parser.hs view
@@ -36,8 +36,14 @@ parseOnly :: Parsec Void Text a -> Text -> Either String a parseOnly p s = first errorBundlePretty $ parse p "input.fasta" s +-- Using 'hspace1' instead of just 'space1' because our 'fastaLine' parser+-- expects each line to end with line-ending or end of file. But if 'sc' consumes end-of-line,+-- 'lexeme' in 'unknownP' also will and 'fastaLine' will not know that line has ended and will+-- expect more symbols.+--+-- 'hspace1' consumes only "horizontal" space, leaving line-ending for 'fastaLine'. sc :: Parser ()-sc = L.space space1 empty empty+sc = L.space hspace1 empty empty lexeme :: Parser a -> Parser a lexeme = L.lexeme sc
+ test/FASTA/order10.fasta view
@@ -0,0 +1,2 @@+>mol1+[FAM]ACGT[UNK][
+ test/FASTA/order9.fasta view
@@ -0,0 +1,8 @@+>mol1+[FAM]ACGT[UNK]++>mol2+[HEX]ACCGT++>mol3+[HEX]ACGTCA[UNK]
test/FASTASpec.hs view
@@ -10,9 +10,9 @@ import System.Directory (removeFile) import Test.Hspec -import Bio.FASTA (fastaP, fromFile, toFile)+import Bio.FASTA (ParsableFastaToken, fastaP, fromFile, toFile) import Bio.FASTA.Parser (parseOnly)-import Bio.FASTA.Type (Fasta, FastaItem (..))+import Bio.FASTA.Type (Fasta, FastaItem (..), ModItem (..), Modification (..)) import Bio.Sequence (bareSequence) correctFasta1 :: Fasta Char@@ -45,6 +45,16 @@ badFasta8 :: Either String (Fasta Char) badFasta8 = Left "input.fasta:21:5:\n |\n21 | CMV + enhMCK + prcTnT-2\r\n | ^^\nunexpected \"+ \"\nexpecting end of input, end of line, or letter\n" +correctFasta9 :: Fasta ModItem+correctFasta9 =+ [ FastaItem "mol1" $ bareSequence [Mod (Unknown "[FAM]"),Letter 'A',Letter 'C',Letter 'G',Letter 'T',Mod (Unknown "[UNK]")]+ , FastaItem "mol2" $ bareSequence [Mod (Unknown "[HEX]"),Letter 'A',Letter 'C',Letter 'C',Letter 'G',Letter 'T']+ , FastaItem "mol3" $ bareSequence [Mod (Unknown "[HEX]"),Letter 'A',Letter 'C',Letter 'G',Letter 'T',Letter 'C',Letter 'A',Mod (Unknown "[UNK]")]+ ]++badFasta10 :: Either String (Fasta ModItem)+badFasta10 = Left "input.fasta:2:16:\n|\n2|[FAM]ACGT[UNK][\n|^\nunexpectednewline\nexpectingmodificationname\n"+ fastaSpec :: Spec fastaSpec = describe "Fasta files parser" $ do describe "fromFile" $ do@@ -56,19 +66,21 @@ parseBadFile "test/FASTA/order6.fasta" badFasta6 parseBadFile "test/FASTA/order7.fasta" badFasta7 parseBadFile "test/FASTA/order8.fasta" badFasta8+ parseFile "test/FASTA/order9.fasta" correctFasta9+ parseBadFile "test/FASTA/order10.fasta" badFasta10 describe "toFile" $ do writeFile "test/FASTA/input.fasta" correctFasta5 writeFile "test/FASTA/input.fasta" correctFasta1 writeFile "test/FASTA/input.fasta" correctFasta3 -parseFile :: FilePath -> Fasta Char -> Spec+parseFile :: (Show a, Eq a, ParsableFastaToken a) => FilePath -> Fasta a -> Spec parseFile path cf = it ("correctly parses good fasta from file " <> path) $ do fasta <- fromFile path fasta `shouldBe` cf -parseBadFile :: FilePath -> Either String (Fasta Char) -> Spec+parseBadFile :: (Show a, Eq a, ParsableFastaToken a) => FilePath -> Either String (Fasta a) -> Spec parseBadFile path cf = it ("correctly parses bad fasta from file " <> path) $ do res <- liftIO (readFile path)