2
2
3
3
import os
4
4
import tempfile
5
+ from dataclasses import dataclass
6
+ from enum import Enum
5
7
6
8
import pandas as pd
7
9
@@ -37,9 +39,6 @@ def visualize_sbml(sbml_path: Path, delete_session: bool = False) -> Optional[in
37
39
38
40
Returns dictionary with "networks" and "views".
39
41
"""
40
- if sbml_path .suffix != ".xml" :
41
- console .error (f"SBML path { sbml_path } does not have .xml extension" )
42
-
43
42
try :
44
43
console .print (p4c .cytoscape_version_info ())
45
44
@@ -76,7 +75,7 @@ def read_layout_xml(sbml_path: Path, xml_path: Path) -> pd.DataFrame:
76
75
df .set_index ("id" , inplace = True )
77
76
return df
78
77
79
- def apply_layout (network , layout : pd .DataFrame ) -> None :
78
+ def apply_layout (layout : pd .DataFrame , network = None ) -> None :
80
79
"""Apply layout information from Cytoscape to SBML networks."""
81
80
82
81
# get SUIDs, sbml_id from node table;
@@ -95,14 +94,55 @@ def apply_layout(network, layout: pd.DataFrame) -> None:
95
94
p4c .set_node_position_bypass (suids , new_x_locations = x_values , new_y_locations = y_values , network = network )
96
95
# p4c.set_node_property_bypass(suids, new_values=x_values, visual_property='NODE_X_LOCATION', network=network)
97
96
# p4c.set_node_property_bypass(suids, new_values=y_values, visual_property='NODE_Y_LOCATION', network=network)
98
- p4c .set_current_view (network = network )
97
+ # positions = p4c.get_node_position()
98
+ # console.print(f"{positions}")
99
+
100
+ # fit content
101
+ p4c .fit_content ()
99
102
100
103
# remove bypass
101
104
# p4c.clear_node_property_bypass(suids, visual_property='NODE_X_LOCATION', network=network)
102
105
# p4c.clear_node_property_bypass(suids, visual_property='NODE_Y_LOCATION', network=network)
103
-
104
- # fit content
105
- p4c .fit_content ()
106
+ # positions = p4c.get_node_position()
107
+ # console.print(f"{positions}")
108
+
109
+
110
+ class AnnotationShapeType (str , Enum ):
111
+ RECTANGLE = "RECTANGLE"
112
+ ROUND_RECTANGLE = "ROUND_RECTANGLE"
113
+
114
+ @dataclass
115
+ class AnnotationShape :
116
+ type : AnnotationShapeType
117
+ x_pos : int
118
+ y_pos : int
119
+ height : int
120
+ width : int
121
+ fill_color : str = "#000000"
122
+ opacity : int = 100
123
+ border_thickness : int = 1
124
+ canvas : str = "background"
125
+ z_order : int = 0
126
+
127
+ def add_annotations (annotations , network = None ):
128
+ """Add annotations to the network."""
129
+
130
+ for a in annotations :
131
+ if isinstance (a , AnnotationShape ):
132
+
133
+ p4c .add_annotation_shape (
134
+ network = network ,
135
+ type = a .type ,
136
+ x_pos = a .x_pos ,
137
+ y_pos = a .y_pos ,
138
+ height = a .height ,
139
+ width = a .width ,
140
+ fill_color = a .fill_color ,
141
+ opacity = a .opacity ,
142
+ border_thickness = a .border_thickness ,
143
+ canvas = a .canvas ,
144
+ z_order = a .z_order ,
145
+ )
106
146
107
147
108
148
0 commit comments