module Bio.Location.Strand ( Strand(..)
                           , Stranded(..), stranded
                           )
    where 

import qualified Data.ByteString.Lazy.Char8 as LBS
import Data.Ix (Ix)

import Bio.Sequence.SeqData

-- | Sequence strand
data Strand = Fwd | RevCompl deriving (Eq, Ord, Show, Read, Bounded, Enum, Ix)

-- | Anything, such as a location or a sequence, which lies on a
-- strand and can thus be reverse complemented.
class Stranded s where
    revCompl :: s -> s

stranded :: (Stranded s) => Strand -> s -> s
stranded Fwd      = id
stranded RevCompl = revCompl

instance Stranded Strand where
    revCompl Fwd      = RevCompl
    revCompl RevCompl = Fwd

instance Stranded Char where
    revCompl = compl

-- Avoid using -XTypeSynonymInstances
instance Stranded LBS.ByteString where
    revCompl = LBS.reverse . LBS.map compl