diff options
author | Justin Bedo <cu@cua0.org> | 2022-09-29 08:53:40 +1000 |
---|---|---|
committer | Justin Bedo <cu@cua0.org> | 2022-09-29 08:55:35 +1000 |
commit | 8ecdab68587c07cf88ebc0b8a8f2bd0e1a703e37 (patch) | |
tree | 258b2b64362b5891e268f2761e6a798f2072759c /src/Uniprot.hs |
init
Diffstat (limited to 'src/Uniprot.hs')
-rw-r--r-- | src/Uniprot.hs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/Uniprot.hs b/src/Uniprot.hs new file mode 100644 index 0000000..9458cfb --- /dev/null +++ b/src/Uniprot.hs @@ -0,0 +1,26 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Uniprot where + +import Codec.Compression.GZip +import Control.Lens +import Data.Aeson.Lens +import qualified Data.ByteString.Char8 as BSS +import qualified Data.ByteString.Lazy.Char8 as BS +import Data.Text (Text) +import qualified Data.Text as T +import Network.Wreq + +type UniprotID = Text + +type GeneName = Text + +geneName :: UniprotID -> IO GeneName +geneName id = do + rep <- getWith (defaults & header "Accept" .~ ["application/json"]) $ "https://rest.uniprot.org/uniprotkb/" <> T.unpack id + let encoding = rep ^. responseHeader "content-encoding" + case encoding of + "gzip" -> + let json = decompress $ rep ^. responseBody + in pure $ json ^. key "genes" . _Array . traverse . key "geneName" . key "value" . _String + _ -> error $ "unkown content encoding " <> BSS.unpack encoding |