Higher-order network motif analysis in hypergraphsยถ
Definition
Motifs are small subhypergraphs that occur more often than expected under a null model.
You will learn
Compute higher-order motifs and interpret their statistics.
Overviewยถ
Compute higher-order motifs and interpret their patterns.
Visualize motif statistics for quick inspection.
Setupยถ
[1]:
import matplotlib as mpl
mpl.rcParams.update({
"figure.figsize": (6, 4),
"figure.dpi": 120,
"savefig.dpi": 150,
})
The function compute_motifs accepts the hypergraph H as a parameter, the order of the motif analysis (i.e., the size of the patterns in terms of the number of nodes), and the runs of the configuration model for computing the score of the motifs (relative abundance). Zero runs of the configuration model corresponds to counting patterns in the input hypergraphs. For example, here we set five runs for the configuration model. Five runs is a very low number, but it is enough for the purpose of this tutorial.
The output object stores the count of the patterns on the input hypergraph, the count of the patterns on the samples from the configuration model and the relative abundance score of the motifs.
[2]:
import sys
sys.path.append("..")
import hypergraphx as hgx
from hypergraphx.motifs import compute_motifs
from hypergraphx.readwrite import load_hypergraph
from hypergraphx.viz import plot_motifs
Here we load the dataset โhigh schoolโ from our data repository
[3]:
H = load_hypergraph("../test_data/hs/hs.json")
[4]:
motifs = compute_motifs(H, order=3, runs_config_model=5)
[5]:
print(motifs.keys())
dict_keys(['observed', 'config_model', 'norm_delta'])
[6]:
motifs['observed']
[6]:
[(((1, 2), (1, 2, 3)), 58),
(((1, 2), (1, 2, 3), (1, 3)), 231),
(((1, 2), (1, 2, 3), (1, 3), (2, 3)), 1802),
(((1, 2), (1, 3)), 115709),
(((1, 2), (1, 3), (2, 3)), 28029),
(((1, 2, 3),), 0)]
[7]:
print(motifs['norm_delta'])
[(((1, 2), (1, 2, 3)), -0.46264365428648674), (((1, 2), (1, 2, 3), (1, 3)), 0.2151545406162159), (((1, 2), (1, 2, 3), (1, 3), (2, 3)), 0.5546029717156314), (((1, 2), (1, 3)), -0.0857528475493179), (((1, 2), (1, 3), (2, 3)), 0.3366743100547552), (((1, 2, 3),), -0.5580159268795104)]
[8]:
motif_profile = [i[1] for i in motifs['norm_delta']]
Letโs plot the profile. Please keep in mind that the x-axis of the plot follows the original paper convention, displaying first the patterns involving lower-order interactions only.
[9]:
plot_motifs(motif_profile)
[9]:
<Axes: ylabel='Motif abundance score'>