Spaces:
Sleeping
Sleeping
Update genesis/api_clients/chembl_api.py
Browse files
genesis/api_clients/chembl_api.py
CHANGED
@@ -1,32 +1,26 @@
|
|
1 |
# genesis/api_clients/chembl_api.py
|
2 |
import requests
|
3 |
|
4 |
-
|
5 |
|
6 |
-
def
|
7 |
-
"""
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
response = requests.get(url)
|
24 |
-
response.raise_for_status()
|
25 |
-
return response.json()
|
26 |
-
|
27 |
-
def get_targets_for_molecule(chembl_id: str):
|
28 |
-
"""Get protein targets related to a molecule."""
|
29 |
-
url = f"{BASE_URL}/target.json?molecule_chembl_id={chembl_id}"
|
30 |
-
response = requests.get(url)
|
31 |
-
response.raise_for_status()
|
32 |
-
return response.json()
|
|
|
1 |
# genesis/api_clients/chembl_api.py
|
2 |
import requests
|
3 |
|
4 |
+
CHEMBL_BASE = "https://www.ebi.ac.uk/chembl/api/data"
|
5 |
|
6 |
+
def search_chembl(molecule_name: str, max_results: int = 10):
|
7 |
+
"""
|
8 |
+
Search ChEMBL database for a molecule by name or identifier.
|
9 |
+
Returns a list of dicts with molecule name, ChEMBL ID, and other details.
|
10 |
+
"""
|
11 |
+
url = f"{CHEMBL_BASE}/molecule"
|
12 |
+
params = {"molecule_synonyms__icontains": molecule_name, "limit": max_results, "format": "json"}
|
13 |
+
res = requests.get(url, params=params)
|
14 |
+
res.raise_for_status()
|
15 |
+
data = res.json()
|
16 |
|
17 |
+
results = []
|
18 |
+
for mol in data.get("molecules", []):
|
19 |
+
results.append({
|
20 |
+
"name": mol.get("pref_name"),
|
21 |
+
"chembl_id": mol.get("molecule_chembl_id"),
|
22 |
+
"max_phase": mol.get("max_phase"),
|
23 |
+
"molecule_type": mol.get("molecule_type"),
|
24 |
+
"link": f"https://www.ebi.ac.uk/chembl/compound_report_card/{mol.get('molecule_chembl_id')}/"
|
25 |
+
})
|
26 |
+
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|