Spaces:
Runtime error
Runtime error
Witold Wydmański
commited on
Commit
·
242f3e4
1
Parent(s):
6a7874b
fix: formatting, output type
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ def convert_outputs_to_pdb(outputs):
|
|
| 27 |
chain_index=outputs["chain_index"][i] if "chain_index" in outputs else None,
|
| 28 |
)
|
| 29 |
pdbs.append(to_pdb(pred))
|
| 30 |
-
return pdbs
|
| 31 |
|
| 32 |
def fold_prot_locally(sequence):
|
| 33 |
logger.info("Folding: " + sequence)
|
|
@@ -38,30 +38,41 @@ def fold_prot_locally(sequence):
|
|
| 38 |
pdb = convert_outputs_to_pdb(output)
|
| 39 |
return pdb
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
sample_code = """
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
fp.write(result)
|
| 56 |
-
fp.flush()
|
| 57 |
-
return fp.name
|
| 58 |
-
else:
|
| 59 |
-
with open(fname, "w") as fp:
|
| 60 |
-
fp.write(result)
|
| 61 |
-
fp.flush()
|
| 62 |
-
return fname
|
| 63 |
-
pdb_fname = fold_huggingface("MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAEDLQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN")
|
| 64 |
-
|
| 65 |
"""
|
| 66 |
|
| 67 |
tokenizer = AutoTokenizer.from_pretrained("facebook/esmfold_v1")
|
|
@@ -69,6 +80,25 @@ model = EsmForProteinFolding.from_pretrained("facebook/esmfold_v1", low_cpu_mem_
|
|
| 69 |
model.esm = model.esm.half()
|
| 70 |
torch.backends.cuda.matmul.allow_tf32 = True
|
| 71 |
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
|
|
|
| 27 |
chain_index=outputs["chain_index"][i] if "chain_index" in outputs else None,
|
| 28 |
)
|
| 29 |
pdbs.append(to_pdb(pred))
|
| 30 |
+
return pdbs[0]
|
| 31 |
|
| 32 |
def fold_prot_locally(sequence):
|
| 33 |
logger.info("Folding: " + sequence)
|
|
|
|
| 38 |
pdb = convert_outputs_to_pdb(output)
|
| 39 |
return pdb
|
| 40 |
|
| 41 |
+
def suggest(option):
|
| 42 |
+
if option == "Plastic degradation protein":
|
| 43 |
+
suggestion = "MGSSHHHHHHSSGLVPRGSHMRGPNPTAASLEASAGPFTVRSFTVSRPSGYGAGTVYYPTNAGGTVGAIAIVPGYTARQSSIKWWGPRLASHGFVVITIDTNSTLDQPSSRSSQQMAALRQVASLNGTSSSPIYGKVDTARMGVMGWSMGGGGSLISAANNPSLKAAAPQAPWDSSTNFSSVTVPTLIFACENDSIAPVNSSALPIYDSMSRNAKQFLEINGGSHSCANSGNSNQALIGKKGVAWMKRFMDNDTRYSTFACENPNSTRVSDFRTANCSLEDPAANKARKEAELAAATAEQ"
|
| 44 |
+
elif option == "Antifreeze protein":
|
| 45 |
+
suggestion = "QCTGGADCTSCTGACTGCGNCPNAVTCTNSQHCVKANTCTGSTDCNTAQTCTNSKDCFEANTCTDSTNCYKATACTNSSGCPGH"
|
| 46 |
+
elif option == "AI Generated protein":
|
| 47 |
+
suggestion = "MSGMKKLYEYTVTTLDEFLEKLKEFILNTSKDKIYKLTITNPKLIKDIGKAIAKAAEIADVDPKEIEEMIKAVEENELTKLVITIEQTDDKYVIKVELENEDGLVHSFEIYFKNKEEMEKFLELLEKLISKLSGS"
|
| 48 |
+
elif option == "7-bladed propeller fold":
|
| 49 |
+
suggestion = "VKLAGNSSLCPINGWAVYSKDNSIRIGSKGDVFVIREPFISCSHLECRTFFLTQGALLNDKHSNGTVKDRSPHRTLMSCPVGEAPSPYNSRFESVAWSASACHDGTSWLTIGISGPDNGAVAVLKYNGIITDTIKSWRNNILRTQESECACVNGSCFTVMTDGPSNGQASYKIFKMEKGKVVKSVELDAPNYHYEECSCYPNAGEITCVCRDNWHGSNRPWVSFNQNLEYQIGYICSGVFGDNPRPNDGTGSCGPVSSNGAYGVKGFSFKYGNGVWIGRTKSTNSRSGFEMIWDPNGWTETDSSFSVKQDIVAITDWSGYSGSFVQHPELTGLDCIRPCFWVELIRGRPKESTIWTSGSSISFCGVNSDTVGWSWPDGAELPFTIDK"
|
| 50 |
+
else:
|
| 51 |
+
suggestion = ""
|
| 52 |
+
return suggestion
|
| 53 |
+
|
| 54 |
sample_code = """
|
| 55 |
+
from gradio_client import Client
|
| 56 |
+
import json
|
| 57 |
+
|
| 58 |
+
client = Client("https://wwydmanski-esmfold.hf.space/")
|
| 59 |
+
|
| 60 |
+
def fold_huggingface(sequence, fname=None):
|
| 61 |
+
result = client.predict(
|
| 62 |
+
sequence, # str in 'sequence' Textbox component
|
| 63 |
+
api_name="/predict")
|
| 64 |
|
| 65 |
+
if fname is None:
|
| 66 |
+
with tempfile.NamedTemporaryFile("w", delete=False, suffix=".pdb", prefix="esmfold_") as fp:
|
| 67 |
+
fp.write(result)
|
| 68 |
+
fp.flush()
|
| 69 |
+
return fp.name
|
| 70 |
+
else:
|
| 71 |
+
with open(fname, "w") as fp:
|
| 72 |
+
fp.write(result)
|
| 73 |
+
fp.flush()
|
| 74 |
+
return fname
|
| 75 |
+
pdb_fname = fold_huggingface("MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAEDLQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
"""
|
| 77 |
|
| 78 |
tokenizer = AutoTokenizer.from_pretrained("facebook/esmfold_v1")
|
|
|
|
| 80 |
model.esm = model.esm.half()
|
| 81 |
torch.backends.cuda.matmul.allow_tf32 = True
|
| 82 |
|
| 83 |
+
with gr.Blocks() as demo:
|
| 84 |
+
gr.Markdown("# ESMFold")
|
| 85 |
+
with gr.Row():
|
| 86 |
+
with gr.Column():
|
| 87 |
+
inp = gr.Textbox(lines=1, label="Sequence")
|
| 88 |
+
name = gr.Dropdown(label="Choose a Sample Protein", value="Plastic degradation protein", choices=["Antifreeze protein", "Plastic degradation protein", "AI Generated protein", "7-bladed propeller fold", "custom"])
|
| 89 |
+
btn = gr.Button("🔬 Predict Structure ")
|
| 90 |
+
|
| 91 |
+
with gr.Row():
|
| 92 |
+
with gr.Column():
|
| 93 |
+
gr.Markdown("## Sample code")
|
| 94 |
+
gr.Code(sample_code, label="Sample usage", language="python", interactive=False)
|
| 95 |
+
|
| 96 |
+
with gr.Row():
|
| 97 |
+
with gr.Column():
|
| 98 |
+
gr.Markdown("## Output")
|
| 99 |
+
out = gr.Code(label="Output", interactive=False)
|
| 100 |
+
|
| 101 |
+
name.change(fn=suggest, inputs=name, outputs=inp)
|
| 102 |
+
btn.click(fold_prot_locally, inputs=[inp], outputs=[out])
|
| 103 |
|
| 104 |
+
demo.launch()
|