Spaces:
Running
Running
Erva Ulusoy
commited on
Commit
·
5cb58d3
1
Parent(s):
31935f9
updated embedded node information
Browse files- visualize_kg.py +21 -6
visualize_kg.py
CHANGED
@@ -33,6 +33,15 @@ EDGE_LABEL_TRANSLATION = {
|
|
33 |
('protein_function', 'GO_term_C'): 'localizes to',
|
34 |
}
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
GO_CATEGORY_MAPPING = {
|
37 |
'Biological Process': 'GO_term_P',
|
38 |
'Molecular Function': 'GO_term_F',
|
@@ -188,7 +197,7 @@ def visualize_protein_subgraph(data, protein_id, prediction_df, limit=10):
|
|
188 |
|
189 |
# Add the main protein node
|
190 |
net.add_node(protein_id,
|
191 |
-
label=f"
|
192 |
color={'background': 'white', 'border': '#c1121f'},
|
193 |
borderWidth=4,
|
194 |
shape="dot",
|
@@ -218,10 +227,10 @@ def visualize_protein_subgraph(data, protein_id, prediction_df, limit=10):
|
|
218 |
# Add source node if not present
|
219 |
if source_str not in added_nodes:
|
220 |
net.add_node(source_str,
|
221 |
-
label=
|
222 |
shape="dot",
|
223 |
font={'color': '#000000', 'size': 12},
|
224 |
-
title=f"{
|
225 |
group=source_type,
|
226 |
size=15,
|
227 |
mass=1.5)
|
@@ -230,10 +239,10 @@ def visualize_protein_subgraph(data, protein_id, prediction_df, limit=10):
|
|
230 |
# Add target node if not present
|
231 |
if target_str not in added_nodes:
|
232 |
net.add_node(target_str,
|
233 |
-
label=
|
234 |
shape="dot",
|
235 |
font={'color': '#000000', 'size': 12},
|
236 |
-
title=f"{
|
237 |
group=target_type,
|
238 |
size=15,
|
239 |
mass=1.5)
|
@@ -328,10 +337,16 @@ def visualize_protein_subgraph(data, protein_id, prediction_df, limit=10):
|
|
328 |
|
329 |
# Node types in 2 columns
|
330 |
for node_type, color in NODE_TYPE_COLORS.items():
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
legend_html += f"""
|
332 |
<div class="legend-item">
|
333 |
<div class="node-indicator" style="background-color: {color};"></div>
|
334 |
-
<span class="legend-label">{
|
335 |
</div>"""
|
336 |
|
337 |
# Edge types in 1 column
|
|
|
33 |
('protein_function', 'GO_term_C'): 'localizes to',
|
34 |
}
|
35 |
|
36 |
+
NODE_LABEL_TRANSLATION = {
|
37 |
+
'HPO': 'Phenotype',
|
38 |
+
'GO_term_P': 'Biological Process',
|
39 |
+
'GO_term_F': 'Molecular Function',
|
40 |
+
'GO_term_C': 'Cellular Component',
|
41 |
+
'kegg_Pathway': 'Pathway',
|
42 |
+
'EC_number': 'EC Number',
|
43 |
+
}
|
44 |
+
|
45 |
GO_CATEGORY_MAPPING = {
|
46 |
'Biological Process': 'GO_term_P',
|
47 |
'Molecular Function': 'GO_term_F',
|
|
|
197 |
|
198 |
# Add the main protein node
|
199 |
net.add_node(protein_id,
|
200 |
+
label=f"{protein_id} (Protein)",
|
201 |
color={'background': 'white', 'border': '#c1121f'},
|
202 |
borderWidth=4,
|
203 |
shape="dot",
|
|
|
227 |
# Add source node if not present
|
228 |
if source_str not in added_nodes:
|
229 |
net.add_node(source_str,
|
230 |
+
label= source_str,
|
231 |
shape="dot",
|
232 |
font={'color': '#000000', 'size': 12},
|
233 |
+
title=f"{source_str} ({NODE_LABEL_TRANSLATION[source_type] if source_type in NODE_LABEL_TRANSLATION else source_type})",
|
234 |
group=source_type,
|
235 |
size=15,
|
236 |
mass=1.5)
|
|
|
239 |
# Add target node if not present
|
240 |
if target_str not in added_nodes:
|
241 |
net.add_node(target_str,
|
242 |
+
label= target_str,
|
243 |
shape="dot",
|
244 |
font={'color': '#000000', 'size': 12},
|
245 |
+
title=f"{target_str} ({NODE_LABEL_TRANSLATION[target_type] if target_type in NODE_LABEL_TRANSLATION else target_type})",
|
246 |
group=target_type,
|
247 |
size=15,
|
248 |
mass=1.5)
|
|
|
337 |
|
338 |
# Node types in 2 columns
|
339 |
for node_type, color in NODE_TYPE_COLORS.items():
|
340 |
+
if node_type == 'kegg_Pathway':
|
341 |
+
continue
|
342 |
+
if node_type in NODE_LABEL_TRANSLATION:
|
343 |
+
node_label = NODE_LABEL_TRANSLATION[node_type]
|
344 |
+
else:
|
345 |
+
node_label = node_type
|
346 |
legend_html += f"""
|
347 |
<div class="legend-item">
|
348 |
<div class="node-indicator" style="background-color: {color};"></div>
|
349 |
+
<span class="legend-label">{node_label}</span>
|
350 |
</div>"""
|
351 |
|
352 |
# Edge types in 1 column
|