packages feed

BiobaseEnsembl 0.2.0.0 → 0.2.0.1

raw patch · 6 files changed

+165/−8 lines, 6 files

Files

+ Biobase/GTF.hs view
@@ -0,0 +1,12 @@+-- | Types and functions for NCBI BLAST++--++module Biobase.GTF+  ( module Biobase.GTF.Types+  , module Biobase.GTF.Import+  ) where++import Biobase.GTF.Import (gtfFromFile)+import Biobase.GTF.Export+import Biobase.GTF.Types+
+ Biobase/GTF/Export.hs view
@@ -0,0 +1,18 @@++-- |++module Biobase.GTF.Export where+import Biobase.GTF.Types+import qualified Data.ByteString.Lazy.Char8 as B+import qualified Data.Vector as V+import Data.List++instance Show GTF where+  show (GTF _Entries _Sequence)+    | not (null _Entries) = entriesString+    | otherwise = ""+    where entriesString =  concatMap show _Entries++instance Show GTFEntry where+  show (GTFEntry _gtfSeqid _gtfSource _gtfType _gtfStart _gtfEnd _gtfScore _gtfStrand _gtfPhase _gtfAttributes) =+    (B.unpack _gtfSeqid) ++ "\t" ++ (B.unpack _gtfSource) ++ "\t" ++ (B.unpack _gtfType) ++ "\t" ++ show _gtfStart ++ "\t" ++ show _gtfEnd ++ "\t" ++ (B.unpack _gtfScore) ++ "\t" ++ [_gtfStrand] ++  "\t" ++ (B.unpack _gtfPhase) ++ "\t" ++ (intercalate ";" (V.toList (V.map B.unpack _gtfAttributes))) ++ "\n"
+ Biobase/GTF/Import.hs view
@@ -0,0 +1,89 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE LambdaCase #-}++-- | Parses GTF++module Biobase.GTF.Import (gtfFromFile,+                             parseGTFs,+                            ) where++import Prelude hiding (takeWhile)+import Data.Attoparsec.ByteString.Char8 hiding (isSpace)+import qualified Data.Attoparsec.ByteString.Lazy as L+import qualified Data.ByteString.Char8 as C+import qualified Data.ByteString.Builder as S+import qualified Data.ByteString.Lazy.Char8 as B+import qualified Data.Vector as V+import System.Directory+import Data.Char+import Control.Monad+import Debug.Trace+import Text.Printf+import Biobase.GTF.Types+import qualified Data.Word8 as W++-- | reads and parses GTF from provided filePath+gtfFromFile :: String -> IO [GTF]+gtfFromFile filePath = do+  printf "# reading GTF from file %s\n" filePath+  fileExists <- doesFileExist filePath+  if fileExists+     then parseGTFs <$> B.readFile filePath+     else fail ("# GTF file \"%s\" does not exist\n" ++ filePath)++-- | Read a lazy bytestring and stream out a list of @GTFs@'s.+-- In case, there is a parse error "late" in the file, we might have+-- already streamed out some (or many!) of these results.++parseGTFs :: B.ByteString -> [GTF]+parseGTFs = go+  where go xs = case L.parse genParseGTF xs of+          L.Fail remainingInput ctxts err  -> error $ "parseGTFs failed! " ++ err ++ " ctxt: " ++ show ctxts ++ " head of remaining input: " ++ B.unpack (B.take 1000 remainingInput)+          L.Done remainingInput btr+            | B.null remainingInput  -> [btr]+            | otherwise              -> btr : go remainingInput++genParseGTF :: Parser GTF+genParseGTF = do+  skipMany (try genParseGTFComment)+  _entry <- many1 (try genParseGTFEntry) <?> "GTF entry"+  return $ GTF (V.fromList _entry) B.empty++genParseGTFComment :: Parser String+genParseGTFComment = do+  string "#"+  takeWhile1 (/= '\n')+  endOfLine+  return $ ""++genParseGTFEntry :: Parser GTFEntry+genParseGTFEntry = do+  _gtfSeqid <- takeWhile1 (/= '\t') <?> "seqid"+  char '\t'+  _gtfSource <- takeWhile1 (/= '\t') <?> "source"+  char '\t'+  _gtfType <- takeWhile1 (/= '\t') <?> "type"+  char '\t'+  _gtfStart <- decimal  <?> "start"+  char '\t'+  _gtfEnd <- decimal <?> "end"+  char '\t'+  _gtfScore <- takeWhile1 (/= '\t') <?> "score"+  char '\t'+  _gtfStrand <- (choice [char '+', char '-', char '.']) <?> "strand"+  char '\t'+  _gtfPhase <- takeWhile1 (/= '\t') <?> "phase"+  char '\t'+  _gtfAttributes <- genParseGTFAttributes <?> "GTF attributes"+  endOfLine+  skipMany (try genParseGTFComment)+  return $ GTFEntry (B.fromStrict _gtfSeqid) (B.fromStrict _gtfSource) (B.fromStrict _gtfType) _gtfStart _gtfEnd (B.fromStrict _gtfScore) _gtfStrand (B.fromStrict _gtfPhase) (V.fromList _gtfAttributes)++genParseGTFAttributes :: Parser [B.ByteString]+genParseGTFAttributes = do+  _gtfAtributesString <- takeTill (\a -> a == '\n') <?> "attributes"+  let _gtfAtributes = map B.fromStrict (C.split ';' _gtfAtributesString)+  return $ _gtfAtributes++toLB :: C.ByteString -> B.ByteString+toLB = S.toLazyByteString . S.byteString
+ Biobase/GTF/Types.hs view
@@ -0,0 +1,38 @@++-- | Encoding of GTF++module Biobase.GTF.Types where++import Prelude hiding (takeWhile)+import Data.Attoparsec.ByteString.Char8 hiding (isSpace)+import qualified Data.Attoparsec.ByteString.Lazy as L+import qualified Data.ByteString.Char8 as C+import qualified Data.ByteString.Builder as S+import qualified Data.ByteString.Lazy.Char8 as B+import qualified Data.Vector as V+import System.Directory+import Data.Char+import Control.Monad+import Debug.Trace+import Text.Printf++  -- | Datastructure for GTF http://gmod.org/wiki/GTF+data GTF = GTF+    { gtfEntries :: !(V.Vector GTFEntry),+      gtfSequence :: !B.ByteString+    }+    deriving (Eq)++-- | Datastructure for data lines of GTF http://gmod.org/wiki/GTF+data GTFEntry = GTFEntry+    { gtfSeqid :: !B.ByteString,+      gtfSource :: !B.ByteString,+      gtfType :: !B.ByteString,+      gtfStart :: Int,+      gtfEnd :: Int,+      gtfScore :: !B.ByteString,+      gtfStrand :: Char,+      gtfPhase :: B.ByteString,+      gtfAttributes :: !(V.Vector B.ByteString)+    }+    deriving (Eq)
BiobaseEnsembl.cabal view
@@ -1,5 +1,5 @@ name:           BiobaseEnsembl-version:        0.2.0.0+version:        0.2.0.1 author:         Florian Eggenhofer maintainer:     egg@informatik.uni-freiburg.de homepage:       https://github.com/eggzilla/BiobaseEnsembl@@ -11,7 +11,7 @@ build-type:     Simple stability:      experimental cabal-version:  >= 1.10.0-tested-with:    GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.1+tested-with:    GHC == 8.6.5, GHC == 8.8.1 synopsis:       Ensembl related datastructures and functions description:                 This library contains high through put sequencing and Ensembl-related functionality:@@ -53,6 +53,10 @@     Biobase.GFF3.Import     Biobase.GFF3.Export     Biobase.GFF3.Types+    Biobase.GTF+    Biobase.GTF.Import+    Biobase.GTF.Export+    Biobase.GTF.Types     Biobase.Ensembl.REST.Types    ghc-options:@@ -64,5 +68,5 @@  source-repository this   type:     git-  location: https://github.com/eggzilla/BiobaseEnsembl/tree/0.2.0.0-  tag:      0.2.0.0+  location: https://github.com/eggzilla/BiobaseEnsembl/tree/0.2.0.1+  tag:      0.2.0.1
ChangeLog.md view
@@ -1,9 +1,5 @@ -*-change-log-*- -### 0.2.0.0 [Florian Eggenhofer](mailto:egg@cs.uni-freiburg.de) 17. December 2019--	* Construction start from input alignment for Scan and Alien-	* Alien is working fully offline, by using offline taxonomy database  ### 0.1.0.0 [Florian Eggenhofer](mailto:egg@cs.uni-freiburg.de) 22. August 2018