seqloc-datafiles 0.1.1 → 0.2
raw patch · 7 files changed
+40/−38 lines, 7 filesdep +biocoredep ~seqloc
Dependencies added: biocore
Dependency ranges changed: seqloc
Files
- seqloc-datafiles.cabal +6/−6
- src/Bio/SeqLoc/Bed.hs +8/−8
- src/Bio/SeqLoc/GTF.hs +18/−16
- src/Bio/SeqLoc/TranscriptTable.hs +3/−3
- src/Bio/SeqLoc/ZeptoUtils.hs +2/−2
- src/GtfToBed.hs +1/−1
- test/GtfIntrons.hs +2/−2
seqloc-datafiles.cabal view
@@ -1,5 +1,5 @@ Name: seqloc-datafiles-Version: 0.1.1+Version: 0.2 Cabal-Version: >= 1.4 Synopsis: Read and write BED and GTF format genome annotations Description: Read and write BED and GTF format genome annotations@@ -20,7 +20,7 @@ Other-modules: Bio.SeqLoc.ZeptoUtils Build-depends: base >= 4.2 && < 5, bytestring, haskell98, attoparsec >= 0.8.5, hashable, unordered-containers,- iteratee >= 0.8.1, seqloc >= 0.0+ iteratee >= 0.8.1, seqloc >= 0.3.1, biocore Hs-Source-Dirs: src Ghc-options: -Wall @@ -29,7 +29,7 @@ Other-modules: Bio.SeqLoc.GTF, Bio.SeqLoc.Bed, Bio.SeqLoc.ZeptoUtils Build-depends: base >= 4.2 && < 5, bytestring, haskell98, attoparsec >= 0.8.5, hashable, unordered-containers,- iteratee >= 0.8.1, seqloc >= 0.0, transformers, monads-tf+ iteratee >= 0.8.1, seqloc >= 0.3.1, biocore, transformers, monads-tf Hs-Source-Dirs: src Ghc-options: -Wall -rtsopts C-Sources: src/rtsopts.c@@ -41,7 +41,7 @@ Other-modules: Bio.SeqLoc.GTF, Bio.SeqLoc.TranscriptTable, Bio.SeqLoc.ZeptoUtils Build-depends: base >= 4.2 && < 5, bytestring, haskell98, attoparsec >= 0.8.5, hashable, unordered-containers,- iteratee >= 0.8.1, seqloc >= 0.0,+ iteratee >= 0.8.1, seqloc >= 0.3.1, biocore, QuickCheck, random Hs-Source-Dirs: src, test Ghc-options: -Wall -rtsopts@@ -54,7 +54,7 @@ Other-modules: Bio.SeqLoc.Bed, Bio.SeqLoc.TranscriptTable, Bio.SeqLoc.ZeptoUtils Build-depends: base >= 4.2 && < 5, bytestring, haskell98, attoparsec >= 0.8.5, hashable, unordered-containers,- iteratee >= 0.8.1, seqloc >= 0.0,+ iteratee >= 0.8.1, seqloc >= 0.3.1, biocore, QuickCheck, random Hs-Source-Dirs: src, test Ghc-options: -Wall@@ -66,7 +66,7 @@ Other-modules: Bio.SeqLoc.GTF, Bio.SeqLoc.TranscriptTable, Bio.SeqLoc.ZeptoUtils Build-depends: base >= 4.2 && < 5, bytestring, haskell98, attoparsec >= 0.8.5, hashable, unordered-containers,- iteratee >= 0.8.1, seqloc >= 0.0,+ iteratee >= 0.8.1, seqloc >= 0.3.1, biocore, QuickCheck, random Hs-Source-Dirs: src, test Ghc-options: -Wall -rtsopts
src/Bio/SeqLoc/Bed.hs view
@@ -40,10 +40,10 @@ -> BS.ByteString transcriptToBed score rgb trx = unfields fields where unfields = BS.intercalate (BS.singleton '\t')- fields = [ unSeqName chrom+ fields = [ unSeqLabel chrom , repr $ chromStart , repr $ chromEnd + 1- , unSeqName . trxId $ trx+ , unSeqLabel . trxId $ trx , score , strandchr , repr $ thickStart@@ -55,7 +55,7 @@ ] (OnSeq chrom loc) = location trx (chromStart, chromEnd) = Loc.bounds loc- strandchr = case Loc.strand loc of Fwd -> "+"; RevCompl -> "-"+ strandchr = case Loc.strand loc of Plus -> "+"; Minus -> "-" (thickStart, thickEnd) = maybe noCds (Loc.bounds . unOnSeq) . cdsLocation $ trx noCds = (chromStart, chromStart - 1) contigs = sortBy (comparing Loc.offset5) . Loc.toContigs $ loc@@ -119,21 +119,21 @@ cdsloc <- if thickStart >= thickEnd then return Nothing else liftM Just $! bedCdsLoc loc thickStart thickEnd- let n = SeqName $ BS.copy name- c = SeqName $ BS.copy chrom+ let n = toSeqLabel $ BS.copy name+ c = toSeqLabel $ BS.copy chrom return $! Transcript n n (OnSeq c loc) cdsloc bedTrxLoc :: (Monad m) => Pos.Offset -> Pos.Offset -> Strand -> [(Pos.Offset, Pos.Offset)] -> m SpLoc.SpliceLoc bedTrxLoc chromStart chromEnd str = maybe badContigs (return . stranded str) . SpLoc.fromContigs . map blockContig- where blockContig (bsize, bstart) = Loc.fromPosLen (Pos.Pos (chromStart + bstart) Fwd) bsize+ where blockContig (bsize, bstart) = Loc.fromPosLen (Pos.Pos (chromStart + bstart) Plus) bsize badContigs = fail $ "Bio.SeqLoc.Bed: bad blocks in " ++ show (chromStart, chromEnd) bedCdsLoc :: (Monad m) => SpLoc.SpliceLoc -> Pos.Offset -> Pos.Offset -> m Loc.ContigLoc bedCdsLoc loc thickStart thickEnd = maybe badCdsLoc return $ do- relstart <- Loc.posInto (Pos.Pos thickStart Fwd) loc- relend <- Loc.posInto (Pos.Pos (thickEnd - 1) Fwd) loc+ relstart <- Loc.posInto (Pos.Pos thickStart Plus) loc+ relend <- Loc.posInto (Pos.Pos (thickEnd - 1) Plus) loc return $! stranded (Loc.strand loc) $ Loc.fromStartEnd (Pos.offset relstart) (Pos.offset relend) where badCdsLoc = fail $ "Bio.SeqLoc.Bed: bad cds in " ++ (BS.unpack . BS.unwords $ [ repr loc, repr thickStart, repr thickEnd ])
src/Bio/SeqLoc/GTF.hs view
@@ -43,20 +43,20 @@ splocLines src trx ftype (OnSeq refname sploc) = map contigLines . Loc.toContigs $ sploc where contigLines contig = let (start0, end0) = Loc.bounds contig strchr = case Loc.strand contig of - Fwd -> "+"- RevCompl -> "-"- in unfields [ unSeqName refname+ Plus -> "+"+ Minus -> "-"+ in unfields [ unSeqLabel refname , src , ftype- , BS.pack . show . Pos.unOffset . (+ 1) $ start0- , BS.pack . show . Pos.unOffset . (+ 1) $ end0+ , BS.pack . show . Pos.unOff . (+ 1) $ start0+ , BS.pack . show . Pos.unOff . (+ 1) $ end0 , "0.0" , strchr , "." , attrs ]- attrs = BS.concat [ "gene_id \"", unSeqName . geneId $ trx- , "\"; transcript_id \"", unSeqName . trxId $ trx+ attrs = BS.concat [ "gene_id \"", unSeqLabel . geneId $ trx+ , "\"; transcript_id \"", unSeqLabel . trxId $ trx , "\"; " ] unfields = BS.intercalate (BS.singleton '\t') @@ -106,7 +106,7 @@ mkTranscript :: BS.ByteString -> [ContigSeqLoc] -> [ContigSeqLoc] -> BS.ByteString -> Either String Transcript mkTranscript trx exons cdses gene = moderr $ do loc <- exonLoc exons cdsloc <- cdsLoc loc cdses- return $ Transcript (SeqName gene) (SeqName trx) loc cdsloc+ return $ Transcript (toSeqLabel gene) (toSeqLabel trx) loc cdsloc where moderr = either (Left . (("Transcript " ++ show trx ++ ": ") ++)) Right exonLoc :: [ContigSeqLoc] -> Either String SpliceSeqLoc@@ -122,7 +122,9 @@ cdsLoc _ [] = return Nothing cdsLoc (OnSeq trxname trxloc) cdses@(_:_) = do (seqname, rawcontigs) <- allSameName cdses- when (trxname /= seqname) $ Left . unwords $ [ "CDS sequence name mismatch", show trxname, show seqname ]+ when (trxname /= seqname) $ Left . unwords $ [ "CDS sequence name mismatch", + show $ unSeqLabel trxname+ , show $ unSeqLabel seqname ] contigs <- sortclocs rawcontigs (contigIn0:contigInRest) <- mapM (cdsIntoTranscript trxloc) contigs cloc <- foldM mergeCLocs contigIn0 contigInRest@@ -139,7 +141,7 @@ mergeCLocs :: Loc.ContigLoc -> Loc.ContigLoc -> Either String Loc.ContigLoc mergeCLocs cloc0 clocnext- | (Loc.strand cloc0 == Fwd) && (Loc.startPos clocnext == Loc.endPos cloc0 `Pos.slide` 1)+ | (Loc.strand cloc0 == Plus) && (Loc.startPos clocnext == Loc.endPos cloc0 `Pos.slide` 1) = return $! Loc.extend (0, Loc.length clocnext) cloc0 | otherwise = Left . unwords $ [ "Merging non-adjacent contigs: " , BS.unpack . repr $ cloc0@@ -147,16 +149,16 @@ ] -allSameName :: [OnSeq a] -> Either String (SeqName, [a])-allSameName s = case group . map onSeqName $ s of+allSameName :: [OnSeq a] -> Either String (SeqLabel, [a])+allSameName s = case group . map onSeqLabel $ s of [(name0:_)] -> return (name0, map unOnSeq s)- names -> Left $ "allSameName: names " ++ show (map (unSeqName . head) names)+ names -> Left $ "allSameName: names " ++ show (map (unSeqLabel . head) names) -data GtfLine = GtfLine { gtfGene, gtfTrx, gtfFtype :: !BS.ByteString, gtfLoc :: !ContigSeqLoc } deriving (Show)+data GtfLine = GtfLine { gtfGene, gtfTrx, gtfFtype :: !BS.ByteString, gtfLoc :: !ContigSeqLoc } data GtfTrxs = GtfTrxs { gtfExonLocs, gtfCdsLocs :: !(HM.HashMap BS.ByteString [ContigSeqLoc]) , gtfTogene :: !(HM.HashMap BS.ByteString BS.ByteString)- } deriving (Show)+ } ftypeCds :: BS.ByteString ftypeCds = BS.pack "CDS"@@ -190,7 +192,7 @@ _frame <- dropField gene <- attr "gene_id" trx <- attr "transcript_id"- let name = SeqName . BS.copy $ seqname+ let name = toSeqLabel . BS.copy $ seqname loc = Loc.fromBoundsStrand (start - 1) (end - 1) str return $! GtfLine gene trx ftype (OnSeq name loc)
src/Bio/SeqLoc/TranscriptTable.hs view
@@ -29,7 +29,7 @@ cdsloc <- if cdslocstr == na then return Nothing else liftM Just $! unreprMaybe cdslocstr- return $! Transcript (SeqName . BS.copy $ geneid) (SeqName . BS.copy $ trxid) trxloc cdsloc+ return $! Transcript (toSeqLabel . BS.copy $ geneid) (toSeqLabel . BS.copy $ trxid) trxloc cdsloc _ -> Nothing -- | Write a transcript table file@@ -38,8 +38,8 @@ -- | Produce a single transcript table line for a 'Transcript', newline not included. unparseLine :: Transcript -> BS.ByteString-unparseLine trx = BS.intercalate (BS.singleton '\t') $ [ unSeqName . geneId $ trx- , unSeqName . trxId $ trx+unparseLine trx = BS.intercalate (BS.singleton '\t') $ [ unSeqLabel . geneId $ trx+ , unSeqLabel . trxId $ trx , repr . location $ trx , maybe na repr . cds $ trx ]
src/Bio/SeqLoc/ZeptoUtils.hs view
@@ -14,8 +14,8 @@ import Bio.SeqLoc.Strand strand :: ZP.Parser Strand-strand = ((ZP.string "+\t" *> return Fwd) <|>- (ZP.string "-\t" *> return RevCompl))+strand = ((ZP.string "+\t" *> return Plus) <|>+ (ZP.string "-\t" *> return Minus)) decfield :: (Integral a) => ZP.Parser a decfield = decimal <* ZP.string "\t"
src/GtfToBed.hs view
@@ -32,7 +32,7 @@ mapM_ (BS.hPutStrLn h . transcriptToBedStd) trxs adjustStop = if confStopIncluded conf then removeDoubleStop else id removeDoubleStop trx = trx { cds = cds trx >>= shortenLoc }- shortenLoc l = Loc.clocOutof (Loc.fromBoundsStrand 0 end Fwd) l+ shortenLoc l = Loc.clocOutof (Loc.fromBoundsStrand 0 end Plus) l where end = max 0 $ Loc.length l - 4 handleErrors (trxs, errs) = do maybe putErrs filePutErrs $ confBadTranscripts conf return trxs
test/GtfIntrons.hs view
@@ -34,8 +34,8 @@ transcriptIntrons trx = zipWith intronTranscript [1..] . junctions $ sploc where (OnSeq refname sploc) = location trx intronTranscript idx jct = Transcript geneid trxid loc Nothing- where geneid = SeqName . flip BS.append "_introns" . unSeqName . geneId $ trx- trxid = SeqName . flip BS.append trxsuffix . unSeqName . trxId $ trx+ where geneid = toSeqLabel . flip BS.append "_introns" . unSeqLabel . geneId $ trx+ trxid = toSeqLabel . flip BS.append trxsuffix . unSeqLabel . trxId $ trx trxsuffix = "_intron" `BS.append` (BS.pack . show $ idx) loc = OnSeq refname (fromMaybe noLoc $ SpLoc.fromContigs [ intron jct ]) noLoc = error $ "Unable to create singleton SpLoc from " ++ (BS.unpack . repr) jct