module Biobase.Types.Accession where
import Control.DeepSeq
import Data.Aeson
import Data.Binary
import Data.Char (isLetter)
import Data.Hashable (Hashable)
import Data.Ix (Ix)
import Data.Serialize
import Data.Serialize.Text
import Data.String
import Data.String.Conversions (ConvertibleStrings(..), cs)
import Data.String.Conversions.Monomorphic (toST, fromST)
import Data.Text.Binary
import Data.Text (Text, span, length)
import GHC.Generics (Generic)
import Prelude hiding (length,span)
newtype Accession t = Accession { _getAccession :: Text }
deriving (Eq,Ord,Read,Show,Generic)
accession' :: ConvertibleStrings s Text => t -> s -> Accession t
accession' t = Accession . toST
accession :: ConvertibleStrings s Text => s -> Accession t
accession = Accession . toST
{-# Inline accession #-}
retagAccession :: Accession f -> Accession t
retagAccession = Accession . _getAccession
{-# Inline retagAccession #-}
instance IsString (Accession t) where
fromString = accession
{-# Inline fromString #-}
instance Binary (Accession t)
instance FromJSON (Accession t)
instance Hashable (Accession t)
instance Serialize (Accession t)
instance ToJSON (Accession t)
instance NFData (Accession t)
data Nucleotide = Nucleotide
data Protein = Protein
data Clan = Clan
data Pfam = Pfam
data Rfam = Rfam
data Species = Species
guessAccessionType :: Accession t -> Maybe Text
guessAccessionType (Accession a) = case (length l, length d) of
(1,5) -> Just "Nucleotide"
(2,6) -> Just "Nucleotide"
(3,5) -> Just "Protein"
(3,k) | 8<= k && k<= 10 -> Just "WGS"
(5,7) -> Just "MGA"
_ -> Nothing
where (l,d) = span isLetter a