process_mapping.process_nodes_and_edges_for_cytoscape
process_mapping.process_nodes_and_edges_for_cytoscape(
nodes,
edges,
node_label='activity',
time_unit='minutes',
time_metric='mean',
show_transition_probabilities=True,
show_edge_counts=True,
show_metric=True,
show_node_counts=True,
)Convert DFG node and edge tables into Cytoscape-compatible elements.
Note that this is called automatically by all cytoscape functions in vidigi.process_mapping. However, it is made available for use in case you wish to develop your own custom cytoscape-based outputs.
This function transforms node and edge tables (e.g. as produced by :func:vidigi.process_mapping.discover_dfg) into lists of dictionaries formatted for use with Cytoscape.js or Cytoscape-based Python wrappers. The output can be passed directly to visualization components such as Dash Cytoscape or similar graph rendering frameworks.
Node and edge labels are constructed dynamically based on the provided display flags, allowing flexible control over which statistics are shown in the visualization.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| nodes | pandas.DataFrame | Node table describing activities. Must contain at least the following columns: - node_label (default "activity") : str Activity label used as the node identifier. - count : int Number of occurrences of the activity. |
required |
| edges | pandas.DataFrame | Edge table describing directly-follows relations. Must contain at least the following columns: - source : str Source activity. - target : str Target activity. - frequency : int Transition frequency. - probability : float Conditional transition probability. - <time_metric>_time : float Time statistic used for edge annotation (e.g. mean_time). |
required |
| node_label | str | Name of the column in nodes used as the node identifier and display label. |
"activity" |
| time_unit | str | Time unit label displayed alongside transition time statistics. This does not rescale values and should match the unit used during DFG discovery. | "minutes" |
| time_metric | (mean, median, min, max, standard_deviation) | Time statistic to display on edges. This value determines which <time_metric>_time column is used from edges. |
"mean" |
| show_transition_probabilities | bool | If True, include transition probabilities in edge labels. | True |
| show_edge_counts | bool | If True, include transition frequencies in edge labels. | True |
| show_metric | bool | If True, include the selected time statistic in edge labels. | True |
| show_node_counts | bool | If True, include activity occurrence counts in node labels. | True |
Returns
| Name | Type | Description |
|---|---|---|
| cy_nodes | list of dict | List of node elements formatted for Cytoscape. Each element contains a data dictionary with id and label fields, and a classes entry enabling multiline labels. |
| cy_edges | list of dict | List of edge elements formatted for Cytoscape. Each element contains a data dictionary with source, target, label, and weight fields. |
Notes
- All node and edge identifiers are cast to strings to ensure consistent matching within Cytoscape.
- Edge weights are set to transition probabilities, which can be used for styling or layout algorithms.
- This function performs no validation of column presence or value ranges and assumes the input tables are consistent and complete.
Examples
>>> cy_nodes, cy_edges = process_nodes_and_edges_for_cytoscape(
... nodes,
... edges,
... show_metric=False,
... )
>>> cy_nodes[0]
>>> cy_edges[0]