|
|
|
|
|
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 = 'Thiol_training_set_curated.sdf' |
|
dataframe = PandasTools.LoadSDF(sdfFile) |
|
dataframe.to_csv('thiol.csv', index=False) |
|
df = pd.read_csv('thiol.csv') |
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
df.rename(columns={'X_1' : 'newSMILES_1', 'X_2' : 'newSMILES_2', 'X_3' : 'newSMILES_3'}, inplace = True) |
|
|
|
|
|
|
|
|
|
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) |