{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}

-- |
-- Module      :  ELynx.Data.AminoAcid
-- Description :  Amino acid related types and functions
-- Copyright   :  (c) Dominik Schrempf 2021
-- License     :  GPL-3.0-or-later
--
-- Maintainer  :  dominik.schrempf@gmail.com
-- Stability   :  unstable
-- Portability :  portable
--
-- Creation date: Thu Oct  4 18:26:35 2018.
--
-- See header of 'ELynx.Data.Alphabet.Alphabet'.
--
-- Amino acids with gaps and translation stops.
--
-- @
-- Amino Acid Code:  Three letter Code:  Amino Acid:
-- ----------------  ------------------  -----------
-- A                 Ala                 Alanine
-- C                 Cys                 Cysteine
-- D                 Asp                 Aspartic Acid
-- E                 Glu                 Glutamic Acid
-- F                 Phe                 Phenylalanine
-- G                 Gly                 Glycine
-- H                 His                 Histidine
-- I                 Ile                 Isoleucine
-- K                 Lys                 Lysine
-- L                 Leu                 Leucine
-- M                 Met                 Methionine
-- N                 Asn                 Asparagine
-- P                 Pro                 Proline
-- Q                 Gln                 Glutamine
-- R                 Arg                 Arginine
-- S                 Ser                 Serine
-- T                 Thr                 Threonine
-- V                 Val                 Valine
-- W                 Trp                 Tryptophan
-- Y                 Tyr                 Tyrosine
-- ----------------  ------------------  -----------
-- *                 Stp                 No amino acid
-- ----------------  ------------------  -----------
-- -                 Gap                 No amino acid (preferred)
-- .                 Gap                 No amino acid
-- @
module ELynx.Data.Character.AminoAcidS
  ( AminoAcidS (..),
  )
where

import Data.ByteString.Internal (c2w, w2c)
import Data.Vector.Unboxed.Deriving
import Data.Word8
import qualified ELynx.Data.Character.Character as C

