This project was done in the Bioinformatics lecture by Chanin Nantasenamat. You can find my notes and rearranged codes in this Project documents for better understanding while taking this course.

Part 1: Data Collection

  1. In this part, We’re going to learn the target protein search that we focused on if we want to have a machine learning model for discovering breast cancer drugs then we’re going to select aromatase as my protein search.
    If we’re looking into Alzheimer, we might want to search for acetylcholine estrase which we’ll be using in this particular series.
  2. We’re going to collect the data set from the ChEMBL database using the Python library (chembl_webresource_client).
  3. Then, we get the bioactivity data and then we’re going to pre-process that
    • dropping missing data
    • dropping duplicates
    • labelling compounds according to bioactivity threshold
      in order to obtain a curated bioactivity data.

! pip install chembl_webresource_client
# Import necessary libraries
import pandas as pd
from chembl_webresource_client.new_client import new_client

Search for Target Protein

Target search for coronavirus

# Target search for coronavirus
target = new_client.target
target_query = target.search('coronavirus')
targets = pd.DataFrame.from_dict(target_query)
targets


cross_references
organismpref_namescorespecies_group_flagtarget_chembl_idtarget_componentstarget_typetax_id
0[]CoronavirusCoronavirus17.0FalseCHEMBL613732[]ORGANISM11119
1[]SARS coronavirusSARS coronavirus15.0FalseCHEMBL612575[]ORGANISM227859
2[]Feline coronavirusFeline coronavirus15.0FalseCHEMBL612744[]ORGANISM12663
3[]Human coronavirus 229EHuman coronavirus 229E13.0FalseCHEMBL613837[]ORGANISM11137
4[{‘xref_id’: ‘P0C6U8’, ‘xref_name’: None, ‘xre…SARS coronavirusSARS coronavirus 3C-like proteinase10.0FalseCHEMBL3927[{‘accession’: ‘P0C6U8’, ‘component_descriptio…SINGLE PROTEIN227859
5[]Middle East respiratory syndrome-related coron…Middle East respiratory syndrome-related coron…9.0FalseCHEMBL4296578[]ORGANISM1335626
6[{‘xref_id’: ‘P0C6X7’, ‘xref_name’: None, ‘xre…SARS coronavirusReplicase polyprotein 1ab4.0FalseCHEMBL5118[{‘accession’: ‘P0C6X7’, ‘component_descriptio…SINGLE PROTEIN227859
7[]Severe acute respiratory syndrome coronavirus 2Replicase polyprotein 1ab4.0FalseCHEMBL4523582[{‘accession’: ‘P0DTD1’, ‘component_descriptio…SINGLE PROTEIN2697049
Result of target research for Coronavirus

Select and retrieve bioactivity data for SARS coronavirus 3C-like proteinase

selected_target = target.target_chembl_id[4]
selected_target
'CHEMBL3927'

We will retrieve only bioactivity data for coronavirus 3C -like proteinase (CHEMBL3927) that are (CHEMBL3927) that are reported as IC$_{50}$ values in nM (nanomolar) unit.

activity = new_client.activity
res = activity.filter(target_chembl_id=selected_target).filter(standard_type="IC50")
df = pd.Dataframe.from_dixt(res)
df.head(3)
activity_commentactivity_idactivity_propertiesassay_chembl_idassay_descriptionassay_typeassay_variant_accessionassay_variant_mutationbao_endpointbao_format…target_organismtarget_pref_nametarget_tax_idtext_valuetoidtypeunitsuo_unitsupper_valuevalue
0None1480935[]CHEMBL829584In vitro inhibitory concentration against SARS…BNoneNoneBAO_0000190BAO_0000357…SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None7.2
1None1480936[]CHEMBL829584In vitro inhibitory concentration against SARS…BNoneNoneBAO_0000190BAO_0000357…SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None9.4
2None1481061[]CHEMBL830868In vitro inhibitory concentration against SARS…BNoneNoneBAO_0000190BAO_0000357…SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None13.5
Dataset filtered by IC50 standard type

Checking if the dataset filtered by IC50 standard type is unique.

Standard value is the potency of the drug and so the lower potency number of the drug becomes good and likewise the higher potency number of the drug becomes bad.

The lower concentration that is required the better because if you have higher number it means that you require more amount of the drug in order to produce the same inhibition at 50.

df.standard_type.unique()
array(['IC50'], dtype=object)

We will save the resulting data to a CSV file bioactivity_data.csv.

df.to_csv("bioactivity_data.csv", index= False)

Copying files to Google Drive

!pip install drive
from google.colab import drive
drive.mount("/content/drive/", force_remount= True)
! cp bioactivity_data.csv "/content/gdrive/My Drive/Colab Notebooks/data"
! ls -l "/content/gdrive/My Drive/Colab Notebooks/data"
! ls
bioactivity_data.csv gdrive sample_data
! head bioactivity_data.csv
Part of the bioactivity_data.csv dataset

Handling Missing Data

If any compounds has missing value for the standard_value column then drop it.

df2 = df[df.standard_value.notna()]
df2
activity_commentactivity_idactivity_propertiesassay_chembl_idassay_descriptionassay_typeassay_variant_accessionassay_variant_mutationbao_endpointbao_formatbao_labelcanonical_smilesdata_validity_commentdata_validity_descriptiondocument_chembl_iddocument_journaldocument_yearligand_efficiencymolecule_chembl_idmolecule_pref_nameparent_molecule_chembl_idpchembl_valuepotential_duplicatequdt_unitsrecord_idrelationsrc_idstandard_flagstandard_relationstandard_text_valuestandard_typestandard_unitsstandard_upper_valuestandard_valuetarget_chembl_idtarget_organismtarget_pref_nametarget_tax_idtext_valuetoidtypeunitsuo_unitsupper_valuevalue
0None1480935[]CHEMBL829584In vitro inhibitory concentration against SARS…BNoneNoneBAO_0000190BAO_0000357single protein formatCc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21NoneNoneCHEMBL1139624Bioorg. Med. Chem. Lett.2005{‘bei’: ‘18.28’, ‘le’: ‘0.33’, ‘lle’: ‘3.25’, …CHEMBL187579NoneCHEMBL1875795.14Falsehttp://www.openphacts.org/units/Nanomolar384103=1True=NoneIC50nMNone7200.0CHEMBL3927SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None7.2
1None1480936[]CHEMBL829584In vitro inhibitory concentration against SARS…BNoneNoneBAO_0000190BAO_0000357single protein formatO=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21NoneNoneCHEMBL1139624Bioorg. Med. Chem. Lett.2005{‘bei’: ‘12.10’, ‘le’: ‘0.33’, ‘lle’: ‘1.22’, …CHEMBL188487NoneCHEMBL1884875.03Falsehttp://www.openphacts.org/units/Nanomolar383984=1True=NoneIC50nMNone9400.0CHEMBL3927SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None9.4
2None1481061[]CHEMBL830868In vitro inhibitory concentration against SARS…BNoneNoneBAO_0000190BAO_0000357single protein formatO=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21NoneNoneCHEMBL1139624Bioorg. Med. Chem. Lett.2005{‘bei’: ‘11.56’, ‘le’: ‘0.29’, ‘lle’: ‘2.21’, …CHEMBL185698NoneCHEMBL1856984.87Falsehttp://www.openphacts.org/units/Nanomolar384106=1True=NoneIC50nMNone13500.0CHEMBL3927SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None13.5
3None1481065[]CHEMBL829584In vitro inhibitory concentration against SARS…BNoneNoneBAO_0000190BAO_0000357single protein formatO=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21NoneNoneCHEMBL1139624Bioorg. Med. Chem. Lett.2005{‘bei’: ‘16.64’, ‘le’: ‘0.32’, ‘lle’: ‘1.25’, …CHEMBL426082NoneCHEMBL4260824.88Falsehttp://www.openphacts.org/units/Nanomolar384075=1True=NoneIC50nMNone13110.0CHEMBL3927SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None13.11
4None1481066[]CHEMBL829584In vitro inhibitory concentration against SARS…BNoneNoneBAO_0000190BAO_0000357single protein formatO=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-]NoneNoneCHEMBL1139624Bioorg. Med. Chem. Lett.2005{‘bei’: ‘16.84’, ‘le’: ‘0.32’, ‘lle’: ‘2.16’, …CHEMBL187717NoneCHEMBL1877175.70Falsehttp://www.openphacts.org/units/Nanomolar384234=1True=NoneIC50nMNone2000.0CHEMBL3927SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None2.0
…………………………………………………………………………………………………………………………
128None12041507[]CHEMBL2150313Inhibition of SARS-CoV PLpro expressed in Esch…BNoneNoneBAO_0000190BAO_0000019assay formatCOC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c…NoneNoneCHEMBL2146458Bioorg. Med. Chem.2012{‘bei’: ‘14.70’, ‘le’: ‘0.27’, ‘lle’: ‘1.57’, …CHEMBL2146517METHYL TANSHINONATECHEMBL21465174.97Falsehttp://www.openphacts.org/units/Nanomolar1727226=1True=NoneIC50nMNone10600.0CHEMBL3927SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None10.6
129None12041508[]CHEMBL2150313Inhibition of SARS-CoV PLpro expressed in Esch…BNoneNoneBAO_0000190BAO_0000019assay formatC[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)CNoneNoneCHEMBL2146458Bioorg. Med. Chem.2012{‘bei’: ‘16.86’, ‘le’: ‘0.31’, ‘lle’: ‘1.56’, …CHEMBL187460CRYPTOTANSHINONECHEMBL1874605.00Falsehttp://www.openphacts.org/units/Nanomolar1727227=1True=NoneIC50nMNone10100.0CHEMBL3927SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None10.1
130None12041509[]CHEMBL2150313Inhibition of SARS-CoV PLpro expressed in Esch…BNoneNoneBAO_0000190BAO_0000019assay formatCc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12NoneNoneCHEMBL2146458Bioorg. Med. Chem.2012{‘bei’: ‘17.88’, ‘le’: ‘0.32’, ‘lle’: ‘0.84’, …CHEMBL363535TANSHINONE ICHEMBL3635354.94Falsehttp://www.openphacts.org/units/Nanomolar1727228=1True=NoneIC50nMNone11500.0CHEMBL3927SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None11.5
131None12041510[]CHEMBL2150313Inhibition of SARS-CoV PLpro expressed in Esch…BNoneNoneBAO_0000190BAO_0000019assay formatCc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1NoneNoneCHEMBL2146458Bioorg. Med. Chem.2012{‘bei’: ‘17.86’, ‘le’: ‘0.32’, ‘lle’: ‘1.68’, …CHEMBL227075DIHYDROTANSHINONE ICHEMBL2270754.97Falsehttp://www.openphacts.org/units/Nanomolar1727229=1True=NoneIC50nMNone10700.0CHEMBL3927SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None10.7
132None12041511[]CHEMBL2150313Inhibition of SARS-CoV PLpro expressed in Esch…BNoneNoneBAO_0000190BAO_0000019assay formatCC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)CNoneNoneCHEMBL2146458Bioorg. Med. Chem.2012{‘bei’: ‘14.53’, ‘le’: ‘0.27’, ‘lle’: ‘-0.01’,…CHEMBL45830MILTIRONECHEMBL458304.10Falsehttp://www.openphacts.org/units/Nanomolar1727230=1True=NoneIC50nMNone78900.0CHEMBL3927SARS coronavirusSARS coronavirus 3C-like proteinase227859NoneNoneIC50uMUO_0000065None78.9

There is no missing data for this dataset.

Data pre-processing of bioactivity data

Labeling compounds as either being active, inactive or intermediate

We’re going to do some data pre-processing of the bioactivity data so for the benefit of creating machine learning models where we could classify compounds into three categories as either being a

  • an active compound
  • an inactive compound or
  • an intermediate compound.

The active compound will be defined as drugs that have IC50 of less than 1000 nM. The inactive compound will be defined as drugs that IC50 of greater than 10,000 nM. Drugs having value in between 1000 nM and 10,000 nM will be called intermediate compound.

bioactivity_class = []
for i in df2.standard_value:
  if float(i) >= 10000:
    bioactivity_class.append("inactive")
  elif float(i) <= 1000:
    bioactivity_class.append("active")
  else:
    bioactivity_class.append("intermediate")

Iterate the molecule_chembl_id to a list

molecule_chembl_id = []
for i in df2.molecule_chembl_id:
  molecule_chembl_id.append(i)

Iterate canocical_smiles to a list

canonical_smiles = []
for i in df2.canonical_smiles:
  canonical_smiles.append(i)

Combine the 4 lists into a dataframe

data_tuples = list(zip(molecule_chembl_id, canonical_smiles, bioactivity_class, standard_value))
df3 = pd.DataFrame( data_tuples,  columns=['molecule_chembl_id', 'canonical_smiles', 'bioactivity_class', 'standard_value'])
df3
molecule_chembl_idcanonical_smilesbioactivity_classstandard_value
0CHEMBL187579Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21intermediate7200.0
1CHEMBL188487O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21intermediate9400.0
2CHEMBL185698O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21inactive13500.0
3CHEMBL426082O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21inactive13110.0
4CHEMBL187717O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-]intermediate2000.0
……………
128CHEMBL2146517COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c…inactive10600.0
129CHEMBL187460C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)Cinactive10100.0
130CHEMBL363535Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12inactive11500.0
131CHEMBL227075Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1inactive10700.0
132CHEMBL45830CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)Cinactive78900.0

Saves dataframe to CSV

df3.to_csv("bioactivity_preprocessed_data.csv", index= False)

Let’s copy to the Google Drive

! cp bioactivity_preprocessed_data.csv "/content/gdrive/My Drive/Colab Notebooks/data"
! cp bioactivity_preprocessed_data.csv "/content/gdrive/My Drive/Colab Notebooks/data"
! ls "/content/gdrive/My Drive/Colab Notebooks/data"

Part 2: Exploratory Data Analysis

  1. Clean the smiles notation which represent the chemical structure of the compound in the dataset
    • Remove small organic compounds
    • Remove salt
  2. Calculate Lipinski’s descriptions
    • MW
    • Log P
    • No. H-bond donor
    • No. H-bond acceptor
  3. Perform Exploratory Data Analysis (EDA)
    • Box Plot
    • Scatter Plot
    • Statistical Analysis

We’re going to select only two by activity class which are the active and the inactive so that we can easily compare between the active compounds and the inactive compounds.

Install conda and rdkit

! 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/')

Load bioactivity data

import pandas as pd
df = pd.read_csv("bioactivity_data_preprocessed.csv")

Calculate Lipinski descriptions

Christopher Lipinski, a scientist at Pfizer, came up with a set of rule-of-thumb for evaluating the druglikeness of compounds. Such druglikeness is based on the Absorption, Distribution, Metabolism and Excretion (ADME) that is also known as the pharmacokinetic profile. Lipinski analyzed all orally active FDA-approved drugs in the formulation of what is to be known as the Rule-of-Five or Lipinski’s Rule.

The Lipinski’s Rule stated the following:

  • Molecular weight < 500 Dalton
  • Octanol-water partition coefficient (LogP) < 5
  • Hydrogen bond donors < 5
  • Hydrogen bond acceptors < 10

Import libraries

import numpy as np
from rdkit import Chem
from rdkit.Chem import Descriptors, Lipinski

Calculate Descriptors

# 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)
    i=0  
    for mol in 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])
        i=i+1      
    
    columnNames=["MW","LogP","NumHDonors","NumHAcceptors"]   
    descriptors = pd.DataFrame(data=baseData,columns=columnNames)
    
    return descriptors

Smiles notation contains the chemical information and so what the chemical information tells us is the exact atomic details of het molecule.

df_lipinski = lipinski(df.canonical_smiles)

Combine Dataframes

df_lipinski
MWLogPNumHDonorsNumHAcceptors
0281.2711.892620.05.0
1415.5893.813200.02.0
2421.1902.660500.04.0
3293.3473.630800.03.0
4338.3443.539000.05.0
……………
128338.3593.401020.05.0
129296.3663.443300.03.0
130276.2914.095640.03.0
131278.3073.291020.03.0
132282.3834.105300.02.0
df_lipinski dataset

133 rows × 4 columns

We have 4 descriptors that are MW(molecular weight) which tells us the size, LogP which tells us the solubility and NumHDonors which tells us the relative number of the hydrogen bond donors and NumHAcceptors which tells us the relative number of the hydrogen acceptors.

df
molecule_chembl_idcanonical_smilesstandard_valuebioactivity_class
0CHEMBL187579Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc217200.0inactive
1CHEMBL188487O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc219400.0inactive
2CHEMBL185698O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc2113500.0active
3CHEMBL426082O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc2113110.0active
4CHEMBL187717O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-]2000.0inactive
……………
128CHEMBL2146517COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c…10600.0NaN
129CHEMBL187460C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)C10100.0NaN
130CHEMBL363535Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc1211500.0NaN
131CHEMBL227075Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO110700.0NaN
132CHEMBL45830CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)C78900.0NaN
Dataset created in Part 1

133 rows × 4 columns

df_combined = pd.concat([df,df_lipinski], axis=1)
df_combined
molecule_chembl_idcanonical_smilesstandard_valuebioactivity_classMWLogPNumHDonorsNumHAcceptors
0CHEMBL187579Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc217200.0inactive281.2711.892620.05.0
1CHEMBL188487O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc219400.0inactive415.5893.813200.02.0
2CHEMBL185698O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc2113500.0active421.1902.660500.04.0
3CHEMBL426082O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc2113110.0active293.3473.630800.03.0
4CHEMBL187717O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-]2000.0inactive338.3443.539000.05.0
………………………
128CHEMBL2146517COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c…10600.0NaN338.3593.401020.05.0
129CHEMBL187460C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)C10100.0NaN296.3663.443300.03.0
130CHEMBL363535Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc1211500.0NaN276.2914.095640.03.0
131CHEMBL227075Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO110700.0NaN278.3073.291020.03.0
132CHEMBL45830CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)C78900.0NaN282.3834.105300.02.0
Combined data set

133 rows × 8 columns

Convert IC50 to pIC50

The reason for doing the IC50 to pIC50 transformation which is essentially the negative logarithmic transformation from IC50 value is that the original IC50 value has uneven distribution of the data points.

To allow IC50 data to be more uniformly distributed, we will convert IC50 to the negative logarithmic scale which is essentially -log10(IC50).

This custom function pIC50() will accept a DataFrame as input and will:

  • Take the IC50 values from the standard_value column and converts it from nM to M by multiplying the value by 10−9
  • Take the molar value and apply -log10
  • Delete the standard_value column and create a new pIC50 column
# https://github.com/chaninlab/estrogen-receptor-alpha-qsar/blob/master/02_ER_alpha_RO5.ipynb
import numpy as np
def pIC50(input):
    pIC50 = []
    for i in input['standard_value_norm']:
        molar = i*(10**-9) # Converts nM to M
        pIC50.append(-np.log10(molar))
    input['pIC50'] = pIC50
    x = input.drop('standard_value_norm', 1)
        
    return x

Point to note: Values greater than 100,000,000 will be fixed at 100,000,000 otherwise the negative logarithmic value will become negative.

df_combined.standard_value.describe()

count 1.330000e+02
mean 8.017926e+12
std 3.344888e+13
min 5.000000e+01
25% 1.070000e+04
50% 2.350000e+04
75% 3.000000e+05
max 3.311311e+14
Name: standard_value, dtype: float64

-np.log10( (10**-9)* 100000000 )

1.0

-np.log10( (10**-9)* 10000000000 ) #make interpretation a bit more difficult

-1.0

def norm_value(input):
    norm = []
    # read through the individual values in the standard value column
    for i in input['standard_value']:
        # if the value is greater than 100 million it will cap the value to be hundred million
        # so that the value will not exceed 100 million
        # Therefore after performing negative algorithmic transformation it will not be less than 1.0.
        if i > 100000000:
          i = 100000000
        norm.append(i)
    input['standard_value_norm'] = norm
    x = input.drop('standard_value', 1)
        
    return x

Apply the norm_value() function so that the values in the standard_value is normalized.

df_norm = norm_value(df_combined)
df_norm
molecule_chembl_idcanonical_smilesbioactivity_classMWLogPNumHDonorsNumHAcceptorsstandard_value_norm
0CHEMBL187579Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21inactive281.2711.892620.05.07200.0
1CHEMBL188487O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21inactive415.5893.813200.02.09400.0
2CHEMBL185698O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21active421.1902.660500.04.013500.0
3CHEMBL426082O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21active293.3473.630800.03.013110.0
4CHEMBL187717O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-]inactive338.3443.539000.05.02000.0
………………………
128CHEMBL2146517COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c…NaN338.3593.401020.05.010600.0
129CHEMBL187460C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)CNaN296.3663.443300.03.010100.0
130CHEMBL363535Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12NaN276.2914.095640.03.011500.0
131CHEMBL227075Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1NaN278.3073.291020.03.010700.0
132CHEMBL45830CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)CNaN282.3834.105300.02.078900.0
Dataset after normalization

133 rows × 8 columns

df_norm.standard_value_norm.describe()

count 1.330000e+02
mean 2.110164e+07
std 4.089714e+07
min 5.000000e+01
25% 1.070000e+04
50% 2.350000e+04
75% 3.000000e+05
max 1.000000e+08
Name: standard_value_norm, dtype: float64

We’re going to apply the PIC50 function to the normalized data frame and we’re going to call the new data frame to be df_final.

df_final = pcIC50(df_norm)
df_final
molecule_chembl_idcanonical_smilesbioactivity_classMWLogPNumHDonorsNumHAcceptorspIC50
0CHEMBL187579Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21inactive281.2711.892620.05.05.142668
1CHEMBL188487O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21inactive415.5893.813200.02.05.026872
2CHEMBL185698O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21active421.1902.660500.04.04.869666
3CHEMBL426082O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21active293.3473.630800.03.04.882397
4CHEMBL187717O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-]inactive338.3443.539000.05.05.698970
………………………
128CHEMBL2146517COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c…NaN338.3593.401020.05.04.974694
129CHEMBL187460C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)CNaN296.3663.443300.03.04.995679
130CHEMBL363535Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12NaN276.2914.095640.03.04.939302
131CHEMBL227075Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1NaN278.3073.291020.03.04.970616
132CHEMBL45830CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)CNaN282.3834.105300.02.04.102923
Dataset

133 rows × 8 columns

We have created a new column called pIC50 and we have already deleted the original IC50 column.

df_final.pIC50.describe()

count 133.000000
mean 4.060148
std 1.783762
min 1.000000
25% 3.522879
50% 4.628932
75% 4.970616
max 7.301030
Name: pIC50, dtype: float64

Removing the “intermediate” bioactivity class

df_2class = df_final[df_final.bioactivity_class != "intermediate"]
molecule_chembl_idcanonical_smilesbioactivity_classMWLogPNumHDonorsNumHAcceptorspIC50
0CHEMBL187579Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21inactive281.2711.892620.05.05.142668
1CHEMBL188487O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21inactive415.5893.813200.02.05.026872
2CHEMBL185698O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21active421.1902.660500.04.04.869666
3CHEMBL426082O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21active293.3473.630800.03.04.882397
4CHEMBL187717O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-]inactive338.3443.539000.05.05.698970
………………………
128CHEMBL2146517COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c…NaN338.3593.401020.05.04.974694
129CHEMBL187460C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)CNaN296.3663.443300.03.04.995679
130CHEMBL363535Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12NaN276.2914.095640.03.04.939302
131CHEMBL227075Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1NaN278.3073.291020.03.04.970616
132CHEMBL45830CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)CNaN282.3834.105300.02.04.102923
Dataset after removing intermediate class

