|
import torch |
|
import torch.nn.functional as F |
|
from torch import nn |
|
import zipfile |
|
import gradio as gr |
|
from transformers import BertTokenizer, BertForSequenceClassification |
|
import os |
|
|
|
tokenizer = BertTokenizer.from_pretrained("dmis-lab/biobert-base-cased-v1.1") |
|
model = BertForSequenceClassification.from_pretrained("dmis-lab/biobert-base-cased-v1.1", num_labels=2) |
|
|
|
|
|
model.load_state_dict(torch.load('Bio_BERT_model.pth')) |
|
|
|
device = "cpu" |
|
|
|
def predict_drug_target_interaction(sentence): |
|
|
|
inputs = tokenizer.encode_plus( |
|
sentence, |
|
add_special_tokens=True, |
|
max_length=128, |
|
padding="max_length", |
|
truncation=True, |
|
return_tensors='pt' |
|
) |
|
|
|
input_ids = inputs['input_ids'].to(device) |
|
attention_mask = inputs['attention_mask'].to(device) |
|
token_type_ids = inputs.get('token_type_ids', None) |
|
if token_type_ids is not None: |
|
token_type_ids = token_type_ids.to(device) |
|
|
|
|
|
with torch.inference_mode(): |
|
outputs = model(input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids) |
|
logits = outputs.logits |
|
probabilities = F.softmax(logits, dim=-1) |
|
predictions = torch.argmax(logits, dim=-1) |
|
|
|
|
|
label = 'Drug-Target Interaction' if predictions.item() == 1 else 'No Interaction' |
|
|
|
|
|
prob_interaction = probabilities[0][1].item() |
|
prob_no_interaction = probabilities[0][0].item() |
|
|
|
return label, prob_interaction, prob_no_interaction |
|
|
|
|
|
def combined_prediction_and_extraction(sentence): |
|
|
|
label, prob_interaction, prob_no_interaction = predict_drug_target_interaction(sentence) |
|
|
|
if prob_interaction > prob_no_interaction: |
|
response = "There is a possible interaction between drug and target in the given input! ✔️" |
|
elif prob_interaction < prob_no_interaction: |
|
response = "There is NO interaction between the drug and target in the given input. ❌" |
|
else: |
|
response = "This interaction needs further studies to classify. 🔬" |
|
|
|
|
|
pred_labels_and_probs_gradio = {"Drug Interaction": prob_interaction, "No Interaction": prob_no_interaction} |
|
|
|
return pred_labels_and_probs_gradio, response |
|
|
|
|
|
description = """ |
|
# The Importance of Drug-Target Interactions in Pharmaceutical Development |
|
|
|
## 🌟 **Mechanism of Action** |
|
Understanding how a drug interacts with its target—usually a protein, enzyme, or receptor—is essential for uncovering its mechanism of action. This insight helps researchers grasp the therapeutic effects of drugs, paving the way for the development of **more effective treatments**. |
|
|
|
## 🎯 **Selectivity and Specificity** |
|
Targeting specific proteins and pathways minimizes side effects and boosts drug efficacy. **High specificity** ensures that the drug primarily interacts with its intended target, reducing the risk of off-target effects that could lead to adverse reactions. |
|
|
|
## 💡 **Drug Design and Development** |
|
Knowledge of drug-target interactions is crucial for crafting new pharmaceuticals. **Optimizing lead compounds** to enhance their affinity for the target can significantly elevate a drug's effectiveness, leading to **innovative treatment solutions**. |
|
|
|
## 🔍 **Predicting Pharmacokinetics and Pharmacodynamics** |
|
Understanding these interactions aids in predicting how a drug behaves in the body, including its absorption, distribution, metabolism, and excretion. This knowledge is vital for determining **appropriate dosages** and anticipating potential drug-drug interactions. |
|
|
|
## 🛡️ **Resistance Mechanisms** |
|
In fields like oncology and infectious diseases, drug-target interactions are crucial for understanding how **resistance** to treatments develops. By studying these interactions, researchers can devise strategies to **overcome or prevent resistance**, ensuring better patient outcomes. |
|
|
|
## ⚠️ **Safety and Toxicity** |
|
Understanding how drugs interact with unintended targets is essential for assessing **safety profiles**. This information is key to identifying potential toxic effects and **mitigating risks** associated with drug therapy. |
|
|
|
""" |
|
|
|
datainfo = """ |
|
The most prominent node in the graph is metformin, which is linked to various targets. This suggests that metformin has a wide range of biological interactions, possibly indicating its involvement in multiple pathways or therapeutic effects beyond its traditional use as an anti-diabetic drug. |
|
|
|
* Metformin interacts with AMP-activated protein kinase (AMPK), which is known to play a crucial role in cellular energy homeostasis. This aligns with metformin’s known mechanism of action in diabetes, where it helps modulate glucose metabolism through AMPK activation. |
|
Other significant metformin interactions include ROR1.69 and nucleoside, indicating additional pathways of relevance, possibly connected to immune modulation or other metabolic pathways. |
|
|
|
* Warfarin, an anticoagulant, is another highly connected node. Its targets include CYP2C9, an enzyme critical for its metabolism, and S-warfarin, which represents its active form. The network also includes its interaction with estrogen, AXIN1, and monoamine oxidase A, indicating potential off-target effects or interactions with other biological pathways. |
|
|
|
* The interaction between serotonin transporter protein and drugs like norepinephrine and serotonin indicates involvement in pathways related to mood regulation, which could be pertinent in psychiatric conditions. |
|
|
|
> The network shows that some drugs share common targets. Both metformin and warfarin interact with multiple common targets (like estrogen). This overlap could imply the potential for drug-drug interactions in patients taking both medications, possibly requiring careful management of therapy. |
|
""" |
|
|
|
|
|
def display_image(): |
|
return "DTI_knowledge graph highlighted.png" |
|
|
|
|
|
|
|
title = "Unlocking Precision: Predicting Drug-Target Interactions for Safer, Smarter Treatments" |
|
article = "Stay Safe!" |
|
examples = [ |
|
["Targeting the secretion of sEV PD-L1 has emerged as a promising strategy to enhance immunotherapy"], |
|
["These results suggested that AM would be a useful platform for the development of a new radiopharmaceutical targeting ER"], |
|
["AP significantly depended on a three-way interaction among the mouse group ORX-KO vs WT, the wake-sleep state, and the drug or vehicle infused."], |
|
["In addition, the pharmacodynamic genes SLC6A4 serotonin transporter and HTR2A serotonin-2A receptor have been examined in relation to efficacy and side effect profiles of these drugs"] |
|
] |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown(f"# {title}") |
|
|
|
with gr.Tab("Model Inference"): |
|
with gr.Row(): |
|
with gr.Column(scale=1, min_width=300): |
|
input_text = gr.Textbox(label="Input", placeholder="Enter your text here...") |
|
gr.Markdown("### Examples") |
|
gr.Examples( |
|
examples=examples, |
|
inputs=input_text, |
|
outputs=None, |
|
label="Select an Example" |
|
) |
|
|
|
|
|
with gr.Row(): |
|
submit_button = gr.Button("Submit") |
|
clear_button = gr.Button("Clear") |
|
|
|
with gr.Column(scale=1, min_width=300): |
|
predictions_output = gr.Label(num_top_classes=2, label="Predictions") |
|
inference_output = gr.Textbox(label="Prediction Inference", interactive=False) |
|
|
|
|
|
submit_button.click( |
|
fn=combined_prediction_and_extraction, |
|
inputs=input_text, |
|
outputs=[predictions_output, inference_output] |
|
) |
|
|
|
|
|
clear_button.click( |
|
fn=lambda: ("", "", ""), |
|
inputs=None, |
|
outputs=[input_text, predictions_output, inference_output] |
|
) |
|
with gr.Tab("Description"): |
|
gr.Markdown(description) |
|
|
|
with gr.Tab("About Data"): |
|
gr.Markdown(datainfo) |
|
gr.Image(value=display_image(), type="filepath") |
|
|
|
|
|
|
|
demo.launch() |