Datasets:
Delete REDOX Interference_ preprocessing script.py
Browse files
REDOX Interference_ preprocessing script.py
DELETED
|
@@ -1,83 +0,0 @@
|
|
| 1 |
-
#1. Import modules
|
| 2 |
-
|
| 3 |
-
pip install rdkit
|
| 4 |
-
pip install molvs
|
| 5 |
-
import pandas as pd
|
| 6 |
-
import numpy as np
|
| 7 |
-
import rdkit
|
| 8 |
-
import molvs
|
| 9 |
-
from rdkit import Chem
|
| 10 |
-
|
| 11 |
-
standardizer = molvs.Standardizer()
|
| 12 |
-
fragment_remover = molvs.fragment.FragmentRemover()
|
| 13 |
-
|
| 14 |
-
# 2. Convert the SDF file from the original paper into data frame
|
| 15 |
-
# Before running the code, please download SDF files from the original paper
|
| 16 |
-
# https://pubs.acs.org/doi/10.1021/acs.jmedchem.3c00482
|
| 17 |
-
|
| 18 |
-
from rdkit.Chem import PandasTools
|
| 19 |
-
sdfFile = 'Redox_training_set_curated.sdf'
|
| 20 |
-
dataframe = PandasTools.LoadSDF(sdfFile)
|
| 21 |
-
dataframe.to_csv('redox.csv', index=False)
|
| 22 |
-
df = pd.read_csv('redox.csv')
|
| 23 |
-
|
| 24 |
-
# 3. Resolve SMILES parse error
|
| 25 |
-
# Some of the 'Raw_SMILES' rows contain TWO SMILES separated by ';'' and, they cause SMILES parse error (which means they cannot be read)
|
| 26 |
-
# So we separated the SMILES and renamed the columns
|
| 27 |
-
|
| 28 |
-
df.rename(columns = {'PUBCHEM_EXT_DATASOURCE_REGID': 'REGID_1'}, inplace = True)
|
| 29 |
-
df.rename(columns = {'Other REGIDs': 'REGID_2'}, inplace = True)
|
| 30 |
-
|
| 31 |
-
df.insert(3, 'SMILES_2', np.NaN)
|
| 32 |
-
df['SMILES_2'] = df['Raw_SMILES'].str.split(';').str[1]
|
| 33 |
-
df['Raw_SMILES'] = df['Raw_SMILES'].str.split(';').str[0]
|
| 34 |
-
df.rename(columns= {'Raw_SMILES' : 'SMILES_1'}, inplace = True)
|
| 35 |
-
|
| 36 |
-
df.insert(10, 'AC50_uM_2', np.NaN)
|
| 37 |
-
df['AC50_uM_2'] = df['AC50_uM'].str.split(';').str[1]
|
| 38 |
-
df['AC50_uM'] = df['AC50_uM'].str.split(';').str[0]
|
| 39 |
-
df.rename(columns = {'AC50_uM': 'AC50_uM_1'}, inplace = True)
|
| 40 |
-
|
| 41 |
-
# 4. Sanitize with MolVS and print problems
|
| 42 |
-
|
| 43 |
-
df['X_1'] = [ \
|
| 44 |
-
rdkit.Chem.MolToSmiles(
|
| 45 |
-
fragment_remover.remove(
|
| 46 |
-
standardizer.standardize(
|
| 47 |
-
rdkit.Chem.MolFromSmiles(
|
| 48 |
-
smiles))))
|
| 49 |
-
for smiles in df['SMILES_1']]
|
| 50 |
-
|
| 51 |
-
def process_smiles(smiles):
|
| 52 |
-
if pd.isna(smiles):
|
| 53 |
-
return None
|
| 54 |
-
try:
|
| 55 |
-
return rdkit.Chem.MolToSmiles(
|
| 56 |
-
fragment_remover.remove(
|
| 57 |
-
standardizer.standardize(
|
| 58 |
-
rdkit.Chem.MolFromSmiles(smiles))))
|
| 59 |
-
except Exception as e:
|
| 60 |
-
print(f"Error processing SMILES {smiles}: {e}")
|
| 61 |
-
return None
|
| 62 |
-
|
| 63 |
-
df['X_2'] = df['SMILES_2'].apply(process_smiles)
|
| 64 |
-
|
| 65 |
-
# 5. Rename the columns
|
| 66 |
-
|
| 67 |
-
df.rename(columns={'X_1' : 'newSMILES_1', 'X_2' : 'newSMILES_2'}, inplace = True)
|
| 68 |
-
|
| 69 |
-
# 6. Create a file with sanitized SMILES
|
| 70 |
-
|
| 71 |
-
df[['REGID_1',
|
| 72 |
-
'REGID_2',
|
| 73 |
-
'newSMILES_1',
|
| 74 |
-
'newSMILES_2',
|
| 75 |
-
'log_AC50_M',
|
| 76 |
-
'Efficacy',
|
| 77 |
-
'CC-v2',
|
| 78 |
-
'Outcome',
|
| 79 |
-
'InChIKey',
|
| 80 |
-
'AC50_uM_1',
|
| 81 |
-
'AC50_uM_2',
|
| 82 |
-
'ID',
|
| 83 |
-
'ROMol']].to_csv('redox_sanitized.csv', index = False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|