-- | Amino acids.
data AminoAcidS
  = A
  | C
  | D
  | E
  | F
  | G
  | H
  | I
  | K
  | L
  | M
  | N
  | P
  | Q
  | R
  | S
  | T
  | V
  | W
  | Y
  | Stop
  | Gap
  deriving (Int -> AminoAcidS -> ShowS
[AminoAcidS] -> ShowS
AminoAcidS -> String
(Int -> AminoAcidS -> ShowS)
-> (AminoAcidS -> String)
-> ([AminoAcidS] -> ShowS)
-> Show AminoAcidS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AminoAcidS] -> ShowS
$cshowList :: [AminoAcidS] -> ShowS
show :: AminoAcidS -> String
$cshow :: AminoAcidS -> String
showsPrec :: Int -> AminoAcidS -> ShowS
$cshowsPrec :: Int -> AminoAcidS -> ShowS
Show, ReadPrec [AminoAcidS]
ReadPrec AminoAcidS
Int -> ReadS AminoAcidS
ReadS [AminoAcidS]
(Int -> ReadS AminoAcidS)
-> ReadS [AminoAcidS]
-> ReadPrec AminoAcidS
-> ReadPrec [AminoAcidS]
-> Read AminoAcidS
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AminoAcidS]
$creadListPrec :: ReadPrec [AminoAcidS]
readPrec :: ReadPrec AminoAcidS
$creadPrec :: ReadPrec AminoAcidS
readList :: ReadS [AminoAcidS]
$creadList :: ReadS [AminoAcidS]
readsPrec :: Int -> ReadS AminoAcidS
$creadsPrec :: Int -> ReadS AminoAcidS
Read, AminoAcidS -> AminoAcidS -> Bool
(AminoAcidS -> AminoAcidS -> Bool)
-> (AminoAcidS -> AminoAcidS -> Bool) -> Eq AminoAcidS
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AminoAcidS -> AminoAcidS -> Bool
$c/= :: AminoAcidS -> AminoAcidS -> Bool
== :: AminoAcidS -> AminoAcidS -> Bool
$c== :: AminoAcidS -> AminoAcidS -> Bool
Eq, Eq AminoAcidS
Eq AminoAcidS
-> (AminoAcidS -> AminoAcidS -> Ordering)
-> (AminoAcidS -> AminoAcidS -> Bool)
-> (AminoAcidS -> AminoAcidS -> Bool)
-> (AminoAcidS -> AminoAcidS -> Bool)
-> (AminoAcidS -> AminoAcidS -> Bool)
-> (AminoAcidS -> AminoAcidS -> AminoAcidS)
-> (AminoAcidS -> AminoAcidS -> AminoAcidS)
-> Ord AminoAcidS
AminoAcidS -> AminoAcidS -> Bool
AminoAcidS -> AminoAcidS -> Ordering
AminoAcidS -> AminoAcidS -> AminoAcidS
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: AminoAcidS -> AminoAcidS -> AminoAcidS
$cmin :: AminoAcidS -> AminoAcidS -> AminoAcidS
max :: AminoAcidS -> AminoAcidS -> AminoAcidS
$cmax :: AminoAcidS -> AminoAcidS -> AminoAcidS
>= :: AminoAcidS -> AminoAcidS -> Bool
$c>= :: AminoAcidS -> AminoAcidS -> Bool
> :: AminoAcidS -> AminoAcidS -> Bool
$c> :: AminoAcidS -> AminoAcidS -> Bool
<= :: AminoAcidS -> AminoAcidS -> Bool
$c<= :: AminoAcidS -> AminoAcidS -> Bool
< :: AminoAcidS -> AminoAcidS -> Bool
$c< :: AminoAcidS -> AminoAcidS -> Bool
compare :: AminoAcidS -> AminoAcidS -> Ordering
$ccompare :: AminoAcidS -> AminoAcidS -> Ordering
$cp1Ord :: Eq AminoAcidS
Ord, Int -> AminoAcidS
AminoAcidS -> Int
AminoAcidS -> [AminoAcidS]
AminoAcidS -> AminoAcidS
AminoAcidS -> AminoAcidS -> [AminoAcidS]
AminoAcidS -> AminoAcidS -> AminoAcidS -> [AminoAcidS]
(AminoAcidS -> AminoAcidS)
-> (AminoAcidS -> AminoAcidS)
-> (Int -> AminoAcidS)
-> (AminoAcidS -> Int)
-> (AminoAcidS -> [AminoAcidS])
-> (AminoAcidS -> AminoAcidS -> [AminoAcidS])
-> (AminoAcidS -> AminoAcidS -> [AminoAcidS])
-> (AminoAcidS -> AminoAcidS -> AminoAcidS -> [AminoAcidS])
-> Enum AminoAcidS
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: AminoAcidS -> AminoAcidS -> AminoAcidS -> [AminoAcidS]
$cenumFromThenTo :: AminoAcidS -> AminoAcidS -> AminoAcidS -> [AminoAcidS]
enumFromTo :: AminoAcidS -> AminoAcidS -> [AminoAcidS]
$cenumFromTo :: AminoAcidS -> AminoAcidS -> [AminoAcidS]
enumFromThen :: AminoAcidS -> AminoAcidS -> [AminoAcidS]
$cenumFromThen :: AminoAcidS -> AminoAcidS -> [AminoAcidS]
enumFrom :: AminoAcidS -> [AminoAcidS]
$cenumFrom :: AminoAcidS -> [AminoAcidS]
fromEnum :: AminoAcidS -> Int
$cfromEnum :: AminoAcidS -> Int
toEnum :: Int -> AminoAcidS
$ctoEnum :: Int -> AminoAcidS
pred :: AminoAcidS -> AminoAcidS
$cpred :: AminoAcidS -> AminoAcidS
succ :: AminoAcidS -> AminoAcidS
$csucc :: AminoAcidS -> AminoAcidS
Enum, AminoAcidS
AminoAcidS -> AminoAcidS -> Bounded AminoAcidS
forall a. a -> a -> Bounded a
maxBound :: AminoAcidS
$cmaxBound :: AminoAcidS
minBound :: AminoAcidS
$cminBound :: AminoAcidS
Bounded)

