Quickstart¶
Build a small signaling graph, inspect its edges, draw it, and save it in the native AnnNet format.
In [1]:
Copied!
import annnet as an
an.info()
import annnet as an
an.info()
Out[1]:
annnetv0.2.0graph: networkxplot: graphvizI/O: 12/13
Show environment details
| Version | v0.2.0 |
|---|---|
| License | BSD-3-Clause |
| Authors | Youssef Zerta ✉, Daniele Bottazzi ✉, Denes Turei ✉ |
| Repository | https://github.com/saezlab/annnet |
| Documentation | https://saezlab.github.io/annnet/reference/ |
| Default adapter backend | networkx |
| Default plot backend | graphviz |
| Graph backends | ✓networkx✓igraph✗graph-tool✓pyg |
| Plot backends | ✓graphviz✗pydot✓matplotlib |
| Tabular data backends | ✓polars✓pandas✓pyarrow |
| I/O modules | ✓annnet✓json/ndjson✓dataframes✓csv✓excel✓graphml/gexf✓sif✓cx2✓parquet✓zarr✗sbml✓scverse✓omnipath |
| Installable bundles | backendsplotiostorageall |
Create a graph¶
In [2]:
Copied!
G = an.AnnNet(directed=True)
G.add_vertices(['EGF', 'EGFR', 'GRB2', 'SOS1', 'RAS', 'ERK'])
G.add_edges('EGF', 'EGFR', edge_id='ligand_binding', weight=1.0)
G.add_edges('EGFR', 'RAS', edge_id='canonical_signal', weight=0.9)
G.add_edges('EGFR', 'RAS', edge_id='adapter_signal', weight=0.7)
G.add_edges('GRB2', 'SOS1', edge_id='adapter_complex', directed=False, weight=0.55)
G.add_edges(
src=['EGFR', 'GRB2', 'SOS1'],
tgt=['RAS'],
edge_id='signalosome',
directed=True,
weight=1.2,
)
G.add_edges('RAS', 'ERK', edge_id='mapk_signal', weight=0.75)
print('shape:', G.shape)
print('vertices:', sorted(G.vertices()))
G = an.AnnNet(directed=True)
G.add_vertices(['EGF', 'EGFR', 'GRB2', 'SOS1', 'RAS', 'ERK'])
G.add_edges('EGF', 'EGFR', edge_id='ligand_binding', weight=1.0)
G.add_edges('EGFR', 'RAS', edge_id='canonical_signal', weight=0.9)
G.add_edges('EGFR', 'RAS', edge_id='adapter_signal', weight=0.7)
G.add_edges('GRB2', 'SOS1', edge_id='adapter_complex', directed=False, weight=0.55)
G.add_edges(
src=['EGFR', 'GRB2', 'SOS1'],
tgt=['RAS'],
edge_id='signalosome',
directed=True,
weight=1.2,
)
G.add_edges('RAS', 'ERK', edge_id='mapk_signal', weight=0.75)
print('shape:', G.shape)
print('vertices:', sorted(G.vertices()))
shape: (6, 6) vertices: ['EGF', 'EGFR', 'ERK', 'GRB2', 'RAS', 'SOS1']
Inspect edges¶
In [3]:
Copied!
G.views.edges().select(
['edge_id', 'kind', 'source', 'target', 'head', 'tail', 'directed', 'effective_weight']
)
G.views.edges().select(
['edge_id', 'kind', 'source', 'target', 'head', 'tail', 'directed', 'effective_weight']
)
Out[3]:
shape: (6, 8)
| edge_id | kind | source | target | head | tail | directed | effective_weight |
|---|---|---|---|---|---|---|---|
| str | str | str | str | list[str] | list[str] | bool | f64 |
| "ligand_binding" | "binary" | "EGF" | "EGFR" | null | null | true | 1.0 |
| "canonical_signal" | "binary" | "EGFR" | "RAS" | null | null | true | 0.9 |
| "adapter_signal" | "binary" | "EGFR" | "RAS" | null | null | true | 0.7 |
| "adapter_complex" | "binary" | "GRB2" | "SOS1" | null | null | false | 0.55 |
| "signalosome" | "hyper" | "EGFR|GRB2|SOS1" | "RAS" | ["EGFR", "GRB2", "SOS1"] | ["RAS"] | true | 1.2 |
| "mapk_signal" | "binary" | "RAS" | "ERK" | null | null | true | 0.75 |
Draw the topology¶
AnnNet stores the graph; Graphviz is just a rendering backend. In a notebook, returning the Graphviz object displays the graph directly.
In [4]:
Copied!
from annnet.utils import plotting
plotting.plot(G, backend='graphviz', show_edge_labels=True)
from annnet.utils import plotting
plotting.plot(G, backend='graphviz', show_edge_labels=True)
Out[4]:
Save and reload¶
In [5]:
Copied!
import os
import tempfile
tmp = tempfile.mkdtemp(prefix='annnet_quickstart_')
path = os.path.join(tmp, 'signaling.annnet')
an.write(G, path)
reloaded = an.read(path)
print('written:', os.path.basename(path))
print('reloaded shape:', reloaded.shape)
import os
import tempfile
tmp = tempfile.mkdtemp(prefix='annnet_quickstart_')
path = os.path.join(tmp, 'signaling.annnet')
an.write(G, path)
reloaded = an.read(path)
print('written:', os.path.basename(path))
print('reloaded shape:', reloaded.shape)
written: signaling.annnet reloaded shape: (6, 6)
The native .annnet file preserves the parallel edges, the
undirected adapter complex, and the signalosome hyperedge instead
of flattening them into a plain edge list.