Datasets:
File size: 2,818 Bytes
d68447d |
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 93 94 95 96 97 98 99 100 101 102 103 104 |
# 1. Load Modules
pip install rdkit
pip install molvs
import pandas as pd
import numpy as np
import rdkit
import molvs
from rdkit import Chem
standardizer = molvs.Standardizer()
fragment_remover = molvs.fragment.FragmentRemover()
# 2. Convert the SDF file from the original paper into data frame
# Before running the code, please download SDF files from the original paper
# https://pubs.acs.org/doi/10.1021/acs.jmedchem.3c00482
from rdkit.Chem import PandasTools
sdfFile = 'Thiol_training_set_curated.sdf'
dataframe = PandasTools.LoadSDF(sdfFile)
dataframe.to_csv('thiol.csv', index=False)
df = pd.read_csv('thiol.csv')
# 3. Resolve SMILES parse error
# Some of the 'Raw_SMILES' rows contain TWO SMILES separated by ';'' and, they cause SMILES parse error (which means they cannot be read)
# So we separated the SMILES and renamed the columns
df.rename(columns = {'PUBCHEM_EXT_DATASOURCE_REGID': 'REGID_1'}, inplace = True)
df.rename(columns = {'Other REGIDs': 'REGID_2'}, inplace = True)
df.insert(2, 'REGID_3', np.NaN)
df['REGID_3'] = df['REGID_2'].str.split(',').str[1]
df['REGID_2'] = df['REGID_2'].str.split(',').str[0]
df.insert(4, 'SMILES_2', np.NaN)
df.insert(5, 'SMILES_3', np.NaN)
df[['Raw_SMILES', 'SMILES_2', 'SMILES_3']] = df['Raw_SMILES'].str.split(';', expand=True)
df.rename(columns= {'Raw_SMILES' : 'SMILES_1'}, inplace = True)
# 4. Sanitize with MolVS and print problems
df['X_1'] = [ \
rdkit.Chem.MolToSmiles(
fragment_remover.remove(
standardizer.standardize(
rdkit.Chem.MolFromSmiles(
smiles))))
for smiles in df['SMILES_1']]
def process_smiles(smiles):
if pd.isna(smiles):
return None
try:
return rdkit.Chem.MolToSmiles(
fragment_remover.remove(
standardizer.standardize(
rdkit.Chem.MolFromSmiles(smiles))))
except Exception as e:
print(f"Error processing SMILES {smiles}: {e}")
return None
df['X_2'] = df['SMILES_2'].apply(process_smiles)
def process_smiles(smiles):
if pd.isna(smiles):
return None
try:
return rdkit.Chem.MolToSmiles(
fragment_remover.remove(
standardizer.standardize(
rdkit.Chem.MolFromSmiles(smiles))))
except Exception as e:
print(f"Error processing SMILES {smiles}: {e}")
return None
df['X_3'] = df['SMILES_3'].apply(process_smiles)
# 5. Rename the columns
df.rename(columns={'X_1' : 'newSMILES_1', 'X_2' : 'newSMILES_2', 'X_3' : 'newSMILES_3'}, inplace = True)
# 6. Create a file with sanitized SMILES
df[['REGID_1',
'REGID_2',
'REGID_3',
'newSMILES_1',
'newSMILES_2',
'newSMILES_3',
'log_AC50_M',
'Efficacy',
'CC-v2',
'Outcome',
'InChIKey',
'ID',
'ROMol']].to_csv('thiol_sanitized.csv', index = False) |