Spaces:
Running
Running
roni
commited on
Commit
·
3380f3c
1
Parent(s):
1d11011
adding the organism to the label
Browse files- app.py +5 -5
- protein_viz.py +9 -7
app.py
CHANGED
@@ -24,7 +24,7 @@ def limit_n_results(n):
|
|
24 |
def update_dropdown_menu(search_res):
|
25 |
choices = []
|
26 |
for row in search_res:
|
27 |
-
choice = "
|
28 |
choices.append(choice)
|
29 |
|
30 |
return gr.Dropdown.update(
|
@@ -47,15 +47,15 @@ def format_search_result(raw_result):
|
|
47 |
prot = raw_result["pdb_name"]
|
48 |
chain = raw_result["chain_id"]
|
49 |
value = raw_result["score"]
|
50 |
-
gene_name = get_gene_name(pdb_id=prot, chain_id=chain)
|
51 |
-
key = f"PDB: {prot}
|
52 |
if gene_name != "Unknown":
|
53 |
-
key += f" | Gene: {gene_name}"
|
54 |
return key, value
|
55 |
|
56 |
|
57 |
def switch_viz(new_choice):
|
58 |
-
choice_parts = new_choice.split("
|
59 |
pdb_id, chain = choice_parts[0], choice_parts[1]
|
60 |
title_update = gr.Markdown.update(visible=True)
|
61 |
protein_name = get_protein_name(pdb_id)
|
|
|
24 |
def update_dropdown_menu(search_res):
|
25 |
choices = []
|
26 |
for row in search_res:
|
27 |
+
choice = ".".join([row["pdb_name"], row["chain_id"]])
|
28 |
choices.append(choice)
|
29 |
|
30 |
return gr.Dropdown.update(
|
|
|
47 |
prot = raw_result["pdb_name"]
|
48 |
chain = raw_result["chain_id"]
|
49 |
value = raw_result["score"]
|
50 |
+
gene_name, species = get_gene_name(pdb_id=prot, chain_id=chain)
|
51 |
+
key = f"PDB: {prot}.{chain}"
|
52 |
if gene_name != "Unknown":
|
53 |
+
key += f" | Gene: {gene_name} | Organism: {species}"
|
54 |
return key, value
|
55 |
|
56 |
|
57 |
def switch_viz(new_choice):
|
58 |
+
choice_parts = new_choice.split(".")
|
59 |
pdb_id, chain = choice_parts[0], choice_parts[1]
|
60 |
title_update = gr.Markdown.update(visible=True)
|
61 |
protein_name = get_protein_name(pdb_id)
|
protein_viz.py
CHANGED
@@ -32,8 +32,10 @@ def render_html(pdb_id, chain):
|
|
32 |
|
33 |
def get_gene_name(pdb_id, chain_id):
|
34 |
entity_id = get_polymer_entity_id(chain_id, pdb_id)
|
35 |
-
gene_name = get_gene_name_from_polymer_entity(
|
36 |
-
|
|
|
|
|
37 |
|
38 |
|
39 |
def get_polymer_entity_id(chain_id, pdb_id):
|
@@ -59,13 +61,13 @@ def get_gene_name_from_polymer_entity(pdb_id, entity_id):
|
|
59 |
if response.ok:
|
60 |
res_data = response.json()
|
61 |
try:
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
return gene_name
|
66 |
except KeyError:
|
67 |
pass
|
68 |
-
return "Unknown"
|
69 |
|
70 |
|
71 |
def get_protein_name(pdb_id: str):
|
|
|
32 |
|
33 |
def get_gene_name(pdb_id, chain_id):
|
34 |
entity_id = get_polymer_entity_id(chain_id, pdb_id)
|
35 |
+
gene_name, species = get_gene_name_from_polymer_entity(
|
36 |
+
pdb_id=pdb_id, entity_id=entity_id
|
37 |
+
)
|
38 |
+
return gene_name, species
|
39 |
|
40 |
|
41 |
def get_polymer_entity_id(chain_id, pdb_id):
|
|
|
61 |
if response.ok:
|
62 |
res_data = response.json()
|
63 |
try:
|
64 |
+
source_organism = res_data["rcsb_entity_source_organism"][0]
|
65 |
+
gene_name = source_organism["rcsb_gene_name"][0]["value"]
|
66 |
+
species = source_organism["ncbi_scientific_name"]
|
67 |
+
return gene_name, species
|
68 |
except KeyError:
|
69 |
pass
|
70 |
+
return "Unknown", "Unknown"
|
71 |
|
72 |
|
73 |
def get_protein_name(pdb_id: str):
|