roni commited on
Commit
1d25e2a
1 Parent(s): c3ff85a

showing pdb title on visualization

Browse files
Files changed (3) hide show
  1. app.py +11 -3
  2. protein_viz.py +24 -0
  3. requirements.txt +1 -0
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
 
3
  from get_index import get_engine
4
- from protein_viz import render_html
5
 
6
  index_repo = "ronig/siamese_protein_index"
7
  model_repo = "ronig/protein_search_engine"
@@ -47,7 +47,12 @@ def format_search_results(raw_search_results):
47
  def switch_viz(new_choice):
48
  pdb_id, chain = new_choice.split(',')
49
  title_update = gr.Markdown.update(visible=True)
50
- return render_html(pdb_id=pdb_id, chain=chain), title_update
 
 
 
 
 
51
 
52
 
53
  with gr.Blocks() as demo:
@@ -72,6 +77,7 @@ with gr.Blocks() as demo:
72
  choices=[], multiselect=False, visible=False,
73
  label="Visualized Search Result"
74
  )
 
75
  protein_viz = gr.HTML(
76
  value=render_html(pdb_id=None, chain=None),
77
  label="Protein Visualization"
@@ -87,7 +93,9 @@ with gr.Blocks() as demo:
87
  outputs=[search_results, results_selector]
88
  )
89
  results_selector.change(
90
- switch_viz, inputs=results_selector, outputs=[protein_viz, viz_header]
 
 
91
  )
92
 
93
  demo.launch()
 
1
  import gradio as gr
2
 
3
  from get_index import get_engine
4
+ from protein_viz import get_protein_name, render_html
5
 
6
  index_repo = "ronig/siamese_protein_index"
7
  model_repo = "ronig/protein_search_engine"
 
47
  def switch_viz(new_choice):
48
  pdb_id, chain = new_choice.split(',')
49
  title_update = gr.Markdown.update(visible=True)
50
+ protein_name = get_protein_name(pdb_id)
51
+ description_update = gr.Markdown.update(
52
+ value=f"""**PDB Title**: {protein_name}""",
53
+ visible=True
54
+ )
55
+ return render_html(pdb_id=pdb_id, chain=chain), title_update, description_update
56
 
57
 
58
  with gr.Blocks() as demo:
 
77
  choices=[], multiselect=False, visible=False,
78
  label="Visualized Search Result"
79
  )
80
+ viz_body = gr.Markdown("", visible=False)
81
  protein_viz = gr.HTML(
82
  value=render_html(pdb_id=None, chain=None),
83
  label="Protein Visualization"
 
93
  outputs=[search_results, results_selector]
94
  )
95
  results_selector.change(
96
+ switch_viz,
97
+ inputs=results_selector,
98
+ outputs=[protein_viz, viz_header, viz_body]
99
  )
100
 
101
  demo.launch()
protein_viz.py CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  def render_html(pdb_id, chain):
2
  if pdb_id is None or chain is None:
3
  return ""
@@ -25,3 +31,21 @@ def render_html(pdb_id, chain):
25
  frameborder="0" srcdoc='{html}'></iframe>
26
  """
27
  return iframe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+
3
+ import mygene
4
+ import requests
5
+
6
+
7
  def render_html(pdb_id, chain):
8
  if pdb_id is None or chain is None:
9
  return ""
 
31
  frameborder="0" srcdoc='{html}'></iframe>
32
  """
33
  return iframe
34
+
35
+
36
+ def get_gene_names(genes: List[str]):
37
+ mg = mygene.MyGeneInfo()
38
+ ginfo = mg.querymany(genes, scopes='ensembl.gene')
39
+ gene_names = [gene['name'] for gene in ginfo]
40
+ return gene_names
41
+
42
+
43
+ def get_protein_name(pdb_id: str):
44
+ url = f"https://data.rcsb.org/rest/v1/core/entry/{pdb_id}"
45
+ response = requests.get(url, timeout=1)
46
+ if response.ok:
47
+ data = response.json()
48
+ protein_name = data['struct']['title']
49
+ else:
50
+ protein_name = 'Unknown'
51
+ return protein_name
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  torch
2
  transformers
3
  annoy
 
 
1
  torch
2
  transformers
3
  annoy
4
+ mygene