OmniPath table ingestion¶
omnipath_client.to_annnet builds a graph from an OmniPath-style
interaction table. AnnNet reaches no knowledge base of its own: the
client for a knowledge base is what returns AnnNet objects. This
notebook uses a local table so it is deterministic.
In [1]:
Copied!
import annnet as an
import omnipath_client as oc
an.info()
import annnet as an
import omnipath_client as oc
an.info()
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Cell In[1], line 2 1 import annnet as an ----> 2 import omnipath_client as oc 4 an.info() ModuleNotFoundError: No module named 'omnipath_client'
Build from a local OmniPath-style table¶
In [2]:
Copied!
import polars as pl
interactions = pl.DataFrame(
{
'source': ['EGF', 'EGFR', 'EGFR', 'EGFR', 'RAS', 'MEK'],
'target': ['EGFR', 'RAS', 'RAS', 'GRB2', 'MEK', 'ERK'],
'interaction_id': [
'EGF_EGFR',
'EGFR_RAS_primary',
'EGFR_RAS_secondary',
'EGFR_GRB2_complex',
'RAS_MEK',
'MEK_ERK',
],
'is_directed': [True, True, True, False, True, True],
'curation_score': [0.95, 0.88, 0.63, 0.76, 0.82, 0.79],
'consensus_direction': [1, 1, 1, 0, 1, 1],
'source_database': [
'omnipath',
'omnipath',
'literature',
'complexportal',
'pathwayextra',
'kinaseextra',
],
}
)
G = oc.to_annnet(
interactions,
source_col='source',
target_col='target',
edge_id_col='interaction_id',
directed_col='is_directed',
weight_col='curation_score',
edge_attr_cols=['consensus_direction', 'source_database'],
)
print('shape:', G.shape)
G.views.edges().select(
['edge_id', 'source', 'target', 'effective_weight', 'source_database']
)
import polars as pl
interactions = pl.DataFrame(
{
'source': ['EGF', 'EGFR', 'EGFR', 'EGFR', 'RAS', 'MEK'],
'target': ['EGFR', 'RAS', 'RAS', 'GRB2', 'MEK', 'ERK'],
'interaction_id': [
'EGF_EGFR',
'EGFR_RAS_primary',
'EGFR_RAS_secondary',
'EGFR_GRB2_complex',
'RAS_MEK',
'MEK_ERK',
],
'is_directed': [True, True, True, False, True, True],
'curation_score': [0.95, 0.88, 0.63, 0.76, 0.82, 0.79],
'consensus_direction': [1, 1, 1, 0, 1, 1],
'source_database': [
'omnipath',
'omnipath',
'literature',
'complexportal',
'pathwayextra',
'kinaseextra',
],
}
)
G = oc.to_annnet(
interactions,
source_col='source',
target_col='target',
edge_id_col='interaction_id',
directed_col='is_directed',
weight_col='curation_score',
edge_attr_cols=['consensus_direction', 'source_database'],
)
print('shape:', G.shape)
G.views.edges().select(
['edge_id', 'source', 'target', 'effective_weight', 'source_database']
)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[2], line 29 1 import polars as pl 3 interactions = pl.DataFrame( 4 { 5 'source': ['EGF', 'EGFR', 'EGFR', 'EGFR', 'RAS', 'MEK'], (...) 26 } 27 ) ---> 29 G = oc.to_annnet( 30 interactions, 31 source_col='source', 32 target_col='target', 33 edge_id_col='interaction_id', 34 directed_col='is_directed', 35 weight_col='curation_score', 36 edge_attr_cols=['consensus_direction', 'source_database'], 37 ) 39 print('shape:', G.shape) 40 G.views.edges().select( 41 ['edge_id', 'source', 'target', 'effective_weight', 'source_database'] 42 ) NameError: name 'oc' is not defined
Add analysis context as slices¶
In [3]:
Copied!
rows = list(G.views.edges().iter_rows(named=True))
edge_label = {
row['edge_id']: f"{row['source']} -> {row['target']}"
for row in rows
}
high_confidence = [
row['edge_id']
for row in rows
if row['effective_weight'] >= 0.85
]
G.slices.add('high_confidence')
G.slices.add_edges('high_confidence', high_confidence)
print(
'high-confidence interactions:',
[edge_label[eid] for eid in sorted(G.slices.edges('high_confidence'))],
)
rows = list(G.views.edges().iter_rows(named=True))
edge_label = {
row['edge_id']: f"{row['source']} -> {row['target']}"
for row in rows
}
high_confidence = [
row['edge_id']
for row in rows
if row['effective_weight'] >= 0.85
]
G.slices.add('high_confidence')
G.slices.add_edges('high_confidence', high_confidence)
print(
'high-confidence interactions:',
[edge_label[eid] for eid in sorted(G.slices.edges('high_confidence'))],
)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[3], line 1 ----> 1 rows = list(G.views.edges().iter_rows(named=True)) 2 edge_label = { 3 row['edge_id']: f"{row['source']} -> {row['target']}" 4 for row in rows 5 } 6 high_confidence = [ 7 row['edge_id'] 8 for row in rows 9 if row['effective_weight'] >= 0.85 10 ] NameError: name 'G' is not defined
Draw the prior network¶
In [4]:
Copied!
from annnet.utils import plotting
plotting.plot(
G,
backend='graphviz',
show_edge_labels=True,
edge_label_keys=['source_database'],
)
from annnet.utils import plotting
plotting.plot(
G,
backend='graphviz',
show_edge_labels=True,
edge_label_keys=['source_database'],
)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[4], line 4 1 from annnet.utils import plotting 3 plotting.plot( ----> 4 G, 5 backend='graphviz', 6 show_edge_labels=True, 7 edge_label_keys=['source_database'], 8 ) NameError: name 'G' is not defined
The client hands back a graph that keeps confidence, provenance and every downstream context in one object. Where the table came from is the concern of the client, and what the graph does with it is the concern of AnnNet.