Spaces:
Sleeping
Sleeping
Update genesis/api_clients/chembl_api.py
Browse files
genesis/api_clients/chembl_api.py
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# genesis/api_clients/chembl_api.py
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
BASE_URL = "https://www.ebi.ac.uk/chembl/api/data"
|
| 5 |
+
|
| 6 |
+
def search_molecule(query: str):
|
| 7 |
+
"""Search ChEMBL molecules by name or ChEMBL ID."""
|
| 8 |
+
url = f"{BASE_URL}/molecule/search.json?q={query}"
|
| 9 |
+
response = requests.get(url)
|
| 10 |
+
response.raise_for_status()
|
| 11 |
+
return response.json()
|
| 12 |
+
|
| 13 |
+
def get_molecule_details(chembl_id: str):
|
| 14 |
+
"""Get details of a molecule by ChEMBL ID."""
|
| 15 |
+
url = f"{BASE_URL}/molecule/{chembl_id}.json"
|
| 16 |
+
response = requests.get(url)
|
| 17 |
+
response.raise_for_status()
|
| 18 |
+
return response.json()
|
| 19 |
+
|
| 20 |
+
def get_assays_for_molecule(chembl_id: str):
|
| 21 |
+
"""Get bioassays related to a molecule."""
|
| 22 |
+
url = f"{BASE_URL}/assay.json?molecule_chembl_id={chembl_id}"
|
| 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()
|