Spaces:
Sleeping
Sleeping
Erva Ulusoy
commited on
Commit
·
67e78f6
1
Parent(s):
51641fb
updated edge coloring, modified edge labels to more clear ones
Browse files- visualize_kg.py +27 -4
visualize_kg.py
CHANGED
|
@@ -16,6 +16,23 @@ NODE_TYPE_COLORS = {
|
|
| 16 |
'Protein': '#3aa6a4'
|
| 17 |
}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
GO_CATEGORY_MAPPING = {
|
| 20 |
'Biological Process': 'GO_term_P',
|
| 21 |
'Molecular Function': 'GO_term_F',
|
|
@@ -186,7 +203,12 @@ def visualize_protein_subgraph(data, protein_id, prediction_df, limit=10):
|
|
| 186 |
# Add edges and target nodes
|
| 187 |
for edge_type, edges in visualized_edges.items():
|
| 188 |
source_type, relation_type, target_type = edge_type
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
for edge_info in edges:
|
| 191 |
edge, probability, is_ground_truth = edge_info
|
| 192 |
source, target = edge[0], edge[1]
|
|
@@ -222,10 +244,11 @@ def visualize_protein_subgraph(data, protein_id, prediction_df, limit=10):
|
|
| 222 |
if probability is not None:
|
| 223 |
if probability == 'no_pred':
|
| 224 |
edge_color = '#219ebc'
|
| 225 |
-
edge_label += '(P=Not generated)'
|
| 226 |
else:
|
| 227 |
-
edge_label += f"(P={probability:.2f})"
|
| 228 |
-
edge_color = '#
|
|
|
|
| 229 |
net.add_edge(source_str, target_str,
|
| 230 |
label=edge_label,
|
| 231 |
font={'size': 0},
|
|
|
|
| 16 |
'Protein': '#3aa6a4'
|
| 17 |
}
|
| 18 |
|
| 19 |
+
EDGE_LABEL_TRANSLATION = {
|
| 20 |
+
'Orthology': 'is ortholog to',
|
| 21 |
+
'Pathway': 'takes part in',
|
| 22 |
+
'kegg_path_prot': 'takes part in',
|
| 23 |
+
'protein_domain': 'has',
|
| 24 |
+
'PPI': 'interacts with',
|
| 25 |
+
'HPO': 'is associated with',
|
| 26 |
+
'kegg_dis_prot': 'is related to',
|
| 27 |
+
'Disease': 'is related to',
|
| 28 |
+
'Drug': 'targets',
|
| 29 |
+
'protein_ec': 'catalyzes',
|
| 30 |
+
'Chembl': 'targets',
|
| 31 |
+
('protein_function', 'GO_term_F'): 'enables',
|
| 32 |
+
('protein_function', 'GO_term_P'): 'is involved in',
|
| 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',
|
|
|
|
| 203 |
# Add edges and target nodes
|
| 204 |
for edge_type, edges in visualized_edges.items():
|
| 205 |
source_type, relation_type, target_type = edge_type
|
| 206 |
+
|
| 207 |
+
if relation_type == 'protein_function':
|
| 208 |
+
relation_type = EDGE_LABEL_TRANSLATION[(relation_type, target_type)]
|
| 209 |
+
else:
|
| 210 |
+
relation_type = EDGE_LABEL_TRANSLATION[relation_type]
|
| 211 |
+
|
| 212 |
for edge_info in edges:
|
| 213 |
edge, probability, is_ground_truth = edge_info
|
| 214 |
source, target = edge[0], edge[1]
|
|
|
|
| 244 |
if probability is not None:
|
| 245 |
if probability == 'no_pred':
|
| 246 |
edge_color = '#219ebc'
|
| 247 |
+
edge_label += ' (P=Not generated)'
|
| 248 |
else:
|
| 249 |
+
edge_label += f" (P={probability:.2f})"
|
| 250 |
+
edge_color = '#8338ec' if is_ground_truth else '#c1121f'
|
| 251 |
+
# if validated prediction purple, if non-validated prediction red, if no prediction (directly from database) blue
|
| 252 |
net.add_edge(source_str, target_str,
|
| 253 |
label=edge_label,
|
| 254 |
font={'size': 0},
|