133 rows × 8 columns

Exploratory Data Analysis (Chemical Space Analysis) via Lipinski descriptors

We’re going to call the exploratory data analysis to be chemical space analysis because what it essentially does is it allows us to look at the chemical space.

The chemical space is kind of like a chemical universe.

Each chemical compound could be thought of as like stars.

Jose Medina Franco

Active molecules would be compared to a constellation and it will be referred to as constellation. He developed an approach which he termed constellation plot whereby you could perform chemical space analysis and create the constellation plot whereby the active molecule would be correspondingly have larger size in comparison with the less active molecule.

Import library

import seaborn as sns
sns.set(style = "ticks")
import maplotlib.pyplot as plt

Frequency plot of the 2 bioactivity classes

We’re going to create a frequency plot comparing the inactive molecules.

plt.figure(figsize=(5.5, 5.5))
sns.countplot(x='bioactivity_class', data=df_2class, edgecolor='black')
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('Frequency', fontsize=14, fontweight='bold')
plt.savefig('plot_bioactivity_class.pdf')
Bioactivity versus Frequency

Scatter plot of MW versus LogP

We’re going to make a scatter plot of the molecular weight versus feed LogP or the solubility of the molecules.

plt.figure(figsize=(5.5, 5.5))
sns.scatterplot(x='MW', y='LogP', data=df_2class, hue='bioactivity_class', size='pIC50', edgecolor='black', alpha=0.7)
plt.xlabel('MW', fontsize=14, fontweight='bold')
plt.ylabel('LogP', fontsize=14, fontweight='bold')
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0)
plt.savefig('plot_MW_vs_LogP.pdf')

