Skip to content

Commit

Permalink
working on automation
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaskoenig committed Oct 28, 2024
1 parent b3e0ca1 commit 126b0f6
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/sbmlutils/cytoscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ def visualize_sbml(sbml_path: Path, delete_session: bool = False) -> Optional[in
p4c.session.close_session(save_before_closing=False)

networks_views = p4c.networks.import_network_from_file(str(sbml_path))
console.print(f"{networks_views}")
# console.print(f"{networks_views}")
network = networks_views["networks"][1]
p4c.set_current_view(network=network) # set the base network
return network

return networks_views

except RequestException:
logger.error(
"Could not connect to a running Cytoscape instance. "
Expand All @@ -78,14 +76,13 @@ def apply_layout(layout: pd.DataFrame, network=None) -> None:

# get SUIDs, sbml_id from node table;
df_nodes = p4c.get_table_columns(table="node", columns=["sbml id"], network=network)
console.print(df_nodes)
sid2suid = {row["sbml id"]: suid for suid, row in df_nodes.iterrows()}
console.print(sid2suid)

# FIXME: necessary to check that all sids exist
suids = [sid2suid[sid] for sid in layout.index.values]
x_values = layout["x"].values.tolist()
y_values = layout["y"].values.tolist()
# z_values = layout["z"].values.tolist()

# set positions
# see: https://github.com/cytoscape/py4cytoscape/issues/144
Expand Down Expand Up @@ -213,6 +210,24 @@ def add_annotations(annotations, network=None):
)


def export_image(image_path: Path, format="PNG", fit_content: bool = False, hide_labels: bool = True):
"""Helper for exporting cytoscape images.
format (str): Type of image to export, e.g., PNG (default), JPEG, PDF, SVG, PS (PostScript).
"""
if fit_content:
p4c.fit_content()

p4c.export_image(
filename=str(image_path),
type=format,
zoom=400.0,
overwrite_file=True,
all_graphics_details=True,
hide_labels=False,
)


if __name__ == "__main__":
pass
# # visual style
Expand Down

0 comments on commit 126b0f6

Please sign in to comment.