|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
|
|
|
from rdkit.Chem import PandasTools |
|
sdfFile = 'Redox_training_set_curated.sdf' |
|
dataframe = PandasTools.LoadSDF(sdfFile) |
|
dataframe.to_csv('redox.csv', index=False) |
|
df = pd.read_csv('redox.csv') |
|
|
|
|
|
|
|
|
|
|
|
df.rename(columns = {'PUBCHEM_EXT_DATASOURCE_REGID': 'REGID_1'}, inplace = True) |
|
df.rename(columns = {'Other REGIDs': 'REGID_2'}, inplace = True) |
|
|
|
df.insert(3, 'SMILES_2', np.NaN) |
|
df['SMILES_2'] = df['Raw_SMILES'].str.split(';').str[1] |
|
df['Raw_SMILES'] = df['Raw_SMILES'].str.split(';').str[0] |
|
df.rename(columns= {'Raw_SMILES' : 'SMILES_1'}, inplace = True) |
|
|
|
df.insert(10, 'AC50_uM_2', np.NaN) |
|
df['AC50_uM_2'] = df['AC50_uM'].str.split(';').str[1] |
|
df['AC50_uM'] = df['AC50_uM'].str.split(';').str[0] |
|
df.rename(columns = {'AC50_uM': 'AC50_uM_1'}, inplace = True) |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
df.rename(columns={'X_1' : 'newSMILES_1', 'X_2' : 'newSMILES_2'}, inplace = True) |
|
|
|
|
|
|
|
df[['REGID_1', |
|
'REGID_2', |
|
'newSMILES_1', |
|
'newSMILES_2', |
|
'log_AC50_M', |
|
'Efficacy', |
|
'CC-v2', |
|
'Outcome', |
|
'InChIKey', |
|
'AC50_uM_1', |
|
'AC50_uM_2', |
|
'ID', |
|
'ROMol']].to_csv('redox_sanitized.csv', index = False) |