Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -166,7 +166,17 @@ def get_drug_features_from_api(drug_name):
|
|
| 166 |
features = {
|
| 167 |
'SMILES': 'No data',
|
| 168 |
'pharmacodynamics': 'No data',
|
| 169 |
-
'toxicity': 'No data'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
}
|
| 171 |
|
| 172 |
# Extract SMILES if available
|
|
@@ -211,6 +221,56 @@ def get_drug_features_from_api(drug_name):
|
|
| 211 |
if 'String' in text:
|
| 212 |
features['toxicity'] = text['String'][:500] # Limit to 500 chars
|
| 213 |
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
return features
|
| 216 |
|
|
@@ -343,6 +403,11 @@ def predict_severity(drug1, drug2):
|
|
| 343 |
'SMILES': ['SMILES', 'smiles'],
|
| 344 |
'pharmacodynamics': ['pharmacodynamics', 'Pharmacodynamics', 'pharmacology'],
|
| 345 |
'toxicity': ['toxicity', 'Toxicity']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
}
|
| 347 |
|
| 348 |
for feature, possible_cols in column_mappings.items():
|
|
@@ -388,7 +453,11 @@ def predict_severity(drug1, drug2):
|
|
| 388 |
drug1_features = {
|
| 389 |
'SMILES': 'No data from API',
|
| 390 |
'pharmacodynamics': 'No data from API',
|
| 391 |
-
'toxicity': 'No data from API'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
}
|
| 393 |
|
| 394 |
drug2_features = get_drug_features_from_api(drug2)
|
|
@@ -396,7 +465,11 @@ def predict_severity(drug1, drug2):
|
|
| 396 |
drug2_features = {
|
| 397 |
'SMILES': 'No data from API',
|
| 398 |
'pharmacodynamics': 'No data from API',
|
| 399 |
-
'toxicity': 'No data from API'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
}
|
| 401 |
|
| 402 |
# Verify we got data for both drugs
|
|
|
|
| 166 |
features = {
|
| 167 |
'SMILES': 'No data',
|
| 168 |
'pharmacodynamics': 'No data',
|
| 169 |
+
'toxicity': 'No data',
|
| 170 |
+
'mechanism': 'No data',
|
| 171 |
+
'metabolism': 'No data',
|
| 172 |
+
'route-of-elimination':'No data',
|
| 173 |
+
'half-life':'No data'
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+

|
| 177 |
+
|
| 178 |
+
route': 'No data'
|
| 179 |
+
|
| 180 |
}
|
| 181 |
|
| 182 |
# Extract SMILES if available
|
|
|
|
| 221 |
if 'String' in text:
|
| 222 |
features['toxicity'] = text['String'][:500] # Limit to 500 chars
|
| 223 |
break
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
# Look for mechanism information
|
| 227 |
+
if section['TOCHeading'] == 'mechanism':
|
| 228 |
+
if 'Information' in section:
|
| 229 |
+
for info in section['Information']:
|
| 230 |
+
if 'Value' in info and 'StringWithMarkup' in info['Value']:
|
| 231 |
+
for text in info['Value']['StringWithMarkup']:
|
| 232 |
+
if 'String' in text:
|
| 233 |
+
features['mechanism'] = text['String'][:500] # Limit to 500 chars
|
| 234 |
+
break
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
# Look for metabolism information
|
| 238 |
+
if section['TOCHeading'] == 'metabolism':
|
| 239 |
+
if 'Information' in section:
|
| 240 |
+
for info in section['Information']:
|
| 241 |
+
if 'Value' in info and 'StringWithMarkup' in info['Value']:
|
| 242 |
+
for text in info['Value']['StringWithMarkup']:
|
| 243 |
+
if 'String' in text:
|
| 244 |
+
features['metabolism'] = text['String'][:500] # Limit to 500 chars
|
| 245 |
+
break
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
# Look for route-of-elimination information
|
| 249 |
+
if section['TOCHeading'] == 'route-of-elimination':
|
| 250 |
+
if 'Information' in section:
|
| 251 |
+
for info in section['Information']:
|
| 252 |
+
if 'Value' in info and 'StringWithMarkup' in info['Value']:
|
| 253 |
+
for text in info['Value']['StringWithMarkup']:
|
| 254 |
+
if 'String' in text:
|
| 255 |
+
features['route-of-elimination'] = text['String'][:500] # Limit to 500 chars
|
| 256 |
+
break
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
# Look for half-life information
|
| 260 |
+
if section['TOCHeading'] == 'half-life':
|
| 261 |
+
if 'Information' in section:
|
| 262 |
+
for info in section['Information']:
|
| 263 |
+
if 'Value' in info and 'StringWithMarkup' in info['Value']:
|
| 264 |
+
for text in info['Value']['StringWithMarkup']:
|
| 265 |
+
if 'String' in text:
|
| 266 |
+
features['half-life'] = text['String'][:500] # Limit to 500 chars
|
| 267 |
+
break
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
|
| 274 |
|
| 275 |
return features
|
| 276 |
|
|
|
|
| 403 |
'SMILES': ['SMILES', 'smiles'],
|
| 404 |
'pharmacodynamics': ['pharmacodynamics', 'Pharmacodynamics', 'pharmacology'],
|
| 405 |
'toxicity': ['toxicity', 'Toxicity']
|
| 406 |
+
'mechanism': ['mechanism', 'Mechanism']
|
| 407 |
+
'metabolism': ['metabolism', 'Metabolism']
|
| 408 |
+
'route-of-elimination': ['route-of-elimination', 'Route-of-elimination']
|
| 409 |
+
- 'half-life': ['half-life', 'Half-life']
|
| 410 |
+
|
| 411 |
}
|
| 412 |
|
| 413 |
for feature, possible_cols in column_mappings.items():
|
|
|
|
| 453 |
drug1_features = {
|
| 454 |
'SMILES': 'No data from API',
|
| 455 |
'pharmacodynamics': 'No data from API',
|
| 456 |
+
'toxicity': 'No data from API',
|
| 457 |
+
'mechanism': 'No data from API',
|
| 458 |
+
'metabolism': 'No data from API',
|
| 459 |
+
'route-of-elimination': 'No data from API',
|
| 460 |
+
'half-life': 'No data from API'
|
| 461 |
}
|
| 462 |
|
| 463 |
drug2_features = get_drug_features_from_api(drug2)
|
|
|
|
| 465 |
drug2_features = {
|
| 466 |
'SMILES': 'No data from API',
|
| 467 |
'pharmacodynamics': 'No data from API',
|
| 468 |
+
'toxicity': 'No data from API',
|
| 469 |
+
'mechanism': 'No data from API',
|
| 470 |
+
'metabolism': 'No data from API',
|
| 471 |
+
'route-of-elimination': 'No data from API',
|
| 472 |
+
'half-life': 'No data from API'
|
| 473 |
}
|
| 474 |
|
| 475 |
# Verify we got data for both drugs
|