Update app.py
Browse files
app.py
CHANGED
@@ -28,27 +28,39 @@ class Config:
|
|
28 |
self.seed = 42
|
29 |
|
30 |
|
31 |
-
def predict_stability(model_choice, organism_choice, pdb_file=None, sequence=None, cfg=Config()):
|
32 |
-
return pdb_file, sequence
|
33 |
-
# if pdb_file:
|
34 |
-
# pdb_path = pdb_file.name # Get the path of the uploaded PDB file
|
35 |
-
# os.system("chmod 777 bin/foldseek")
|
36 |
-
# sequences = get_foldseek_seq(pdb_path)
|
37 |
-
# if not sequences:
|
38 |
-
# return "Failed to extract sequence from the PDB file."
|
39 |
-
# sequence = sequences[2] if model_choice == "SaProt" else sequences[0]
|
40 |
-
|
41 |
-
# if not sequence:
|
42 |
-
# return "No valid input provided."
|
43 |
-
|
44 |
-
# cell_line = "HeLa" if organism_choice == "Human" else "NIH3T3"
|
45 |
-
# cfg.model = f"sagawa/PLTNUM-{model_choice}-{cell_line}"
|
46 |
-
# cfg.architecture = model_choice
|
47 |
-
# cfg.model_path = f"sagawa/PLTNUM-{model_choice}-{cell_line}"
|
48 |
-
|
49 |
-
# output = predict(cfg, sequence)
|
50 |
-
# return output
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
|
54 |
def get_foldseek_seq(pdb_path):
|
@@ -155,7 +167,7 @@ with gr.Blocks() as demo:
|
|
155 |
)
|
156 |
|
157 |
predict_button.click(
|
158 |
-
fn=
|
159 |
inputs=[model_choice, organism_choice, pdb_file],
|
160 |
outputs=prediction_output,
|
161 |
)
|
@@ -173,8 +185,8 @@ with gr.Blocks() as demo:
|
|
173 |
)
|
174 |
|
175 |
predict_button.click(
|
176 |
-
fn=
|
177 |
-
inputs=[model_choice, organism_choice,
|
178 |
outputs=prediction_output,
|
179 |
)
|
180 |
|
|
|
28 |
self.seed = 42
|
29 |
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
def predict_stability_with_pdb(model_choice, organism_choice, pdb_file, cfg=Config()):
|
33 |
+
try:
|
34 |
+
pdb_path = pdb_file.name
|
35 |
+
os.system("chmod 777 bin/foldseek")
|
36 |
+
sequences = get_foldseek_seq(pdb_path)
|
37 |
+
if not sequences:
|
38 |
+
return "Failed to extract sequence from the PDB file."
|
39 |
+
sequence = sequences[2] if model_choice == "SaProt" else sequences[0]
|
40 |
+
|
41 |
+
return predict_stability_core(model_choice, organism_choice, sequence, cfg)
|
42 |
+
except Exception as e:
|
43 |
+
return f"An error occurred: {str(e)}"
|
44 |
+
|
45 |
+
|
46 |
+
def predict_stability_with_sequence(model_choice, organism_choice, sequence, cfg=Config()):
|
47 |
+
try:
|
48 |
+
if not sequence:
|
49 |
+
return "No valid sequence provided."
|
50 |
+
|
51 |
+
return predict_stability_core(model_choice, organism_choice, sequence, cfg)
|
52 |
+
except Exception as e:
|
53 |
+
return f"An error occurred: {str(e)}"
|
54 |
+
|
55 |
+
|
56 |
+
def predict_stability_core(model_choice, organism_choice, sequence, cfg=Config()):
|
57 |
+
cell_line = "HeLa" if organism_choice == "Human" else "NIH3T3"
|
58 |
+
cfg.model = f"sagawa/PLTNUM-{model_choice}-{cell_line}"
|
59 |
+
cfg.architecture = model_choice
|
60 |
+
cfg.model_path = f"sagawa/PLTNUM-{model_choice}-{cell_line}"
|
61 |
+
|
62 |
+
output = predict(cfg, sequence)
|
63 |
+
return output
|
64 |
|
65 |
|
66 |
def get_foldseek_seq(pdb_path):
|
|
|
167 |
)
|
168 |
|
169 |
predict_button.click(
|
170 |
+
fn=predict_stability_with_pdb,
|
171 |
inputs=[model_choice, organism_choice, pdb_file],
|
172 |
outputs=prediction_output,
|
173 |
)
|
|
|
185 |
)
|
186 |
|
187 |
predict_button.click(
|
188 |
+
fn=predict_stability_with_sequence,
|
189 |
+
inputs=[model_choice, organism_choice, sequence],
|
190 |
outputs=prediction_output,
|
191 |
)
|
192 |
|