module Bio.SeqLoc.Position (
Offset(..)
, Pos(..)
, slide
, atPos
)
where
import Control.Applicative
import Control.Arrow
import Control.Monad (liftM)
import qualified Data.ByteString.Char8 as BS
import Bio.Core.Sequence
import Bio.Core.Strand
import Bio.SeqLoc.LocRepr
import Bio.SeqLoc.SeqLike
import Bio.SeqLoc.Strand
instance Enum Offset where
toEnum = Offset . toEnum
fromEnum = fromEnum . unOff
instance Real Offset where
toRational = toRational . unOff
instance Integral Offset where
(Offset n) `quotRem` (Offset d) = (Offset *** Offset) $ n `quotRem` d
toInteger = toInteger . unOff
data Pos = Pos { offset :: !Offset
, strand :: !Strand
}
deriving (Eq, Ord, Show)
instance Stranded Pos where
revCompl (Pos off str) = Pos off (revCompl str)
instance LocRepr Pos where
repr (Pos off str) = BS.concat [ repr off, repr str ]
unrepr = Pos <$> unrepr <*> unrepr
slide :: Pos -> Offset -> Pos
slide (Pos off str) doff = Pos (off + doff) str
atPos :: (SeqLike s) => s -> Pos -> Maybe Char
atPos sequ (Pos off str) = liftM (stranded str) . ntAt sequ $ off