Update mcp/gene_hub.py
Browse files- mcp/gene_hub.py +15 -11
mcp/gene_hub.py
CHANGED
@@ -1,18 +1,22 @@
|
|
1 |
-
"""
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
async def resolve_gene(symbol: str) -> dict:
|
7 |
-
"""
|
8 |
-
Return the first non-empty gene record.
|
9 |
-
The order is chosen for speed & richness.
|
10 |
-
"""
|
11 |
for fn in (fetch_gene_info, fetch_ensembl, fetch_ot):
|
12 |
try:
|
13 |
data = await fn(symbol)
|
14 |
-
if data:
|
15 |
return data
|
16 |
-
except Exception:
|
17 |
-
pass
|
18 |
return {}
|
|
|
1 |
+
"""
|
2 |
+
gene_hub β resolve_gene() tries three sources in order of speed & richness.
|
3 |
+
|
4 |
+
1. MyGene.info (v3) β 500 QPS key tier :contentReference[oaicite:3]{index=3}
|
5 |
+
2. Ensembl REST β key-less, species-agnostic :contentReference[oaicite:4]{index=4}
|
6 |
+
3. Open Targets GQL β tractability & constraint :contentReference[oaicite:5]{index=5}
|
7 |
+
"""
|
8 |
+
|
9 |
+
from mcp.mygene import fetch_gene_info
|
10 |
+
from mcp.ensembl import fetch_ensembl
|
11 |
+
from mcp.opentargets import fetch_ot
|
12 |
|
13 |
async def resolve_gene(symbol: str) -> dict:
|
14 |
+
"""Return first non-empty gene record; never raises."""
|
|
|
|
|
|
|
15 |
for fn in (fetch_gene_info, fetch_ensembl, fetch_ot):
|
16 |
try:
|
17 |
data = await fn(symbol)
|
18 |
+
if data:
|
19 |
return data
|
20 |
+
except Exception: # network hiccup / 429 etc.
|
21 |
+
pass
|
22 |
return {}
|