File size: 2,516 Bytes
792fe00
6fa7402
792fe00
 
6fa7402
792fe00
6fa7402
a8a0045
6fa7402
a8a0045
6fa7402
a8a0045
 
6fa7402
 
792fe00
6fa7402
 
 
 
5404a41
6fa7402
5404a41
6fa7402
 
5404a41
6fa7402
 
5404a41
6fa7402
5404a41
6fa7402
 
5404a41
6fa7402
 
 
 
5404a41
6fa7402
5404a41
6fa7402
 
 
5404a41
 
 
6fa7402
5404a41
6fa7402
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# genesis/api_clients/chembl_api.py
import os
import requests

CHEMBL_BASE_URL = "https://www.ebi.ac.uk/chembl/api/data"

def _chembl_get(endpoint: str, params: dict = None):
    """
    Generic ChEMBL GET request helper.
    """
    url = f"{CHEMBL_BASE_URL}/{endpoint}"
    res = requests.get(url, params=params)
    res.raise_for_status()
    return res.json()


# -----------------------
# Drug & Compound Search
# -----------------------
def search_drug_by_name(drug_name: str, limit: int = 5):
    """
    Search for a drug/compound by name in ChEMBL.
    """
    params = {"pref_name__icontains": drug_name, "limit": limit}
    return _chembl_get("molecule", params)


def get_drug_details(chembl_id: str):
    """
    Retrieve detailed information for a specific ChEMBL compound.
    """
    return _chembl_get(f"molecule/{chembl_id}")


# -----------------------
# Target & Mechanism
# -----------------------
def search_target_by_name(target_name: str, limit: int = 5):
    """
    Search for a biological target (e.g., protein) by name.
    """
    params = {"pref_name__icontains": target_name, "limit": limit}
    return _chembl_get("target", params)


def get_target_details(chembl_target_id: str):
    """
    Retrieve target details from ChEMBL.
    """
    return _chembl_get(f"target/{chembl_target_id}")


def get_mechanism_of_action(chembl_id: str):
    """
    Retrieve the mechanism of action for a given compound.
    """
    params = {"molecule_chembl_id": chembl_id}
    return _chembl_get("mechanism", params)


# -----------------------
# Bioactivity Data
# -----------------------
def get_bioactivity_for_target(chembl_target_id: str, limit: int = 10):
    """
    Get bioactivity data (IC50, Ki, etc.) for a target.
    """
    params = {"target_chembl_id": chembl_target_id, "limit": limit}
    return _chembl_get("activity", params)


def get_bioactivity_for_drug(chembl_id: str, limit: int = 10):
    """
    Get bioactivity data for a compound.
    """
    params = {"molecule_chembl_id": chembl_id, "limit": limit}
    return _chembl_get("activity", params)


# -----------------------
# Clinical Candidates
# -----------------------
def get_clinical_candidates(drug_name: str):
    """
    Find drugs in clinical trials from ChEMBL.
    """
    compounds = search_drug_by_name(drug_name, limit=1)
    if compounds["page_meta"]["total_count"] > 0:
        chembl_id = compounds["molecules"][0]["molecule_chembl_id"]
        return get_mechanism_of_action(chembl_id)
    return None