module Bio.SeqLoc.OnSeq (
SeqName(..)
, OnSeq(..)
, SeqOffset, SeqPos
, ContigSeqLoc
, SpliceSeqLoc
, andSameSeq
)
where
import Control.Applicative
import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Internal (c2w)
import Data.String
import qualified Data.Attoparsec.Zepto as ZP
import Bio.SeqLoc.LocRepr
import qualified Bio.SeqLoc.Location as Loc
import qualified Bio.SeqLoc.Position as Pos
import qualified Bio.SeqLoc.SpliceLocation as SpLoc
import Bio.SeqLoc.Strand
newtype SeqName = SeqName { unSeqName :: BS.ByteString } deriving (Show, Read, Eq, Ord, IsString)
data OnSeq s = OnSeq { onSeqName :: !SeqName, unOnSeq :: !s } deriving (Show, Read, Eq, Ord)
at :: BS.ByteString
at = BS.singleton '@'
instance Stranded s => Stranded (OnSeq s) where
revCompl (OnSeq name obj) = OnSeq name (revCompl obj)
instance LocRepr s => LocRepr (OnSeq s) where
repr (OnSeq name obj) = BS.concat [ unSeqName name, at, repr obj ]
unrepr = OnSeq <$> (SeqName <$> ZP.takeWhile (/= c2w '@')) <* ZP.string at <*> unrepr
type SeqOffset = OnSeq Pos.Offset
type SeqPos = OnSeq Pos.Pos
type ContigSeqLoc = OnSeq Loc.ContigLoc
type SpliceSeqLoc = OnSeq SpLoc.SpliceLoc
andSameSeq :: (a -> b -> Bool) -> OnSeq a -> OnSeq b -> Bool
andSameSeq p (OnSeq n1 x) (OnSeq n2 y) | n1 == n2 = p x y
| otherwise = False