Update mcp/opentargets.py
Browse files- mcp/opentargets.py +18 -18
mcp/opentargets.py
CHANGED
|
@@ -1,22 +1,22 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
from functools import lru_cache
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
}
|
| 14 |
-
}""")
|
| 15 |
|
| 16 |
-
|
| 17 |
-
async def fetch_ot(sym: str, n: int = 30):
|
| 18 |
-
payload = {"query": _QUERY, "variables": {"g": sym, "n": n}}
|
| 19 |
-
async with httpx.AsyncClient(timeout=10, headers=_HDR) as c:
|
| 20 |
-
r = await c.post(_URL, json=payload)
|
| 21 |
-
r.raise_for_status()
|
| 22 |
-
return r.json()["data"]["associations"]["rows"]
|
|
|
|
| 1 |
+
# mcp/opentargets.py
|
| 2 |
+
import textwrap
|
| 3 |
from functools import lru_cache
|
| 4 |
+
from mcp.clients import BaseClient
|
| 5 |
|
| 6 |
+
class OTClient(BaseClient):
|
| 7 |
+
QUERY = textwrap.dedent("""
|
| 8 |
+
query ($g: String!, $n: Int!){
|
| 9 |
+
associations(geneSymbol: $g, size: $n) {
|
| 10 |
+
rows { score datatypeId datasourceId disease { id name } target { id symbol } }
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
+
""")
|
| 14 |
+
def __init__(self):
|
| 15 |
+
super().__init__("https://api.platform.opentargets.org/api/v4/graphql", api_key_env="OT_KEY")
|
| 16 |
|
| 17 |
+
@lru_cache(512)
|
| 18 |
+
async def fetch(self, symbol: str, n: int = 30):
|
| 19 |
+
payload = {"query": self.QUERY, "variables": {"g": symbol, "n": n}}
|
| 20 |
+
return (await self.request("POST", "", json=payload))["data"]["associations"]["rows"]
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
ot = OTClient()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|