<jupyter_start><jupyter_text><jupyter_code># Inspired by https://github.com/dataprofessor/code/blob/master/python/CDD_ML_Part_1_Bioactivity_Data_Concised.ipynb
! pip install chembl_webresource_client
# Import necessary libraries
import pandas as pd
from chembl_webresource_client.new_client import new_client<jupyter_output>Collecting chembl_webresource_client
[?25l  Downloading https://files.pythonhosted.org/packages/c3/75/ccfc66e213d685c623d74609d116020452f36826d206924f2a948419ddf6/chembl_webresource_client-0.10.3-py3-none-any.whl (55kB)

[K     |██████                          | 10kB 14.4MB/s eta 0:00:01
[K     |███████████▉                    | 20kB 21.0MB/s eta 0:00:01
[K     |█████████████████▊              | 30kB 25.3MB/s eta 0:00:01
[K     |███████████████████████▋        | 40kB 17.6MB/s eta 0:00:01
[K     |█████████████████████████████▌  | 51kB 19.9MB/s eta 0:00:01
[K     |████████████████████████████████| 61kB 6.6MB/s 
[?25hCollecting requests-cache>=0.4.7
  Downloading https://files.pythonhosted.org/packages/3c/b7/ece6951b3ca140c3ff403d4e2aaecd796ccdf3b004c3bfd5a9787d384f1f/requests_cache-0.6.3-py2.py3-none-any.whl
Requirement already satisfied: easydict in /usr/local/lib/python3.7/dist-packages (from chembl_webresource_client) (1.9)
Requirement already satisfied: requests>=2.18.4 in /u[...]<jupyter_text>Chembl database majorly includes small molecule data<jupyter_code># Target search for SARS coronavirus
target = new_client.target
target_query = target.search('SARS coronavirus')
targets = pd.DataFrame.from_dict(target_query)
targets
selected_target = targets.target_chembl_id[1]
selected_target<jupyter_output><empty_output><jupyter_text>Target types are majorly divided as molecular and non-molecular.> Molecular target types inludes nucleic acids and protein.Protein can be further divided as single protein, protein complex and protein family.> Non- molecular target type includes cell-line, tissue, subcellular fraction and organism.Here, we are choosing SARS Coronavirus 3C-like proteinase, as it is very important in the processing of coronaviral polyproteins and could be an effective drug target.<jupyter_code>activity = new_client.activity
resource = activity.filter(target_chembl_id=selected_target).filter(standard_type="IC50")<jupyter_output><empty_output><jupyter_text>We will retrieve the bioactivity data that are reported as IC50 value. IC50 represents the concentration at which a substance exerts half of its maximal inhibitory effect.<jupyter_code>dataframe = pd.DataFrame.from_dict(resource)
dataframe_filtered = dataframe[dataframe.standard_value.notna()]
dataframe_filtered
bioactivity_class = []
for i in dataframe_filtered.standard_value:
  if float(i) >= 10000:
    bioactivity_class.append("inactive")
  elif float(i) <= 1000:
    bioactivity_class.append("active")
  else:
   bioactivity_class.append("intermediate")
selection = ['molecule_chembl_id','canonical_smiles','standard_value']
selected_columns = dataframe_filtered[selection]
selected_columns
bioactivity_class = pd.Series(bioactivity_class, name='bioactivity_class')
bioactivity_data = pd.concat([selected_columns, bioactivity_class], axis=1)
bioactivity_data
! wget https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.2-Linux-x86_64.sh
! chmod +x Miniconda3-py37_4.8.2-Linux-x86_64.sh
! bash ./Miniconda3-py37_4.8.2-Linux-x86_64.sh -b -f -p /usr/local
! conda install -c rdkit rdkit -y
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages/')
import numpy as np
from rdkit import Chem
from rdkit.Chem import Descriptors, Lipinski
# Inspired by: https://codeocean.com/explore/capsules?query=tag:data-curation

def lipinski(smiles, verbose=False):

    moldata= []
    for elem in smiles:
        mol=Chem.MolFromSmiles(elem) 
        moldata.append(mol)
       
    baseData= np.arange(1,1)

    for i,mol in enumerate(moldata):        
        desc_MolWt = Descriptors.MolWt(mol)
        desc_MolLogP = Descriptors.MolLogP(mol)
        desc_NumHDonors = Lipinski.NumHDonors(mol)
        desc_NumHAcceptors = Lipinski.NumHAcceptors(mol)
           
        row = np.array([desc_MolWt,
                        desc_MolLogP,
                        desc_NumHDonors,
                        desc_NumHAcceptors])       
        if(i==0):
            baseData=row
        else:
            baseData=np.vstack([baseData, row])
    
    columnNames=["MW","LogP","NumHDonors","NumHAcceptors"]   
    descriptors = pd.DataFrame(data=baseData,columns=columnNames)
    
    return descriptors
df_lipinski = lipinski(dataframe.canonical_smiles)
df_lipinski
combined = pd.concat([bioactivity_data,df_lipinski], axis=1)
combined<jupyter_output><empty_output><jupyter_text>Here, we will be removing the intermediate class from our data set.<jupyter_code>intermediate_removed = bioactivity_data[bioactivity_data.bioactivity_class != 'intermediate']
intermediate_removed 
import seaborn as sns
sns.set(style='ticks')
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Frequency plot of the two bioactivity classes<jupyter_code>plt.figure(figsize=(5.5, 5.5))

sns.countplot(x='bioactivity_class', data=intermediate_removed, edgecolor='black')

plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('Frequency', fontsize=14, fontweight='bold')

plt.savefig('plot_bioactivity_class.pdf')
active_compound = bioactivity_data[bioactivity_data.bioactivity_class == 'active']
active_compound<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12110726643598616, 'fraction_numerical': 0.04079402658896376, 'mean_word_length': 4.899033297529538, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '249850', 'license': 'MIT', 'n_tokens_mistral': 2118, 'n_tokens_neox': 1874, 'n_words': 344, 'path': 'drug_discovery_coronavirus.ipynb', 'repo_name': 'anshi-kaaaa/Drug-Discovery', 'size': '5491'}