<jupyter_start><jupyter_text>**ChEMBL Database**The [*ChEMBL Database*](https://www.ebi.ac.uk/chembl/) is a database that contains curated bioactivity data of more than 2 million compounds. It is compiled from more than 76,000 documents, 1.2 million assays and the data spans 13,000 targets and 1,800 cells and 33,000 indications.[Data as of June 17, 2021; ChEMBL version 26].  **Installing libraries** Install the ChEMBL web service package so that we can retrieve bioactivity data from the ChEMBL Database.<jupyter_code>! pip install chembl_webresource_client<jupyter_output>Collecting chembl_webresource_client
[?25l  Downloading https://files.pythonhosted.org/packages/e5/c9/a909331598965376ba15a9e5dbe02b5a007172c0726e6cd56424f558b236/chembl-webresource-client-0.10.4.tar.gz (51kB)

[K     |██████▍                         | 10kB 14.6MB/s eta 0:00:01
[K     |████████████▊                   | 20kB 20.7MB/s eta 0:00:01
[K     |███████████████████             | 30kB 24.7MB/s eta 0:00:01
[K     |█████████████████████████▍      | 40kB 27.0MB/s eta 0:00:01
[K     |███████████████████████████████▊| 51kB 29.3MB/s eta 0:00:01
[K     |████████████████████████████████| 61kB 6.9MB/s 
[?25hRequirement already satisfied: urllib3 in /usr/local/lib/python3.7/dist-packages (from chembl_webresource_client) (1.24.3)
Requirement already satisfied: requests>=2.18.4 in /usr/local/lib/python3.7/dist-packages (from chembl_webresource_client) (2.23.0)
Collecting requests-cache>=0.6.0
  Downloading https://files.pythonhosted.org/packages/1d/a1/3062a791c433212c98a7dd2e510913bc[...]<jupyter_text>**Importing libraries**<jupyter_code># Import necessary libraries
import pandas as pd
from chembl_webresource_client.new_client import new_client<jupyter_output><empty_output><jupyter_text>**Search for Target protein**  **Target search for Acetylcholinesterase**<jupyter_code># Target search for coronavirus
target = new_client.target
target_query = target.search('acetylcholinesterase')
targets = pd.DataFrame.from_dict(target_query)
targets<jupyter_output><empty_output><jupyter_text>**Select and retrieve bioactivity data for *Human Acetylcholinesterase* (first entry)** We will assign the fifth entry (which corresponds to the target protein, *Human Acetylcholinesterase*) to the ***selected_target*** variable<jupyter_code>selected_target = targets.target_chembl_id[0]
selected_target<jupyter_output><empty_output><jupyter_text>Here, we will retrieve only bioactivity data for *Human Acetylcholinesterase* (CHEMBL220) that are reported as pChEMBL values.<jupyter_code>activity = new_client.activity
res = activity.filter(target_chembl_id=selected_target).filter(standard_type="IC50")
df = pd.DataFrame.from_dict(res)
df<jupyter_output><empty_output><jupyter_text>Finally we will save the resulting bioactivity data to a CSV file **bioactivity_data.csv**.<jupyter_code>df.to_csv('acetylcholinesterase_01_bioactivity_data_raw.csv', index=False)<jupyter_output><empty_output><jupyter_text>**Handling missing data**If any compounds has missing value for the **standard_value** and **canonical_smiles** column then drop it.<jupyter_code>df2 = df[df.standard_value.notna()]
df2 = df2[df.canonical_smiles.notna()]
df2
len(df2.canonical_smiles.unique())
df2_nr = df2.drop_duplicates(['canonical_smiles'])
df2_nr<jupyter_output><empty_output><jupyter_text>**Data pre-processing of the bioactivity data**  **Combine the 3 columns (molecule_chembl_id,canonical_smiles,standard_value) and bioactivity_class into a DataFrame**<jupyter_code>selection = ['molecule_chembl_id','canonical_smiles','standard_value']
df3 = df2_nr[selection]
df3<jupyter_output><empty_output><jupyter_text>Saves dataframe to CSV file<jupyter_code>df3.to_csv('acetylcholinesterase_02_bioactivity_data_preprocessed.csv', index=False)<jupyter_output><empty_output><jupyter_text>**Labeling compounds as either being active, inactive or intermediate**The bioactivity data is in the IC50 unit. Compounds having values of less than 1000 nM will be considered to be **active** while those greater than 10,000 nM will be considered to be **inactive**. As for those values in between 1,000 and 10,000 nM will be referred to as **intermediate**.<jupyter_code>df4 = pd.read_csv('acetylcholinesterase_02_bioactivity_data_preprocessed.csv')
bioactivity_threshold = []
for i in df4.standard_value:
  if float(i) >= 10000:
    bioactivity_threshold.append("inactive")
  elif float(i) <= 1000:
    bioactivity_threshold.append("active")
  else:
    bioactivity_threshold.append("intermediate")
bioactivity_class = pd.Series(bioactivity_threshold, name='class')
df5 = pd.concat([df4, bioactivity_class], axis=1)
df5<jupyter_output><empty_output><jupyter_text>Saves dataframe to CSV file<jupyter_code>df5.to_csv('acetylcholinesterase_03_bioactivity_data_curated.csv', index=False)
! zip acetylcholinesterase.zip *.csv
! ls -l
# Import necessary libraries
import pandas as pd
from chembl_webresource_client.new_client import new_client<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1267718107406668, 'fraction_numerical': 0.04951088041525255, 'mean_word_length': 6.965023847376789, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 47, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '36582', 'license': 'MIT', 'n_tokens_mistral': 1981, 'n_tokens_neox': 1696, 'n_words': 370, 'path': 'CDD_Data.ipynb', 'repo_name': 'krishnaaxo/Drug_Discovery_AI', 'size': '5009'}