Simon Duerr commited on
Commit
e5ccf64
1 Parent(s): ff6c561

first commit

Browse files
Files changed (2) hide show
  1. app.py +74 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ import torch
4
+ import pydssp
5
+ import py3Dmol
6
+
7
+ import os
8
+
9
+
10
+ def get_pdb(pdb_code="", filepath=""):
11
+ try:
12
+ return filepath.name
13
+ except AttributeError as e:
14
+ if pdb_code is None or pdb_code == "":
15
+ return None
16
+ else:
17
+ os.system(f"wget -qnc https://files.rcsb.org/view/{pdb_code}.pdb")
18
+ return f"{pdb_code}.pdb"
19
+
20
+
21
+ def get_offset(pdb):
22
+ pdb_multiline = pdb.split("\n")
23
+ for line in pdb_multiline:
24
+ if line.startswith("ATOM"):
25
+ return int(line[22:27])
26
+
27
+
28
+ def predict(pdb_code, pdb_file, helix, sheet, loop):
29
+ path_to_pdb = get_pdb(pdb_code=pdb_code, filepath=pdb_file)
30
+
31
+ pdb = open(path_to_pdb, "r").read()
32
+ offset = get_offset(pdb)
33
+
34
+ coord = torch.tensor(pydssp.read_pdbtext(pdb))
35
+ secondary_struct = pydssp.assign(coord)
36
+
37
+ view = py3Dmol.view(width=400, height=400)
38
+ view.addModel(pdb, "pdb")
39
+ colormap = {"H": helix, "E": sheet, "-": loop}
40
+ colors = {i + offset: colormap[resi] for i, resi in enumerate(secondary_struct)}
41
+
42
+ view.setStyle({"cartoon": {"colorscheme": {"prop": "resi", "map": colors}}})
43
+
44
+ view.zoomTo()
45
+
46
+ output = view._make_html().replace("'", '"')
47
+
48
+ x = f"""<!DOCTYPE html><html> {output} </html>""" # do not use ' in this input
49
+ return f"""<iframe style="width: 100%; height:420px" name="result" allow="midi; geolocation; microphone; camera;
50
+ display-capture; encrypted-media;" sandbox="allow-modals allow-forms
51
+ allow-scripts allow-same-origin allow-popups
52
+ allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
53
+ allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
54
+
55
+
56
+ with gr.Blocks() as demo:
57
+ gr.Markdown("# Secondary structure using pyDSSP")
58
+ pdb_code = gr.Textbox(label="PDB Code")
59
+ pdb_file = gr.File(label="PDB File Upload")
60
+ with gr.Row():
61
+ helix = gr.ColorPicker(label="helix")
62
+ sheet = gr.ColorPicker(label="sheet")
63
+ loop = gr.ColorPicker(label="loop")
64
+ btn = gr.Button(label="Run")
65
+ html = gr.HTML()
66
+ btn.click(
67
+ fn=predict, inputs=[pdb_code, pdb_file, helix, sheet, loop], outputs=[html]
68
+ )
69
+ gr.Examples(
70
+ [["1QYS", "#ff0000", "#00ff00", "#0000ff"]],
71
+ inputs=[pdb_code, helix, sheet, loop],
72
+ fn=predict,
73
+ )
74
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ gradio
3
+ py3Dmol
4
+ git+https://github.com/ShintaroMinami/PyDSSP.git