Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,7 +58,7 @@ def inject_bfactors_and_save(pdb_file, scores_list, component_indices):
|
|
| 58 |
|
| 59 |
return output_paths
|
| 60 |
|
| 61 |
-
#
|
| 62 |
def render_structure(pdb_path):
|
| 63 |
with open(pdb_path, 'r') as f:
|
| 64 |
pdb_data = f.read()
|
|
@@ -66,16 +66,25 @@ def render_structure(pdb_path):
|
|
| 66 |
view.addModel(pdb_data, 'pdb')
|
| 67 |
view.setStyle({'cartoon': {'color': 'bfactor'}})
|
| 68 |
view.zoomTo()
|
| 69 |
-
|
| 70 |
-
#
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
+ viewer_html
|
| 75 |
)
|
| 76 |
-
return
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
# Gradio UI
|
| 81 |
demo = gr.Interface(
|
|
@@ -87,9 +96,10 @@ demo = gr.Interface(
|
|
| 87 |
],
|
| 88 |
outputs=[
|
| 89 |
gr.File(label="Download PDBs with PCA Projections", file_types=[".pdb"], file_count="multiple"),
|
| 90 |
-
gr.HTML(label="Interactive Structure Viewer (first
|
| 91 |
],
|
| 92 |
title="ESM-1b PCA Component Projection with Interactive 3D Structure"
|
| 93 |
)
|
| 94 |
|
| 95 |
demo.launch()
|
|
|
|
|
|
| 58 |
|
| 59 |
return output_paths
|
| 60 |
|
| 61 |
+
# Render structure with py3Dmol and inject script tag manually
|
| 62 |
def render_structure(pdb_path):
|
| 63 |
with open(pdb_path, 'r') as f:
|
| 64 |
pdb_data = f.read()
|
|
|
|
| 66 |
view.addModel(pdb_data, 'pdb')
|
| 67 |
view.setStyle({'cartoon': {'color': 'bfactor'}})
|
| 68 |
view.zoomTo()
|
| 69 |
+
|
| 70 |
+
# Combine viewer HTML with explicit 3Dmol.js script
|
| 71 |
+
html = (
|
| 72 |
+
'<script src="https://3Dmol.org/build/3Dmol.js"></script>'
|
| 73 |
+
+ view._make_html()
|
|
|
|
| 74 |
)
|
| 75 |
+
return html
|
| 76 |
|
| 77 |
+
# Gradio interface logic
|
| 78 |
+
def process(seq, pdb_file, component_string):
|
| 79 |
+
try:
|
| 80 |
+
components = [int(c.strip()) for c in component_string.split(",") if c.strip().isdigit()]
|
| 81 |
+
except:
|
| 82 |
+
return [], "<p style='color:red'>Error: Invalid component list. Use comma-separated integers.</p>"
|
| 83 |
|
| 84 |
+
scores_list = compute_scaled_pca_scores(seq, components)
|
| 85 |
+
pdb_paths = inject_bfactors_and_save(pdb_file, scores_list, components)
|
| 86 |
+
html_view = render_structure(pdb_paths[0]) if pdb_paths else ""
|
| 87 |
+
return pdb_paths, html_view
|
| 88 |
|
| 89 |
# Gradio UI
|
| 90 |
demo = gr.Interface(
|
|
|
|
| 96 |
],
|
| 97 |
outputs=[
|
| 98 |
gr.File(label="Download PDBs with PCA Projections", file_types=[".pdb"], file_count="multiple"),
|
| 99 |
+
gr.HTML(label="Interactive Structure Viewer (first PCA component only)")
|
| 100 |
],
|
| 101 |
title="ESM-1b PCA Component Projection with Interactive 3D Structure"
|
| 102 |
)
|
| 103 |
|
| 104 |
demo.launch()
|
| 105 |
+
|