MCP_Res / mcp /opentargets.py
mgbam's picture
Update mcp/opentargets.py
6aa799c verified
raw
history blame
781 Bytes
### `opentargets.py` – tractability & constraint
import os, httpx, textwrap, asyncio
from functools import lru_cache
_URL="https://api.platform.opentargets.org/api/v4/graphql"
_HDR={"Content-Type":"application/json","Accept":"application/json"}
if os.getenv("OT_KEY"): HDR["Authorization"]="Bearer "+os.getenv("OT_KEY")
_Q=textwrap.dedent("""query Q($g:String!,$n:Int){associations(geneSymbol:$g,size:$n){rows{score datatypeId disease{id name} target{id symbol}}}}""")
@lru_cache(maxsize=512)
async def fetch_ot(sym:str, n:int=30):
p={"query":_Q,"variables":{"g":sym,"n":n}}
async with httpx.AsyncClient(timeout=10,headers=_HDR) as c:
r=await c.post(_URL,json=p);
return r.json()["data"]["associations"]["rows"]
``` :contentReference[oaicite:9]{index=9