Box Plots

pIC50 value
plt.figure(figsize=(5.5, 5.5))
sns.boxplot(x = 'bioactivity_class', y = 'pIC50', data = df_2class)
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('pIC50 value', fontsize=14, fontweight='bold')
plt.savefig('plot_ic50.pdf')
Statistical analysis | Mann – Whitney U Test

We’re going to apply this Mann – Whitney U Test to test the statistical significance of the difference whether they are different or not different and so the code for performing the manually U Test was modified from Machine Learning Mastery

def mannwhitney(descriptor, verbose=False):
  # https://machinelearningmastery.com/nonparametric-statistical-significance-tests-in-python/
  from numpy.random import seed
  from numpy.random import randn
  from scipy.stats import mannwhitneyu
# seed the random number generator
  seed(1)
# actives and inactives
  selection = [descriptor, 'bioactivity_class']
  df = df_2class[selection]
  active = df[df.bioactivity_class == 'active']
  active = active[descriptor]
  selection = [descriptor, 'bioactivity_class']
  df = df_2class[selection]
  inactive = df[df.bioactivity_class == 'inactive']
  inactive = inactive[descriptor]
# compare samples
  stat, p = mannwhitneyu(active, inactive)
  #print('Statistics=%.3f, p=%.3f' % (stat, p))
