Skip to content

CX2

Read and write the Cytoscape Exchange format, version 2 (CX2) of Cytoscape. The structures that CX2 has no place for, such as hyperedges, slices and layers, go into a manifest inside the network attributes, so from_cx2 can rebuild them. To show a graph as an interactive Cytoscape.js network, use show_cytoscape.

annnet.io.cx2.from_cx2

from_cx2(cx2_data, *, hyperedges='manifest')

Fully robust CX2 - AnnNet importer.

Supports: - manifest reconstruction (full fidelity) - reified hyperedges - expanded hyperedges - Cytoscape-edited files - sparse attribute tables - arbitrary attribute modifications

annnet.io.cx2.to_cx2

to_cx2(
    G,
    path=None,
    *,
    export_name="annnet export",
    layer=None,
    include_inter=False,
    include_coupling=False,
    hyperedges="skip",
    coefficients="error",
    sidecar=True
)

Convert an AnnNet graph to CX2 compliant JSON format.

The output is a list of aspect dictionaries (CX2 format). Complex AnnNet features (hyperedges, slices, multilayer structure) are serialized into a JSON string stored in networkAttributes under 'AnnNet_Manifest'.

Parameters:

Name Type Description Default
G AnnNet

The graph to export.

required
path str | PathLike

If given, the CX2 document is written to this path as JSON. The function still returns the CX2 dict structure for in-memory use.

None
export_name str

Name of the exported network (stored in networkAttributes).

"annnet export"
layer tuple of str

Elementary layer tuple specifying which layer to export. If provided, only the subgraph for that layer is exported. Useful for multilayer graphs where flattening creates unreadable visualizations in Cytoscape (e.g., coupling edges become self-loops). If None, exports the entire graph. Example: layer=("social", "2020") for a 2-aspect multilayer network.

None
hyperedges ('skip', 'expand', 'reify')

How to handle hyperedges in the export: - "skip": Omit hyperedges entirely - "expand": Convert to cartesian product of pairwise edges - "reify": Create explicit hyperedge nodes with membership edges

"skip"

Returns:

Type Description
list of dict

CX2-compliant JSON structure (list of aspect dictionaries).

Notes
  • Cytoscape does not natively support multilayer networks. When exporting multilayer graphs without specifying a layer, coupling edges may appear as self-loops and the visualization becomes cluttered.
  • Use the layer parameter to export individual elementary layers for clean, interpretable Cytoscape visualizations.
  • The full multilayer structure is preserved in the manifest regardless of the layer parameter, enabling lossless round-trip via from_cx2().