Update mcp/mygene.py
Browse files- mcp/mygene.py +14 -13
mcp/mygene.py
CHANGED
|
@@ -1,21 +1,22 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
No API‑key required; 500 QPS community quota.
|
| 4 |
-
"""
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from functools import lru_cache
|
| 8 |
|
| 9 |
_BASE = "https://mygene.info/v3"
|
| 10 |
|
| 11 |
-
@lru_cache(maxsize=128)
|
| 12 |
-
async def fetch_gene_info(query: str) -> dict: # noqa: C901 – simple IO fn
|
| 13 |
-
"""Return first hit dict or {} if nothing found.
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
"""
|
| 19 |
params = {
|
| 20 |
"q": query,
|
| 21 |
"fields": "symbol,name,summary,alias,entrezgene,clinvar,location,go",
|
|
@@ -25,4 +26,4 @@ async def fetch_gene_info(query: str) -> dict: # noqa: C901 – simple IO fn
|
|
| 25 |
resp = await client.get(f"{_BASE}/query", params=params)
|
| 26 |
resp.raise_for_status()
|
| 27 |
hits = resp.json().get("hits", [])
|
| 28 |
-
return hits[0] if hits else {}
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Async wrapper for MyGene.info API (https://mygene.info)
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
Provides a single helper:
|
| 5 |
+
• `fetch_gene_info(query)` → returns the first matching hit dict or `{}`.
|
| 6 |
+
|
| 7 |
+
No API‑key needed; community tier allows 500 QPS.
|
| 8 |
+
"""
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import httpx
|
| 12 |
from functools import lru_cache
|
| 13 |
|
| 14 |
_BASE = "https://mygene.info/v3"
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
@lru_cache(maxsize=128)
|
| 18 |
+
async def fetch_gene_info(query: str) -> dict: # noqa: D401
|
| 19 |
+
"""Return first hit for *query* or an empty dict."""
|
|
|
|
| 20 |
params = {
|
| 21 |
"q": query,
|
| 22 |
"fields": "symbol,name,summary,alias,entrezgene,clinvar,location,go",
|
|
|
|
| 26 |
resp = await client.get(f"{_BASE}/query", params=params)
|
| 27 |
resp.raise_for_status()
|
| 28 |
hits = resp.json().get("hits", [])
|
| 29 |
+
return hits[0] if hits else {}
|