module ELynx.Data.Character.Character
( Character (..),
fromChar,
toChar,
fromString,
toString,
CharacterX (..),
isGap,
CharacterI (..),
isUnknown,
isIUPAC,
isStandard,
convert,
)
where
import Data.ByteString.Internal (c2w, w2c)
import qualified Data.Set as S
import Data.Vector.Unboxed.Base (Unbox)
import Data.Word8 (Word8)
class (Show a, Read a, Eq a, Ord a, Enum a, Bounded a, Unbox a) => Character a where
toWord :: a -> Word8
fromWord :: Word8 -> a
toChar :: Character a => a -> Char
toChar :: a -> Char
toChar = Word8 -> Char
w2c (Word8 -> Char) -> (a -> Word8) -> a -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Word8
forall a. Character a => a -> Word8
toWord
fromChar :: Character a => Char -> a
fromChar :: Char -> a
fromChar = Word8 -> a
forall a. Character a => Word8 -> a
fromWord (Word8 -> a) -> (Char -> Word8) -> Char -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
toString :: Character a => [a] -> String
toString :: [a] -> String
toString = (a -> Char) -> [a] -> String
forall a b. (a -> b) -> [a] -> [b]
map a -> Char
forall a. Character a => a -> Char
toChar
fromString :: Character a => String -> [a]
fromString :: String -> [a]
fromString = (Char -> a) -> String -> [a]
forall a b. (a -> b) -> [a] -> [b]
map Char -> a
forall a. Character a => Char -> a
fromChar
class Character a => CharacterX a where
gap :: a
isGap :: CharacterX a => a -> Bool
isGap :: a -> Bool
isGap a
c = a
c a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
forall a. CharacterX a => a
gap
class CharacterX a => CharacterI a where
unknown :: a
iupac :: [a]
toStandard :: a -> [a]
isUnknown :: CharacterI a => a -> Bool
isUnknown :: a -> Bool
isUnknown a
c = a
c a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
forall a. CharacterI a => a
unknown
iupacLookup :: CharacterI a => S.Set a
iupacLookup :: Set a
iupacLookup = [a] -> Set a
forall a. Ord a => [a] -> Set a
S.fromList [a]
forall a. CharacterI a => [a]
iupac
isIUPAC :: CharacterI a => a -> Bool
isIUPAC :: a -> Bool
isIUPAC a
c = a
c a -> Set a -> Bool
forall a. Ord a => a -> Set a -> Bool
`S.member` Set a
forall a. CharacterI a => Set a
iupacLookup
isStandard :: CharacterI a => a -> Bool
isStandard :: a -> Bool
isStandard a
c = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ a -> Bool
forall a. CharacterI a => a -> Bool
isIUPAC a
c
convert :: (Character a, Character b) => a -> b
convert :: a -> b
convert = Word8 -> b
forall a. Character a => Word8 -> a
fromWord (Word8 -> b) -> (a -> Word8) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Word8
forall a. Character a => a -> Word8
toWord