ribesstefano
commited on
Commit
•
f979fd7
1
Parent(s):
5c5788c
Created initial version of a Gradio app.
Browse files
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import protac_degradation_predictor as pdp
|
2 |
+
|
3 |
+
from typing import Dict, List, Literal
|
4 |
+
import difflib
|
5 |
+
|
6 |
+
import torch
|
7 |
+
import numpy as np
|
8 |
+
from rdkit import Chem
|
9 |
+
import gradio as gr
|
10 |
+
|
11 |
+
|
12 |
+
def gradio_app(
|
13 |
+
protac_smiles: str | List[str],
|
14 |
+
e3_ligase: str | List[str],
|
15 |
+
target_uniprot: str | List[str],
|
16 |
+
cell_line: str | List[str],
|
17 |
+
use_models_from_cv: bool = False,
|
18 |
+
) -> Dict[str, np.ndarray]:
|
19 |
+
|
20 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
21 |
+
avail_uniprots = pdp.avail_uniprots()
|
22 |
+
avail_cells = pdp.avail_cell_lines()
|
23 |
+
|
24 |
+
if target_uniprot not in avail_uniprots:
|
25 |
+
suggestions = difflib.get_close_matches(target_uniprot, avail_uniprots, n=3, cutoff=0.5)
|
26 |
+
suggestion_text = "Did you mean:" + ", ".join(suggestions) + "?" if suggestions else "No close matches found."
|
27 |
+
raise gr.Error(f"Invalid Uniprot ID. {suggestion_text}", duration=None)
|
28 |
+
|
29 |
+
if cell_line not in avail_cells:
|
30 |
+
suggestions = difflib.get_close_matches(cell_line, avail_cells, n=3, cutoff=0.5)
|
31 |
+
suggestion_text = "Did you mean:" + ", ".join(suggestions) + "?" if suggestions else "No close matches found."
|
32 |
+
raise gr.Error(f"Invalid Cell Line. {suggestion_text}", duration=None)
|
33 |
+
|
34 |
+
prediction = pdp.get_protac_active_proba(
|
35 |
+
protac_smiles,
|
36 |
+
e3_ligase,
|
37 |
+
target_uniprot,
|
38 |
+
cell_line,
|
39 |
+
device=device,
|
40 |
+
use_models_from_cv=use_models_from_cv,
|
41 |
+
)
|
42 |
+
mean_pred = {"Active": prediction['mean'], "Inactive": 1 - prediction['mean']}
|
43 |
+
majvote_pred = "Active" if prediction['majority_vote'] else "Inactive"
|
44 |
+
return mean_pred, majvote_pred
|
45 |
+
|
46 |
+
demo = gr.Interface(
|
47 |
+
fn=gradio_app,
|
48 |
+
inputs=[
|
49 |
+
gr.Textbox(placeholder="PROTAC SMILES", label="PROTAC SMILES"),
|
50 |
+
gr.Dropdown(pdp.avail_e3_ligases(), label="E3 ligase"),
|
51 |
+
gr.Textbox(placeholder="E.g., Q92769", label="Target Uniprot"),
|
52 |
+
gr.Textbox(placeholder="E.g., HeLa", label="Cell line"),
|
53 |
+
gr.Checkbox(label="Use models trained during cross-validation"),
|
54 |
+
],
|
55 |
+
outputs=[gr.Label(label="Average probability (confidence)"), gr.Label(label="Majority vote prediction")],
|
56 |
+
title="PROTAC Degradation Predictor",
|
57 |
+
examples=[ [
|
58 |
+
"Cc1ncsc1-c1ccc(CNC(=O)[C@@H]2C[C@@H](O)CN2C(=O)[C@@H](NC(=O)COCCCCCCCCCOCC(=O)Nc2ccc(C(=O)Nc3ccc(F)cc3N)cc2)C(C)(C)C)cc1",
|
59 |
+
"VHL",
|
60 |
+
"Q92769",
|
61 |
+
"HeLa",
|
62 |
+
],
|
63 |
+
],
|
64 |
+
description="Predict whether a PROTAC is active or inactive.",
|
65 |
+
)
|
66 |
+
|
67 |
+
demo.launch()
|