Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import gradio as gr
|
|
| 5 |
from evodiff.pretrained import OA_DM_38M, D3PM_UNIFORM_38M, MSA_OA_DM_MAXSUB
|
| 6 |
from evodiff.generate import generate_oaardm, generate_d3pm
|
| 7 |
from evodiff.generate_msa import generate_query_oadm_msa_simple
|
|
|
|
| 8 |
|
| 9 |
import py3Dmol
|
| 10 |
from colabfold.download import download_alphafold_params
|
|
@@ -97,6 +98,49 @@ def make_cond_seq(seq_len, msa_file, model_type, pred_structure):
|
|
| 97 |
return generated_sequence, molhtml
|
| 98 |
else:
|
| 99 |
return generated_sequence, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
usg_app = gr.Interface(
|
| 102 |
fn=make_uncond_seq,
|
|
@@ -130,6 +174,40 @@ csg_app = gr.Interface(
|
|
| 130 |
description="Evolutionary guided sequence generation with the `EvoDiff-MSA` model."
|
| 131 |
)
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
with gr.Blocks() as edapp:
|
| 135 |
with gr.Row():
|
|
@@ -140,11 +218,15 @@ with gr.Blocks() as edapp:
|
|
| 140 |
|
| 141 |
Created By: Microsoft Research [Sarah Alamdari, Nitya Thakkar, Rianne van den Berg, Alex X. Lu, Nicolo Fusi, ProfileAva P. Amini, and Kevin K. Yang]
|
| 142 |
|
| 143 |
-
Spaces App By: [Colby T. Ford]
|
| 144 |
"""
|
| 145 |
)
|
| 146 |
with gr.Row():
|
| 147 |
-
gr.TabbedInterface([usg_app, csg_app
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
|
| 150 |
|
|
|
|
| 5 |
from evodiff.pretrained import OA_DM_38M, D3PM_UNIFORM_38M, MSA_OA_DM_MAXSUB
|
| 6 |
from evodiff.generate import generate_oaardm, generate_d3pm
|
| 7 |
from evodiff.generate_msa import generate_query_oadm_msa_simple
|
| 8 |
+
from evodiff.conditional_generation import inpaint_simple, generate_scaffold
|
| 9 |
|
| 10 |
import py3Dmol
|
| 11 |
from colabfold.download import download_alphafold_params
|
|
|
|
| 98 |
return generated_sequence, molhtml
|
| 99 |
else:
|
| 100 |
return generated_sequence, None
|
| 101 |
+
|
| 102 |
+
def make_inpainted_idrs(sequence, start_idx, end_idx, model_type, pred_structure):
|
| 103 |
+
if model_type == "EvoDiff-Seq":
|
| 104 |
+
checkpoint = OA_DM_38M()
|
| 105 |
+
model, collater, tokenizer, scheme = checkpoint
|
| 106 |
+
sample, entire_sequence, generated_idr = inpaint_simple(model, sequence, start_idx, end_idx, tokenizer=tokenizer, device='cpu')
|
| 107 |
+
|
| 108 |
+
generated_idr_output = {
|
| 109 |
+
"original_sequence": sequence,
|
| 110 |
+
"generated_sequence": entire_sequence,
|
| 111 |
+
"original_region": sequence[start_idx:end_idx],
|
| 112 |
+
"generated_region": generated_idr
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
if pred_structure:
|
| 116 |
+
path_to_pdb = predict_protein(entire_sequence)
|
| 117 |
+
molhtml = display_pdb(path_to_pdb)
|
| 118 |
+
|
| 119 |
+
return generated_idr_output, molhtml
|
| 120 |
+
else:
|
| 121 |
+
return generated_idr_output, None
|
| 122 |
+
|
| 123 |
+
def make_scaffold_motifs(pdb_code, start_idx, end_idx, scaffold_length, model_type, pred_structure):
|
| 124 |
+
if model_type == "EvoDiff-Seq":
|
| 125 |
+
checkpoint = OA_DM_38M()
|
| 126 |
+
model, collater, tokenizer, scheme = checkpoint
|
| 127 |
+
data_top_dir = './'
|
| 128 |
+
generated_sequence, new_start_idx, new_end_idx = generate_scaffold(model, pdb_code, start_idx, end_idx, scaffold_length, data_top_dir, tokenizer, device='cpu')
|
| 129 |
+
|
| 130 |
+
generated_scaffold_output = {
|
| 131 |
+
"generated_sequence": generated_sequence,
|
| 132 |
+
"new_start_index": new_start_idx,
|
| 133 |
+
"new_end_index": new_end_idx
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
if pred_structure:
|
| 137 |
+
# path_to_pdb = predict_protein(generated_sequence)
|
| 138 |
+
path_to_pdb = f"scaffolding-pdbs/{pdb_code}.pdb"
|
| 139 |
+
molhtml = display_pdb(path_to_pdb)
|
| 140 |
+
|
| 141 |
+
return generated_scaffold_output, molhtml
|
| 142 |
+
else:
|
| 143 |
+
return generated_scaffold_output, None
|
| 144 |
|
| 145 |
usg_app = gr.Interface(
|
| 146 |
fn=make_uncond_seq,
|
|
|
|
| 174 |
description="Evolutionary guided sequence generation with the `EvoDiff-MSA` model."
|
| 175 |
)
|
| 176 |
|
| 177 |
+
idr_app = gr.Interface(
|
| 178 |
+
fn=make_inpainted_idrs,
|
| 179 |
+
inputs=[
|
| 180 |
+
gr.Textbox(placeholder="DQTERTVRSFEGRRTAPYLDSRNVLTIGYGHLLNRPGANKSWEGRLTSALPREFKQRLTELAASQLHETDVRLATARAQALYGSGAYFESVPVSLNDLWFDSVFNLGERKLLNWSGLRTKLESRDWGAAAKDLGRHTFGREPVSRRMAESMRMRRGIDLNHYNI", label = "Sequence"),
|
| 181 |
+
gr.Number(value=20, placeholder=20, label = "Start Index"),
|
| 182 |
+
gr.Number(value=50, placeholder=50, label = "End Index"),
|
| 183 |
+
gr.Dropdown(["EvoDiff-Seq"], value="EvoDiff-Seq", type="value", label = "Model"),
|
| 184 |
+
gr.Checkbox(value=False, label = "Predict Structure?", visible=False)
|
| 185 |
+
],
|
| 186 |
+
outputs=[
|
| 187 |
+
"text",
|
| 188 |
+
gr.HTML()
|
| 189 |
+
],
|
| 190 |
+
title = "Inpainting IDRs",
|
| 191 |
+
description="Inpaining a new region inside a given sequence using the `EvoDiff-Seq` model."
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
scaffold_app = gr.Interface(
|
| 195 |
+
fn=make_scaffold_motifs,
|
| 196 |
+
inputs=[
|
| 197 |
+
gr.Textbox(placeholder="1prw", label = "PDB Code"),
|
| 198 |
+
gr.Textbox(value="[15, 51]", placeholder="[15, 51]", label = "Start Index (as list)"),
|
| 199 |
+
gr.Textbox(value="[34, 70]", placeholder="[34, 70]", label = "End Index (as list)"),
|
| 200 |
+
gr.Number(value=75, placeholder=75, label = "Scaffold Length"),
|
| 201 |
+
gr.Dropdown(["EvoDiff-Seq", "EvoDiff-MSA"], value="EvoDiff-Seq", type="value", label = "Model"),
|
| 202 |
+
gr.Checkbox(value=False, label = "Predict Structure?", visible=False)
|
| 203 |
+
],
|
| 204 |
+
outputs=[
|
| 205 |
+
"text",
|
| 206 |
+
gr.HTML()
|
| 207 |
+
],
|
| 208 |
+
title = "Scaffolding functional motifs",
|
| 209 |
+
description="Scaffolding a new functional motif inside a given PDB structure using the `EvoDiff-Seq` model."
|
| 210 |
+
)
|
| 211 |
|
| 212 |
with gr.Blocks() as edapp:
|
| 213 |
with gr.Row():
|
|
|
|
| 218 |
|
| 219 |
Created By: Microsoft Research [Sarah Alamdari, Nitya Thakkar, Rianne van den Berg, Alex X. Lu, Nicolo Fusi, ProfileAva P. Amini, and Kevin K. Yang]
|
| 220 |
|
| 221 |
+
Spaces App By: Tuple, The Cloud Genomics Company [Colby T. Ford]
|
| 222 |
"""
|
| 223 |
)
|
| 224 |
with gr.Row():
|
| 225 |
+
gr.TabbedInterface([usg_app, csg_app, idr_app, scaffold_app],
|
| 226 |
+
["Unconditional sequence generation",
|
| 227 |
+
"Conditional generation",
|
| 228 |
+
"Inpainting IDRs",
|
| 229 |
+
"Scaffolding functional motifs"])
|
| 230 |
|
| 231 |
|
| 232 |
|