# interpret
  alpha = 0.05
  if p > alpha:
    interpretation = 'Same distribution (fail to reject H0)'
  else:
    interpretation = 'Different distribution (reject H0)'
  
  results = pd.DataFrame({'Descriptor':descriptor,
                          'Statistics':stat,
                          'p':p,
                          'alpha':alpha,
                          'Interpretation':interpretation}, index=[0])
  filename = 'mannwhitneyu_' + descriptor + '.csv'
  results.to_csv(filename)
  return results
mannwhitney("PIC50")
DescriptorStatisticspalphaInterpretation
0pIC500.01.662636e-100.05Different distribution (reject H0)
MW
plt.figure(figsize=(5.5, 5.5))
sns.boxplot(x = 'bioactivity_class', y = 'MW', data = df_2class)
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('MW', fontsize=14, fontweight='bold')
plt.savefig('plot_MW.pdf')
mannwhitney("MW")
DescriptorStatisticspalphaInterpretation
0MW409.50.0015250.05Different distribution (reject H0)
LogP
plt.figure(figsize=(5.5, 5.5))
sns.boxplot(x = 'bioactivity_class', y = 'LogP', data = df_2class)
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('LogP', fontsize=14, fontweight='bold')
plt.savefig('plot_LogP.pdf')
mannwhitney('LogP')
DescriptorStatisticspalphaInterpretation
0LogP712.50.2958050.05Same distribution (fail to reject H0)
NumHDonors
plt.figure(figsize=(5.5, 5.5))
sns.boxplot(x = 'bioactivity_class', y = 'NumHDonors', data = df_2class)
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('NumHDonors', fontsize=14, fontweight='bold')
plt.savefig('plot_NumHDonors.pdf')
mannwhitney('NumHDonors')
DescriptorStatisticspalphaInterpretation
0NumHDonors299.50.0000240.05Different distribution (reject H0)
NumHAcceptors
plt.figure(figsize=(5.5, 5.5))
sns.boxplot(x = 'bioactivity_class', y = 'NumHAcceptors', data = df_2class)
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('NumHAcceptors', fontsize=14, fontweight='bold')
plt.savefig('plot_NumHAcceptors.pdf')
mannwhitney('NumHAcceptors')
DescriptorStatisticspalphaInterpretation
0NumHAcceptors415.00.0015570.05Different distribution (reject H0)
Interpretations of Statistical
Box Plots
pIC50 values

