SIF
SIF import and export helpers from annnet.io.SIF_io.
annnet.io.SIF_io
Classes
Functions
to_sif(graph, path=None, *, relation_attr='relation', default_relation='interacts_with', write_nodes=True, nodes_path=None, lossless=False, manifest_path=None)
Export graph to SIF format.
Standard mode (lossless=False): - Writes only binary edges to SIF file - Hyperedges, weights, attrs, IDs are lost - Returns None
Lossless mode (lossless=True): - Writes binary edges to SIF file - Returns (None, manifest) where manifest contains all lost info - Manifest can be saved separately and used with from_sif()
Args: path: Output SIF file path (if None, only manifest is returned in lossless mode) relation_attr: Edge attribute key for relation type default_relation: Default relation if attr missing write_nodes: Whether to write .nodes sidecar with vertex attrs nodes_path: Custom path for nodes sidecar (default: path + ".nodes") lossless: If True, return manifest with all non-SIF data manifest_path: If provided, write manifest to this path (only when lossless=True)
Returns: None (standard mode) or (None, manifest_dict) (lossless mode)
from_sif(path, *, manifest=None, directed=True, relation_attr='relation', default_relation='interacts_with', read_nodes_sidecar=True, nodes_path=None, encoding='utf-8', delimiter=None, comment_prefixes=('#', '!'))
Import graph from SIF (Simple Interaction Format).
Standard mode (manifest=None):
- Reads binary edges from SIF file (source, relation, target)
- Auto-generates edge IDs (edge_0, edge_1, ...)
- All edges inherit the directed parameter
- Vertex attributes loaded from optional .nodes sidecar
- Hyperedges, per-edge directedness, and complex metadata are lost
Lossless mode (manifest provided): - Reads binary edges from SIF file - Restores original edge IDs, weights, and attributes from manifest - Reconstructs hyperedges from manifest - Restores per-edge directedness from manifest - Restores slice memberships and slice-specific weights from manifest - Full round-trip fidelity when paired with to_sif(lossless=True)
SIF Format:
- Three columns: source
Sidecar .nodes file format (optional):
- One vertex per line: vertex_id
Args: path: Input SIF file path manifest: Manifest dict or path to manifest JSON (for lossless reconstruction) directed: Default directedness for edges (overridden by manifest if provided) relation_attr: Edge attribute key for storing relation type default_relation: Default relation if not specified in file read_nodes_sidecar: Whether to read .nodes sidecar file with vertex attributes nodes_path: Custom path for nodes sidecar (default: path + ".nodes") encoding: File encoding (default: utf-8) delimiter: Custom delimiter (default: auto-detect TAB or whitespace) comment_prefixes: Line prefixes to skip (default: # and !)
Returns: AnnNet: Reconstructed graph object
Notes: - SIF format only supports binary edges natively - For full graph reconstruction (hyperedges, slices, metadata), use manifest - Manifest files are created by to_sif(lossless=True) - Edge IDs are auto-generated in standard mode, preserved in lossless mode - Vertex attributes require .nodes sidecar file or manifest