Skip to content

Commit 2f74f51

Browse files
working on cytoscape interface
1 parent b6eed1f commit 2f74f51

File tree

1 file changed

+48
-8
lines changed

1 file changed

+48
-8
lines changed

src/sbmlutils/cytoscape.py

+48-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import os
44
import tempfile
5+
from dataclasses import dataclass
6+
from enum import Enum
57

68
import pandas as pd
79

@@ -37,9 +39,6 @@ def visualize_sbml(sbml_path: Path, delete_session: bool = False) -> Optional[in
3739
3840
Returns dictionary with "networks" and "views".
3941
"""
40-
if sbml_path.suffix != ".xml":
41-
console.error(f"SBML path {sbml_path} does not have .xml extension")
42-
4342
try:
4443
console.print(p4c.cytoscape_version_info())
4544

@@ -76,7 +75,7 @@ def read_layout_xml(sbml_path: Path, xml_path: Path) -> pd.DataFrame:
7675
df.set_index("id", inplace=True)
7776
return df
7877

79-
def apply_layout(network, layout: pd.DataFrame) -> None:
78+
def apply_layout(layout: pd.DataFrame, network=None) -> None:
8079
"""Apply layout information from Cytoscape to SBML networks."""
8180

8281
# get SUIDs, sbml_id from node table;
@@ -95,14 +94,55 @@ def apply_layout(network, layout: pd.DataFrame) -> None:
9594
p4c.set_node_position_bypass(suids, new_x_locations=x_values, new_y_locations=y_values, network=network)
9695
# p4c.set_node_property_bypass(suids, new_values=x_values, visual_property='NODE_X_LOCATION', network=network)
9796
# 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()
99102

100103
# remove bypass
101104
# p4c.clear_node_property_bypass(suids, visual_property='NODE_X_LOCATION', network=network)
102105
# 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+
)
106146

107147

108148

0 commit comments

Comments
 (0)