Update Processing Script.py
Browse files- Processing Script.py +4 -61
Processing Script.py
CHANGED
@@ -141,63 +141,6 @@ Long2023['X'] = [ \
|
|
141 |
smiles))))
|
142 |
for smiles in Long2023['SMILES']]
|
143 |
|
144 |
-
Long2023['X'] = [Chem.MolFromSmiles(smiles) for smiles in Long2023['X']]
|
145 |
-
for mol in Long2023['X']:
|
146 |
-
Chem.Kekulize(mol)
|
147 |
-
|
148 |
-
Long2023['X'] = [Chem.MolToSmiles(mol, kekuleSmiles=True) for mol in Long2023['X']]
|
149 |
-
|
150 |
-
problems = []
|
151 |
-
for index, row in tqdm.tqdm(Long2023.iterrows()):
|
152 |
-
result = molvs.validate_smiles(row['X'])
|
153 |
-
if len(result) == 0:
|
154 |
-
continue
|
155 |
-
problems.append( (row['ID'], result) )
|
156 |
-
|
157 |
-
# Most are because it includes the salt form and/or it is not neutralized
|
158 |
-
for id, alert in problems:
|
159 |
-
print(f"ID: {id}, problem: {alert[0]}")
|
160 |
-
|
161 |
-
for index, row in tqdm.tqdm(Long2023.iterrows()):
|
162 |
-
mol = Chem.MolFromSmiles(row['X'])
|
163 |
-
Chem.Kekulize(mol) # Attempt to kekulize the molecule
|
164 |
-
kekulized_smiles = Chem.MolToSmiles(mol, kekuleSmiles=True) # Get the kekulized SMILES
|
165 |
-
if row['X'] != kekulized_smiles:
|
166 |
-
print(f"Molecule with ID {row['ID']} could not be kekulized.")
|
167 |
-
|
168 |
-
#5. Resolve kekulization error
|
169 |
-
|
170 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)C2=C3C(=CC=CC3=CC=C2)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=CC=CC3=CC=CC(=C23)C1=O'
|
171 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)NCCCl)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)NCCCl)=CC3=CC=C2)C1=O'
|
172 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC=O)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC=O)=CC3=CC=C2)C1=O'
|
173 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)CCCCl)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)CCCCl)=CC3=CC=C2)C1=O'
|
174 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)C(Cl)(Cl)Cl)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)C(Cl)(Cl)Cl)=CC3=CC=C2)C1=O'
|
175 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc([N+](=O)[O-])cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC([N+](=O)[O-])=CC3=CC=C2)C1=O'
|
176 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(N)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(N)=CC3=CC=C2)C1=O'
|
177 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)Nc4ccc(Cl)cc4)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)NC4=CC=C(Cl)C=C4)=CC3=CC=C2)C1=O'
|
178 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)Nc4ccc(C#N)cc4)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)NC4=CC=C(C#N)C=C4)=CC3=CC=C2)C1=O'
|
179 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=S)Nc4ccc(Cl)cc4)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=S)NC4=CC=C(Cl)C=C4)=CC3=CC=C2)C1=O'
|
180 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(/N=C/c4ccc(C#N)cc4)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(/N=C/C4=CC=C(C#N)C=C4)=CC3=CC=C2)C1=O'
|
181 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=S)Nc4ccc(C#N)cc4)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=S)NC4=CC=C(C#N)C=C4)=CC3=CC=C2)C1=O'
|
182 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NCc4ccc5c(c4)OCO5)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NCC4=CC=C5OCOC5=C4)=CC3=CC=C2)C1=O'
|
183 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)NC(=O)c4ccccc4)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)NC(=O)C4=CC=CC=C4)=CC3=CC=C2)C1=O'
|
184 |
-
Long2023.loc[Long2023['X'] == 'C[C@H]1Oc2cc(cnc2N)-c2c(nn(C)c2C#N)CN(C)C(=O)c2ccc(F)cc21', 'X'] = 'C[C@H]1OC2=C(N)N=CC(=C2)C2=C(C#N)N(C)N=C2CN(C)C(=O)C2=CC=C(F)C=C21'
|
185 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)Nc4cc5c6c(cccc6c4)C(=O)N(CCN(C)C)C5=O)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)NC4=CC5=C6C(=CC=CC6=C4)C(=O)N(CCN(C)C)C5=O)=CC3=CC=C2)C1=O'
|
186 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NCc4ccc5c(c4)OCCO5)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NCC4=CC=C5OCCOC5=C4)=CC3=CC=C2)C1=O'
|
187 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)c4ccccc4)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)C4=CC=CC=C4)=CC3=CC=C2)C1=O'
|
188 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)NC(=O)CCl)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)NC(=O)CCl)=CC3=CC=C2)C1=O'
|
189 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)C(F)(F)F)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)C(F)(F)F)=CC3=CC=C2)C1=O'
|
190 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)Nc4ccc(OC(F)(F)F)cc4)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)NC4=CC=C(OC(F)(F)F)C=C4)=CC3=CC=C2)C1=O'
|
191 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(/N=C/c4cc(O)ccc4O)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(/N=C/C4=CC(O)=CC=C4O)=CC3=CC=C2)C1=O'
|
192 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=S)Nc4ccc(OC(F)(F)F)cc4)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=S)NC4=CC=C(OC(F)(F)F)C=C4)=CC3=CC=C2)C1=O'
|
193 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NCc4cc5c(cc4[N+](=O)[O-])OCO5)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NCC4=CC5=C(C=C4[N+](=O)[O-])OCO5)=CC3=CC=C2)C1=O'
|
194 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)Cc4ccc(Cl)cc4)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)CC4=CC=C(Cl)C=C4)=CC3=CC=C2)C1=O'
|
195 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(/N=C/c4cc5c(cc4[N+](=O)[O-])OCO5)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(/N=C/C4=CC5=C(C=C4[N+](=O)[O-])OCO5)=CC3=CC=C2)C1=O'
|
196 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(/N=C/c4ccc5c(c4)OCO5)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(/N=C/C4=CC=C5OCOC5=C4)=CC3=CC=C2)C1=O'
|
197 |
-
Long2023.loc[Long2023['X'] == 'CN(C)CCN1C(=O)c2cccc3cc(NC(=O)Nc4ccc5c(c4)OCO5)cc(c23)C1=O', 'X'] = 'CN(C)CCN1C(=O)C2=C3C(=CC(NC(=O)NC4=CC=C5OCOC5=C4)=CC3=CC=C2)C1=O'
|
198 |
-
|
199 |
-
#6. Print problems again to check if the errors have been resolved
|
200 |
-
|
201 |
problems = []
|
202 |
for index, row in tqdm.tqdm(Long2023.iterrows()):
|
203 |
result = molvs.validate_smiles(row['X'])
|
@@ -209,19 +152,19 @@ for index, row in tqdm.tqdm(Long2023.iterrows()):
|
|
209 |
for id, alert in problems:
|
210 |
print(f"ID: {id}, problem: {alert[0]}")
|
211 |
|
212 |
-
#
|
213 |
|
214 |
Long2023.rename(columns={'X': 'new SMILES', 'Y': 'Label'}, inplace=True)
|
215 |
Long2023[['new SMILES', 'Label']].to_csv('Long2023.csv', index=False)
|
216 |
|
217 |
-
#
|
218 |
|
219 |
import sys
|
220 |
from rdkit import DataStructs
|
221 |
from rdkit.Chem import AllChem as Chem
|
222 |
from rdkit.Chem import PandasTools
|
223 |
|
224 |
-
#
|
225 |
|
226 |
class MolecularFingerprint:
|
227 |
def __init__(self, fingerprint):
|
@@ -403,7 +346,7 @@ smiles_index = 0 # Because smiles is in the first column
|
|
403 |
realistic = realistic_split(HematoxLong2023.copy(), smiles_index, 0.75, split_for_exact_frac=True, cluster_method="Auto")
|
404 |
realistic_train, realistic_test = split_df_into_train_and_test_sets(realistic)
|
405 |
|
406 |
-
#
|
407 |
|
408 |
selected_columns = realistic_train[['new SMILES', 'Label']]
|
409 |
selected_columns.to_csv("HematoxLong2023_train.csv", index=False)
|
|
|
141 |
smiles))))
|
142 |
for smiles in Long2023['SMILES']]
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
problems = []
|
145 |
for index, row in tqdm.tqdm(Long2023.iterrows()):
|
146 |
result = molvs.validate_smiles(row['X'])
|
|
|
152 |
for id, alert in problems:
|
153 |
print(f"ID: {id}, problem: {alert[0]}")
|
154 |
|
155 |
+
#5. Select columns and rename the dataset
|
156 |
|
157 |
Long2023.rename(columns={'X': 'new SMILES', 'Y': 'Label'}, inplace=True)
|
158 |
Long2023[['new SMILES', 'Label']].to_csv('Long2023.csv', index=False)
|
159 |
|
160 |
+
#6. Import modules to split the dataset
|
161 |
|
162 |
import sys
|
163 |
from rdkit import DataStructs
|
164 |
from rdkit.Chem import AllChem as Chem
|
165 |
from rdkit.Chem import PandasTools
|
166 |
|
167 |
+
#7. Split the dataset into test and train
|
168 |
|
169 |
class MolecularFingerprint:
|
170 |
def __init__(self, fingerprint):
|
|
|
346 |
realistic = realistic_split(HematoxLong2023.copy(), smiles_index, 0.75, split_for_exact_frac=True, cluster_method="Auto")
|
347 |
realistic_train, realistic_test = split_df_into_train_and_test_sets(realistic)
|
348 |
|
349 |
+
#8. Test and train datasets have been made
|
350 |
|
351 |
selected_columns = realistic_train[['new SMILES', 'Label']]
|
352 |
selected_columns.to_csv("HematoxLong2023_train.csv", index=False)
|