mgbam commited on
Commit
a8a0045
·
verified ·
1 Parent(s): b94ef99

Update genesis/api_clients/chembl_api.py

Browse files
Files changed (1) hide show
  1. genesis/api_clients/chembl_api.py +21 -27
genesis/api_clients/chembl_api.py CHANGED
@@ -1,32 +1,26 @@
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()
 
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