blob: 9458cfb38cd5698a6828507c35eb926dbf04eaba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
|