Datasets:
Upload AggregatorAdvisor Preprocessing Script.py
Browse files
AggregatorAdvisor Preprocessing Script.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Script to sanitize and split AggregatorAdvisor dataset
|
| 2 |
+
|
| 3 |
+
# 1. Load modules
|
| 4 |
+
|
| 5 |
+
pip install rdkit
|
| 6 |
+
pip install molvs
|
| 7 |
+
import pandas as pd
|
| 8 |
+
import numpy as np
|
| 9 |
+
import urllib.request
|
| 10 |
+
import tqdm
|
| 11 |
+
import rdkit
|
| 12 |
+
from rdkit import Chem
|
| 13 |
+
import molvs
|
| 14 |
+
|
| 15 |
+
standardizer = molvs.Standardizer()
|
| 16 |
+
fragment_remover = molvs.fragment.FragmentRemover()
|
| 17 |
+
|
| 18 |
+
#3. Resolve SMILES parse error
|
| 19 |
+
|
| 20 |
+
# Smiles is 'None', found the compound on ChemSpider
|
| 21 |
+
# Smiles displayed 'Explicit valence for atom # 2 O, 3, is greater than permitted'
|
| 22 |
+
# https://www.chemspider.com/Chemical-Structure.17588253.html?rid=026abd00-5d7b-4c7a-b279-3ba43ab46203
|
| 23 |
+
AA.loc[AA['smiles'] == '[O-][N+](=[O-])C1=CC=CC(=C1)C2=NC(CO2)C3=CC=CC=C3' , 'smiles'] = 'c1ccc(cc1)C2COC(=N2)c3cccc(c3)[N+](=O)[O-]'
|
| 24 |
+
|
| 25 |
+
# Smiles is 'None', found the compound on ChemSpider
|
| 26 |
+
# Smiles displayed 'Explicit valence for atom # 2 O, 3, is greater than permitted'
|
| 27 |
+
# https://www.chemspider.com/Chemical-Structure.17588254.html?rid=0f94ced5-dee6-4274-b0c5-796500b40be7
|
| 28 |
+
AA.loc[AA['smiles'] == '[O-][N+](=[O-])C1=CC=CC(=C1)C2=NCCC(O2)C3=CC=CC=C3', 'smiles'] = 'c1ccc(cc1)C2CCN=C(O2)c3cccc(c3)[N+](=O)[O-]'
|
| 29 |
+
|
| 30 |
+
#4. Sanitize with MolVS and print problems
|
| 31 |
+
|
| 32 |
+
AA['X'] = [ \
|
| 33 |
+
rdkit.Chem.MolToSmiles(
|
| 34 |
+
fragment_remover.remove(
|
| 35 |
+
standardizer.standardize(
|
| 36 |
+
rdkit.Chem.MolFromSmiles(
|
| 37 |
+
smiles))))
|
| 38 |
+
for smiles in AA['smiles']]
|
| 39 |
+
|
| 40 |
+
problems = []
|
| 41 |
+
for index, row in tqdm.tqdm(AA.iterrows()):
|
| 42 |
+
result = molvs.validate_smiles(row['X'])
|
| 43 |
+
if len(result) == 0:
|
| 44 |
+
continue
|
| 45 |
+
problems.append( (row['substance_id'], result) )
|
| 46 |
+
|
| 47 |
+
# most are because it includes the salt form and/or it is not neutralized
|
| 48 |
+
for substance_id, alert in problems:
|
| 49 |
+
print(f"substance_id: {substance_id}, problem: {alert[0]}")
|
| 50 |
+
|
| 51 |
+
#5. Select columns and rename the dataset
|
| 52 |
+
|
| 53 |
+
AA.rename(columns={'X': 'new SMILES'}, inplace=True)
|
| 54 |
+
AA[['new SMILES', 'substance_id', 'aggref_index', 'logP']].to_csv('AggregatorAdvisor.csv', index=False)
|