Taking a look at pIC50 values, the actives and inactives displayed statistically significant difference, which is to be expected since threshold values (IC50 < 1,000 nM = Actives while IC50 > 10,000 nM = Inactives, corresponding to pIC50 > 6 = Actives and pIC50 < 5 = Inactives) were used to define actives and inactives.

Lipinski’s descriptors

Of the 4 Lipinski’s descriptors (MW, LogP, NumHDonors and NumHAcceptors), only LogP exhibited no difference between the actives and inactives while the other 3 descriptors (MW, NumHDonors and NumHAcceptors) shows statistically significant difference between actives and inactives.

Zip Files

! zip -r results.zip . -i *.csv *.pdf

Part 3: Descriptor calculation

  1. Read in CSV file as a Dataframe
  2. Prepare input file to PADEL-Descriptor
  3. Calculate fingerprints using PADEL – Descriptor

Download PaDEL – Descriptor

! wget https://github.com/dataprofessor/bioinformatics/raw/master/padel.zip
! wget https://github.com/dataprofessor/bioinformatics/raw/master/padel.sh
! unzip padel.zip

Load Bioactivity Data

! wget https://raw.githubusercontent.com/dataprofessor/data/master/acetylcholinesterase_04_bioactivity_data_3class_pIC50.csv
import pandas as pd
df3 = pd.read_csv('acetylcholinesterase_04_bioactivity_data_3class_pIC50.csv')
df3
Unnamed: 0molecule_chembl_idcanonical_smilesclassMWLogPNumHDonorsNumHAcceptorspIC50
00CHEMBL133897CCOc1nn(-c2cccc(OCc3ccccc3)c2)c(=O)o1active312.3252.803200.06.06.124939
11CHEMBL336398O=C(N1CCCCC1)n1nc(-c2ccc(Cl)cc2)nc1SCC1CC1active376.9134.554600.05.07.000000
22CHEMBL131588CN(C(=O)n1nc(-c2ccc(Cl)cc2)nc1SCC(F)(F)F)c1ccccc1inactive426.8515.357400.05.04.301030
33CHEMBL130628O=C(N1CCCCC1)n1nc(-c2ccc(Cl)cc2)nc1SCC(F)(F)Factive404.8454.706900.05.06.522879
44CHEMBL130478CSc1nc(-c2ccc(OC(F)(F)F)cc2)nn1C(=O)N(C)Cactive346.3343.095300.06.06.096910
…………………………
46904690CHEMBL4293155CC(C)(C)c1cc(/C=C/C(=O)NCCC2CCN(Cc3ccccc3Cl)CC…intermediate511.1507.072302.03.05.612610
46914691CHEMBL4282558CC(C)(C)c1cc(/C=C/C(=O)NCCC2CCN(Cc3cccc(Cl)c3)…intermediate511.1507.072302.03.05.595166
46924692CHEMBL4281727CC(C)(C)c1cc(/C=C/C(=O)NCCC2CCN(Cc3ccc(Br)cc3)…intermediate555.6017.181402.03.05.419075
46934693CHEMBL4292349CC(C)(C)c1cc(/C=C/C(=O)NCCC2CCN(Cc3cccc([N+](=…intermediate521.7026.327102.05.05.460924
46944694CHEMBL4278260CC(C)(C)c1cc(/C=C/C(=O)NCCC2CCN(Cc3ccc(C#N)cc3…intermediate501.7156.290582.04.05.555955

4695 rows × 9 columns

selection = ['canonical_smiles','molecule_chembl_id']
df3_selection = df3[selection]
df3_selection.to_csv('molecule.smi', sep='\t', index=False, header=False)
! cat molecule.smi | head -5

CCOc1nn(-c2cccc(OCc3ccccc3)c2)c(=O)o1 CHEMBL133897 O=C(N1CCCCC1)n1nc(-c2ccc(Cl)cc2)nc1SCC1CC1 CHEMBL336398 CN(C(=O)n1nc(-c2ccc(Cl)cc2)nc1SCC(F)(F)F)c1ccccc1 CHEMBL131588 O=C(N1CCCCC1)n1nc(-c2ccc(Cl)cc2)nc1SCC(F)(F)F CHEMBL130628 CSc1nc(-c2ccc(OC(F)(F)F)cc2)nn1C(=O)N(C)C CHEMBL130478

How many molecules do we have?

! cat molecule.smi | wc -l

4695

Calculate fingerprint descriptors

Calculate PaDEL descriptors

! cat padel.sh
! bash padel.sh
! ls -l

Preparing the X and Y Data Matrices

X data matrix

df3_X = pd.read_csv('descriptors_output.csv')
df3_X
NamePubchemFP0PubchemFP1PubchemFP2PubchemFP3PubchemFP4PubchemFP5PubchemFP6PubchemFP7PubchemFP8PubchemFP9PubchemFP10PubchemFP11PubchemFP12PubchemFP13PubchemFP14PubchemFP15PubchemFP16PubchemFP17PubchemFP18PubchemFP19PubchemFP20PubchemFP21PubchemFP22PubchemFP23PubchemFP24PubchemFP25PubchemFP26PubchemFP27PubchemFP28PubchemFP29PubchemFP30PubchemFP31PubchemFP32PubchemFP33PubchemFP34PubchemFP35PubchemFP36PubchemFP37PubchemFP38…PubchemFP841PubchemFP842PubchemFP843PubchemFP844PubchemFP845PubchemFP846PubchemFP847PubchemFP848PubchemFP849PubchemFP850PubchemFP851PubchemFP852PubchemFP853PubchemFP854PubchemFP855PubchemFP856PubchemFP857PubchemFP858PubchemFP859PubchemFP860PubchemFP861PubchemFP862PubchemFP863PubchemFP864PubchemFP865PubchemFP866PubchemFP867PubchemFP868PubchemFP869PubchemFP870PubchemFP871PubchemFP872PubchemFP873PubchemFP874PubchemFP875PubchemFP876PubchemFP877PubchemFP878PubchemFP879PubchemFP880
0CHEMBL336398111000000111101110100000000000000100010…0000000000000000000000000000000000000000
1CHEMBL133897111000000111101100111000000000000000000…0000000000000000000000000000000000000000
2CHEMBL130628111000000111101110100001100000000100010…0000000000000000000000000000000000000000
3CHEMBL131588110000000111101110100001100000000100010…0000000000000000000000000000000000000000
4CHEMBL130478110000000111001110110001100000000100000…0000000000000000000000000000000000000000
…………………………………………………………………………………………………………………………………………………………………………………………………………………………
4690CHEMBL4293155111100000111101100110000000000000000010…0000000000000000000000000000000000000000
4691CHEMBL4282558111100000111101100110000000000000000010…0000000000000000000000000000000000000000
4692CHEMBL4281727111100000111101100110000000000000000000…0000000000000000000000000000000000000000
4693CHEMBL4292349111100000111101100111000000000000000000…0000000000000000000000000000000000000000
4694CHEMBL4278260111100000111111100110000000000000000000…0000000000000000000000000000000000000000

4695 rows × 882 columns

df3_X = df3_X.drop(columns=['Name'])
df3_X

Y variable

Convert IC50 to pIC50

df3_Y = df3['pIC50']
df3_Y

Combining X and Y variable

dataset3 = pd.concat([df3_X,df3_Y], axis=1)
dataset3
dataset3 = pd.concat([df3_X,df3_Y], axis=1)
dataset3
PubchemFP0PubchemFP1PubchemFP2PubchemFP3PubchemFP4PubchemFP5PubchemFP6PubchemFP7PubchemFP8PubchemFP9PubchemFP10PubchemFP11PubchemFP12PubchemFP13PubchemFP14PubchemFP15PubchemFP16PubchemFP17PubchemFP18PubchemFP19PubchemFP20PubchemFP21PubchemFP22PubchemFP23PubchemFP24PubchemFP25PubchemFP26PubchemFP27PubchemFP28PubchemFP29PubchemFP30PubchemFP31PubchemFP32PubchemFP33PubchemFP34PubchemFP35PubchemFP36PubchemFP37PubchemFP38PubchemFP39…PubchemFP842PubchemFP843PubchemFP844PubchemFP845PubchemFP846PubchemFP847PubchemFP848PubchemFP849PubchemFP850PubchemFP851PubchemFP852PubchemFP853PubchemFP854PubchemFP855PubchemFP856PubchemFP857PubchemFP858PubchemFP859PubchemFP860PubchemFP861PubchemFP862PubchemFP863PubchemFP864PubchemFP865PubchemFP866PubchemFP867PubchemFP868PubchemFP869PubchemFP870PubchemFP871PubchemFP872PubchemFP873PubchemFP874PubchemFP875PubchemFP876PubchemFP877PubchemFP878PubchemFP879PubchemFP880pIC50
01110000001111011101000000000000001000100…0000000000000000000000000000000000000006.124939
11110000001111011001110000000000000000000…0000000000000000000000000000000000000007.000000
21110000001111011101000011000000001000100…0000000000000000000000000000000000000004.301030
31100000001111011101000011000000001000100…0000000000000000000000000000000000000006.522879
41100000001110011101100011000000001000000…0000000000000000000000000000000000000006.096910
…………………………………………………………………………………………………………………………………………………………………………………………………………………………
46901111000001111011001100000000000000000100…0000000000000000000000000000000000000005.612610
46911111000001111011001100000000000000000100…0000000000000000000000000000000000000005.595166
46921111000001111011001100000000000000000000…0000000000000000000000000000000000000005.419075
46931111000001111011001110000000000000000000…0000000000000000000000000000000000000005.460924
46941111000001111111001100000000000000000000…0000000000000000000000000000000000000005.555955

4695 rows × 882 columns

dataset3.to_csv('acetylcholinesterase_06_bioactivity_data_3class_pIC50_pubchem_fp.csv', index=False)

Part 4: Model Building

  1. Read in CSV file as a Dataframe
  2. Remove low variance features
  3. Data Splitting
  4. Build Regression Model
  5. Make a scatter plot

Import libraries

import pandas as pd
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor

Load the data set

❓ In Part 3, we have prepared a pop-can fingerprint and in Part 2, we have prepared Lipinski descriptors and then the question was what’s the difference between these two?

➕ Firstly the descriptor will provide us with a set of simple molecular descriptors that essentially will be giving us a quick overview of the drop light properties of the molecule.
➕ So, historically Christopher Lipinski created a set of four descriptors that the had investigated in his research that are responsible for drop light properties whereby the analyzed a set of orally active drugs and then he came up with his rule of five will make good oral drugs.

➕ For the top ten fingerprints which we will be using as well for the model building. It is describing the local features of the molecules so that Lipinski descriptor will be describing the global features of the molecule particularly the molecular size of the molecule the solubility of the molecule and also the number of hydrogen bond donor and acceptor which is the propensity to accept and donate hydrogen bonds.

! wget https://github.com/dataprofessor/data/raw/master/acetylcholinesterase_06_bioactivity_data_3class_pIC50_pubchem_fp.csv
df = pd.read_csv('acetylcholinesterase_06_bioactivity_data_3class_pIC50_pubchem_fp.csv')

Features

The Acetylcholinesterase data set contains 881 input features and 1 output variable (pIC50 values).

Each molecule will be given a unique fingerprint kind of like each of us humans fingerprint kind of like each of humans have unique fingerprint. So the unique fingerprints of each molecule will allow the machine learning algorithm to learn from the unique properties in terms of the molecular properties of the compound and then create a model that will be able to distinguish between compounds that are active compounds that are inactive.

❗ This is the goal of our model building we want to see which functional group of fingerprints are essential for designing a good drug or a potent one.

So target variable that we are using for our prediction is called pIC50 which is the negative logarithm of IC50 value.

Input features

X = df.drop('pIC50', axis=1)
X
PubchemFP0PubchemFP1PubchemFP2PubchemFP3PubchemFP4PubchemFP5PubchemFP6PubchemFP7PubchemFP8PubchemFP9PubchemFP10PubchemFP11PubchemFP12PubchemFP13PubchemFP14PubchemFP15PubchemFP16PubchemFP17PubchemFP18PubchemFP19PubchemFP20PubchemFP21PubchemFP22PubchemFP23PubchemFP24PubchemFP25PubchemFP26PubchemFP27PubchemFP28PubchemFP29PubchemFP30PubchemFP31PubchemFP32PubchemFP33PubchemFP34PubchemFP35PubchemFP36PubchemFP37PubchemFP38PubchemFP39…PubchemFP841PubchemFP842PubchemFP843PubchemFP844PubchemFP845PubchemFP846PubchemFP847PubchemFP848PubchemFP849PubchemFP850PubchemFP851PubchemFP852PubchemFP853PubchemFP854PubchemFP855PubchemFP856PubchemFP857PubchemFP858PubchemFP859PubchemFP860PubchemFP861PubchemFP862PubchemFP863PubchemFP864PubchemFP865PubchemFP866PubchemFP867PubchemFP868PubchemFP869PubchemFP870PubchemFP871PubchemFP872PubchemFP873PubchemFP874PubchemFP875PubchemFP876PubchemFP877PubchemFP878PubchemFP879PubchemFP880
01110000001111011101000000000000001000100…0000000000000000000000000000000000000000
11110000001111011001110000000000000000000…0000000000000000000000000000000000000000
21110000001111011101000011000000001000100…0000000000000000000000000000000000000000
31100000001111011101000011000000001000100…0000000000000000000000000000000000000000
41100000001110011101100011000000001000000…0000000000000000000000000000000000000000
…………………………………………………………………………………………………………………………………………………………………………………………………………………………
46901111000001111011001100000000000000000100…0000000000000000000000000000000000000000
46911111000001111011001100000000000000000100…0000000000000000000000000000000000000000
46921111000001111011001100000000000000000000…0000000000000000000000000000000000000000
46931111000001111011001110000000000000000000…0000000000000000000000000000000000000000
46941111000001111111001100000000000000000000…0000000000000000000000000000000000000000

4695 rows × 881 columns

Output Features

Y = df.pIC50
Y

Let’s examine the data dimension

X.shape

(4695, 881)

Y.shape

(4695,)

Remove low variance features

from sklearn.feature_selection import VarianceThreshold
selection = VarianceThreshold(threshold=(.8 * (1 - .8)))    
X = selection.fit_transform(X)
X.shape

(4695, 137)

Data split (80 / 20 ratio)

X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)
X_train.shape, Y_train.shape

((3756, 137), (3756,))

X_test.shape, Y_test.shape

((939, 137), (939,))

Building a Regression Model using Random Forest

model = RandomForestRegressor(n_estimators=100)
model.fit(X_train, Y_train)
r2 = model.score(X_test, Y_test)
r2

0.540922477079912

Y_pred = model.predict(X_test)

Scatter Plot of Experimental vs Predicted pIC50 Values

import seaborn as sns
import matplotlib.pyplot as plt
sns.set(color_codes=True)
sns.set_style("white")
ax = sns.regplot(Y_test, Y_pred, scatter_kws={'alpha':0.4})
ax.set_xlabel('Experimental pIC50', fontsize='large', fontweight='bold')
ax.set_ylabel('Predicted pIC50', fontsize='large', fontweight='bold')
ax.set_xlim(0, 12)
ax.set_ylim(0, 12)
ax.figure.set_size_inches(5, 5)
plt.show
Scatter Plot of Experimental and Predicted

Part 5: Model Comparison

  1. Read in CSV files as a Dataframe
  2. Remove low variance features
  3. Data Splitting
  4. Build Several Regression Models
  5. Make a performance comparison plot

Import Libraries

!pip install lazypredict
import pandas as pd
import seaborn as sns
from sklearn.model_selection import train_test_split
import lazypredict
from lazypredict.Supervised import LazyRegressor

Load the data set

! wget https://github.com/dataprofessor/data/raw/master/acetylcholinesterase_06_bioactivity_data_3class_pIC50_pubchem_fp.csv
df = pd.read_csv('acetylcholinesterase_06_bioactivity_data_3class_pIC50_pubchem_fp.csv')
X = df.drop('pIC50', axis=1)
Y = df.pIC50

Data pre-processing

# Examine X dimension
X.shape

(4695, 881)

# Remove low variance features
from sklearn.feature_selection import VarianceThreshold
selection = VarianceThreshold(threshold=(.8 * (1 - .8)))    
X = selection.fit_transform(X)
X.shape

(4695, 137)

# Perform data splitting using 80/20 ratio
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=42)

Compare ML Algorithms

# Defines and builds the lazyclassifier
clf = LazyRegressor(verbose=0,ignore_warnings=True, custom_metric=None)
models_train,predictions_train = clf.fit(X_train, X_train, Y_train, Y_train)
models_test,predictions_test = clf.fit(X_train, X_test, Y_train, Y_test)
# Performance table of the training set (80% subset)
predictions_train
Adjusted R-SquaredR-SquaredRMSETime Taken
Model
ExtraTreesRegressor0.860.860.575.98
DecisionTreeRegressor0.860.860.570.17
ExtraTreeRegressor0.860.860.570.14
GaussianProcessRegressor0.860.860.575.03
RandomForestRegressor0.820.830.644.70
XGBRegressor0.820.830.652.12
BaggingRegressor0.800.810.670.59
MLPRegressor0.760.770.756.38
HistGradientBoostingRegressor0.670.690.873.40
LGBMRegressor0.670.690.870.44
KNeighborsRegressor0.630.650.922.97
SVR0.560.581.016.54
NuSVR0.550.571.024.91
GradientBoostingRegressor0.440.461.141.71
Ridge0.310.331.270.06
LinearRegression0.310.331.270.11
TransformedTargetRegressor0.310.331.270.10
LassoCV0.300.331.273.63
ElasticNetCV0.300.331.273.49
RidgeCV0.300.331.270.19
SGDRegressor0.300.321.280.19
BayesianRidge0.290.321.280.15
HuberRegressor0.290.311.290.66
LassoLarsCV0.280.311.290.56
LassoLarsIC0.280.311.290.14
LinearSVR0.270.301.300.77
PoissonRegressor0.250.281.320.12
AdaBoostRegressor0.200.231.360.89
OrthogonalMatchingPursuit0.200.231.370.08
OrthogonalMatchingPursuitCV0.200.231.370.18
GeneralizedLinearRegressor0.190.221.370.07
TweedieRegressor0.190.221.370.09
GammaRegressor0.190.221.370.07
Lars0.190.221.370.15
LarsCV0.120.151.430.54
Lasso-0.040.001.550.07
ElasticNet-0.040.001.550.06
DummyRegressor-0.040.001.550.04
LassoLars-0.040.001.550.07
PassiveAggressiveRegressor-0.17-0.131.650.14
KernelRidge-14.25-13.705.951.41
RANSACRegressor-808435070627303626113024.00-778939570047825400037376.001370167375456.901.18
# Performance table of the test set (20% subset)
predictions_test
R-SquaredRMSETime Taken
Model
HistGradientBoostingRegressor0.541.062.13
LGBMRegressor0.541.060.46
RandomForestRegressor0.521.084.56
BaggingRegressor0.481.120.54
NuSVR0.481.123.47
SVR0.481.124.29
KNeighborsRegressor0.461.140.97
MLPRegressor0.451.156.73
GradientBoostingRegressor0.421.181.70
XGBRegressor0.421.181.17
ExtraTreesRegressor0.341.265.89
Ridge0.321.280.04
RidgeCV0.321.280.13
ElasticNetCV0.321.283.75
LassoCV0.321.283.95
ExtraTreeRegressor0.311.290.12
SGDRegressor0.311.290.18
TransformedTargetRegressor0.311.290.07
LinearRegression0.311.290.08
BayesianRidge0.311.290.16
LassoLarsCV0.311.290.45
LassoLarsIC0.311.290.09
HuberRegressor0.311.290.61
LinearSVR0.291.310.73
DecisionTreeRegressor0.281.310.16
OrthogonalMatchingPursuit0.241.360.04
OrthogonalMatchingPursuitCV0.241.360.12
Lars0.211.380.10
AdaBoostRegressor0.211.380.77
LarsCV0.151.430.46
Lasso-0.001.550.05
ElasticNet-0.001.550.03
DummyRegressor-0.001.550.03
LassoLars-0.001.550.05
PassiveAggressiveRegressor-0.221.710.09
GaussianProcessRegressor-4.993.803.88
KernelRidge-13.825.981.28
RANSACRegressor-225543784142202044678144.00737597884681.011.13

Data Visualization of Model performance

# Bar plot of R-squared values
import matplotlib.pyplot as plt
import seaborn as sns
#train["R-Squared"] = [0 if i < 0 else i for i in train.iloc[:,0] ]
plt.figure(figsize=(5, 10))
sns.set_theme(style="whitegrid")
ax = sns.barplot(y=predictions_train.index, x="R-Squared", data=predictions_train)
ax.set(xlim=(0, 1))
[(0.0, 1.0)]
# Bar plot of RMSE values
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(5, 10))
sns.set_theme(style="whitegrid")
ax = sns.barplot(y=predictions_train.index, x="RMSE", data=predictions_train)
ax.set(xlim=(0, 10))
[(0.0, 10.0)]
# Bar plot of calculation time
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(5, 10))
sns.set_theme(style="whitegrid")
ax = sns.barplot(y=predictions_train.index, x="Time Taken", data=predictions_train,
                 order = predictions_train.sort_values("Time Taken").index)
ax.set(xlim=(0, 10))
[(0.0, 10.0)]

Part 6: Model Deployment

  1. Build Regression Model from Part 4
  2. Code the Web app -> Save Model to file

Resources:


Eda AYDIN sitesinden daha fazla şey keşfedin

Son gönderilerin e-postanıza gönderilmesi için abone olun.

Leave a Reply