toWord :: AminoAcidS -> Word8
toWord :: AminoAcidS -> Word8
toWord AminoAcidS
A = Char -> Word8
c2w Char
'A'
toWord AminoAcidS
C = Char -> Word8
c2w Char
'C'
toWord AminoAcidS
D = Char -> Word8
c2w Char
'D'
toWord AminoAcidS
E = Char -> Word8
c2w Char
'E'
toWord AminoAcidS
F = Char -> Word8
c2w Char
'F'
toWord AminoAcidS
G = Char -> Word8
c2w Char
'G'
toWord AminoAcidS
H = Char -> Word8
c2w Char
'H'
toWord AminoAcidS
I = Char -> Word8
c2w Char
'I'
toWord AminoAcidS
K = Char -> Word8
c2w Char
'K'
toWord AminoAcidS
L = Char -> Word8
c2w Char
'L'
toWord AminoAcidS
M = Char -> Word8
c2w Char
'M'
toWord AminoAcidS
N = Char -> Word8
c2w Char
'N'
toWord AminoAcidS
P = Char -> Word8
c2w Char
'P'
toWord AminoAcidS
Q = Char -> Word8
c2w Char
'Q'
toWord AminoAcidS
R = Char -> Word8
c2w Char
'R'
toWord AminoAcidS
S = Char -> Word8
c2w Char
'S'
toWord AminoAcidS
T = Char -> Word8
c2w Char
'T'
toWord AminoAcidS
V = Char -> Word8
c2w Char
'V'
toWord AminoAcidS
W = Char -> Word8
c2w Char
'W'
toWord AminoAcidS
Y = Char -> Word8
c2w Char
'Y'
toWord AminoAcidS
Stop = Char -> Word8
c2w Char
'*'
toWord AminoAcidS
Gap = Char -> Word8
c2w Char
'-'

fromWord :: Word8 -> AminoAcidS
fromWord :: Word8 -> AminoAcidS
fromWord Word8
w = case Word8 -> Char
w2c Word8
w of
  Char
'A' -> AminoAcidS
A
  Char
'C' -> AminoAcidS
C
  Char
'D' -> AminoAcidS
D
  Char
'E' -> AminoAcidS
E
  Char
'F' -> AminoAcidS
F
  Char
'G' -> AminoAcidS
G
  Char
'H' -> AminoAcidS
H
  Char
'I' -> AminoAcidS
I
  Char
'K' -> AminoAcidS
K
  Char
'L' -> AminoAcidS
L
  Char
'M' -> AminoAcidS
M
  Char
'N' -> AminoAcidS
N
  Char
'P' -> AminoAcidS
P
  Char
'Q' -> AminoAcidS
Q
  Char
'R' -> AminoAcidS
R
  Char
'S' -> AminoAcidS
S
  Char
'T' -> AminoAcidS
T
  Char
'V' -> AminoAcidS
V
  Char
'W' -> AminoAcidS
W
  Char
'Y' -> AminoAcidS
Y
  Char
'*' -> AminoAcidS
Stop
  Char
'-' -> AminoAcidS
Gap
  Char
'.' -> AminoAcidS
Gap
  Char
_ -> String -> AminoAcidS
forall a. HasCallStack => String -> a
error String
"fromWord: Cannot convert to AminoAcidS."

derivingUnbox
  "AminoAcidS"
  [t|AminoAcidS -> Word8|]
  [|toWord|]
  [|fromWord|]

instance C.Character AminoAcidS where
  toWord :: AminoAcidS -> Word8
toWord = AminoAcidS -> Word8
toWord
  fromWord :: Word8 -> AminoAcidS
fromWord = Word8 -> AminoAcidS
fromWord

instance C.CharacterX AminoAcidS where
  gap :: AminoAcidS
gap = AminoAcidS
Gap