CX2 to HCX conversion
The CX2 to HCX conversion process enhances a CX2 hierarchical network by adding HCX-specific annotations. The HCX format is a specialized version of CX2 that enables hierarchical visualization in Cytoscape, ensuring that relationships and interactome information are properly structured.
Why Convert to HCX?
Enables hierarchical network visualization in Cytoscape.
Adds interactome annotations to define relationships.
Supports integration with NDEx, allowing retrieval of interactome data.
Example 1: Converting a CX2 Hierarchical Network to HCX
To convert a CX2 hierarchical network into an HCX format, use the convert_hierarchical_network_to_hcx function:
from cellmaps_utils.hcx_utils import convert_hierarchical_network_to_hcx
hierarchy_path = "path/to/hierarchy.cx2"
interactome_url = "https://www.ndexbio.org/network/uuid"
hcx_network = convert_hierarchical_network_to_hcx(
hierarchy=hierarchy_path,
interactome_url=interactome_url
)
hcx_network.write_as_raw_cx2("path/to/output/hierarchy_hcx.cx2")
Expected Output: hierarchy_hcx.cx2 – The HCX hierarchical network, enriched with interactome annotations.
Example 2: Converting a CX2 Hierarchy with a Local Interactome
If you have a local interactome file instead of an NDEx link, you can still convert a CX2 hierarchy to HCX:
from ndex2.cx2 import RawCX2NetworkFactory
from cellmaps_utils.hcx_utils import add_hcx_network_annotations, add_hcx_members_annotation, add_isroot_node_attribute, get_root_nodes
hierarchy_path = "path/to/hierarchy.cx2"
interactome_path = "path/to/interactome.cx2"
# Load hierarchy network and interactome
factory = RawCX2NetworkFactory()
hierarchy = factory.get_cx2network(hierarchy_path)
interactome = factory.get_cx2network(interactome_path)
# Add HCX annotations
hierarchy = add_hcx_network_annotations(hierarchy, interactome=interactome, outdir='path/to/output/')
# Add HCX::members attribute to node attributes
add_hcx_members_annotation(hierarchy, interactome)
# Add isRoot attribute to node attributes
add_isroot_node_attribute(hierarchy, get_root_nodes(hierarchy))
# Save HCX file
hierarchy.write_as_raw_cx2("path/to/output/hierarchy.cx2")
Expected Output (Hierarchy and interactome will be saved in the same directory path/to/output/):
hierarchy_hcx.cx2– HCX hierarchical network with interactome annotations.hierarchy_parent.cx2