mgbam commited on
Commit
e78237f
·
verified ·
1 Parent(s): 563f401

Create opentargets.py

Browse files
Files changed (1) hide show
  1. mcp/opentargets.py +15 -0
mcp/opentargets.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### `opentargets.py` – tractability & constraint
2
+ ```python
3
+ import os, httpx, textwrap, asyncio
4
+ from functools import lru_cache
5
+ _URL="https://api.platform.opentargets.org/api/v4/graphql"
6
+ _HDR={"Content-Type":"application/json","Accept":"application/json"}
7
+ if os.getenv("OT_KEY"): HDR["Authorization"]="Bearer "+os.getenv("OT_KEY")
8
+ _Q=textwrap.dedent("""query Q($g:String!,$n:Int){associations(geneSymbol:$g,size:$n){rows{score datatypeId disease{id name} target{id symbol}}}}""")
9
+ @lru_cache(maxsize=512)
10
+ async def fetch_ot(sym:str, n:int=30):
11
+ p={"query":_Q,"variables":{"g":sym,"n":n}}
12
+ async with httpx.AsyncClient(timeout=10,headers=_HDR) as c:
13
+ r=await c.post(_URL,json=p);
14
+ return r.json()["data"]["associations"]["rows"]
15
+ ``` :contentReference[oaicite:9]{index=9