summaryrefslogtreecommitdiff
path: root/src/Uniprot.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Uniprot.hs')
-rw-r--r--src/Uniprot.hs26
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