Para (beyond pairwise) Graph: interactive visualization of higher-order graphs in Python
pip install paragProportion of degrees by communities in a pairwise graph helps reveal how nodes are grouped together and connected within different communities. This analysis highlights clusters of nodes with strong internal connections, potentially representing higher-order relationships. By comparing the degree proportions within and between communities, we can distinguish internal cohesion from inter-community interactions. These insights aid in interpreting the graph as a hypergraph, where communities with high intra-community connections may signify higher-order relationships, offering a richer understanding of complex interactions beyond simple pairwise connections.
Inspired by
Vehlow, Corinna, Thomas Reinhardt, and Daniel Weiskopf. “Visualizing fuzzy overlapping communities in networks.” IEEE Transactions on Visualization and Computer Graphics 19.12 (2013): 2486-2495.
Figure 9B
Examples:
from parag.hypergraph import to_net
cfg,df_=to_net(
nodes=nodes.sort_values('Essentiality (determined from multiple datasets)'),
edges=edges,
col_node_id='Gene ID',
col_source='# protein1',
col_target='protein2',
col_subset_id='Essentiality (determined from multiple datasets)',
show_node_names=True,
defaults=dict(
radius=250,
innerRadius=280,
outerRadius=295,
textSize=7,
textOffset=3,
),
) <iframe
width="100%"
height="1000"
src="outputs//interactions.html"
frameborder="0"
allowfullscreen
></iframe>
sc.pl.umap(adata, color="bulk_labels",title='Latent space')from parag.core import get_net_data
nodes,edges=get_net_data(adata) ## generated network data by measuring distances in the latent space and thresholdingfrom parag.hypergraph import to_net
cfg,df_=to_net(
nodes,
edges,
col_node_id='cell id',
col_source='cell id1',
col_target='cell id2',
col_subset_id='bulk_labels',
show_node_names=False,
defaults=dict(
textSize=8,
textOffset=3,
),
) <iframe
width="100%"
height="1000"
src="outputs//neighbourhoods.html"
frameborder="0"
allowfullscreen
></iframe>
## filter
nodes=(df02
.loc[:,["Individual Side Effect","Side Effect Name"]]
.log.drop_duplicates()
.assign(
#Side Effect type
subset=lambda df: df['Side Effect Name'].str.split(' ',expand=True)[0],
)
.drop(['Side Effect Name'],axis=1)
.groupby('subset').filter(lambda df: len(df)>3 and len(df)<10)
.head(5)
.sort_values('subset')
.log('Individual Side Effect') # id
.log('Individual Side Effect') # name
)
nodes.head(1)| Individual Side Effect | subset | |
|---|---|---|
| 1 | C0162830 | Photosensitivity |
edges=(
df02
.log.query(expr=f"`Individual Side Effect` == {nodes['Individual Side Effect'].unique().tolist()}")
)
edges.head(1)| # STITCH | Individual Side Effect | Side Effect Name | |
|---|---|---|---|
| 1 | CID003062316 | C0162830 | Photosensitivity reaction |
## append drugs to nodes
nodes=pd.concat(
[
edges.loc[:,['# STITCH']].drop_duplicates().rename(columns={'# STITCH':'node id'},errors='raise').assign(subset='drug'),
nodes.rename(columns={'Individual Side Effect':'node id'},errors='raise'),
],
axis=0,
)
nodes.head(1)| node id | subset | |
|---|---|---|
| 1 | CID003062316 | drug |
from parag.hypergraph import to_net
cfg,df_=to_net(
nodes,
edges,
col_node_id='node id',
col_source='# STITCH',
col_target='Individual Side Effect',
col_subset_id='subset',
show_node_names=False,
defaults=dict(
radius=200,
innerRadius=205,
outerRadius=235,
textSize=9,
textOffset=3,
cornerRadius=3.5,
),
) <iframe
width="100%"
height="1000"
src="outputs//heterogeneous.html"
frameborder="0"
allowfullscreen
></iframe>
# Plot graph with colouring based on communities
fig, ax = plt.subplots(1,1, figsize=(5, 3))
visualize_communities(G, communities[3], 2)nodes=pd.Series({i:list(t) for i,t in enumerate(communities[3])}).explode().to_frame('node id').reset_index().rename(columns={'index':'community id'}).sort_values('community id')
nodes.head(1)| community id | node id | |
|---|---|---|
| 0 | 0 | 0 |
edges=pd.DataFrame(G.edges,columns=['source','target'])
edges.head(1)| source | target | |
|---|---|---|
| 0 | 0 | 1 |
from parag.hypergraph import to_net
cfg,df_=to_net(
nodes.applymap(str),
edges.applymap(str),
col_node_id='node id',
col_source='source',
col_target='target',
col_subset_id='community id',
show_node_names=True,
defaults=dict(
radius=180,
innerRadius=205,
outerRadius=235,
textSize=17,
textOffset=4,
cornerRadius=3.5,
),
) <iframe
width="100%"
height="1000"
src="outputs//communities.html"
frameborder="0"
allowfullscreen
></iframe>
Nodes and edges can be converted to and from the Hypergraph Interchange
Format (HIF), e.g. to exchange
data with XGI or
HyperNetX. With mode='subsets'
(default), the subsets (e.g. communities) are the hyperedges; with
mode='pairwise', each edge is a hyperedge of 2 nodes.
from parag.io import to_hif, from_hif
hif = to_hif(
nodes,
edges,
col_node_id='node id',
col_source='source',
col_target='target',
col_subset_id='community id',
)
## e.g. write_hif(hif, 'communities.json'), xgi.read_hif('communities.json')
## from HIF, e.g. from_hif(read_hif('communities.json')), input for to_net
d = from_hif(hif)
d['nodes'].head(2)The gene-interaction and drug side-effect examples use datasets from the
BioSNAP collection. To keep the
examples (and CI) fast and independent of network access, only the first
1000 lines of each file are stored in
examples/inputs;
see the README there for details.
| File | BioSNAP dataset | Source |
|---|---|---|
G-HumanEssential.tsv |
Human essential genes | Gene essentiality from the studies listed in its Data Source column (PubMed IDs) |
PPT-Ohmnet_tissues-combined.edgelist |
Tissue-specific protein-protein interactions | Zitnik M, Leskovec J. Predicting multicellular function through multi-layer tissue networks. Bioinformatics 33(14), i190–i198 (2017) |
ChSe-Decagon_monopharmacy.csv |
Drug side effects | Zitnik M, Agrawal M, Leskovec J. Modeling polypharmacy side effects with graph convolutional networks. Bioinformatics 34(13), i457–i466 (2018). doi:10.1093/bioinformatics/bty294 |
Collection: Zitnik M, Sosič R, Maheshwari S, Leskovec J. BioSNAP Datasets: Stanford Biomedical Network Dataset Collection (2018). https://snap.stanford.edu/biodata
- Using BibTeX:
@software{Dandage_parag,
title = {parag: interactive visualization of higher-order graphs in Python},
author = {Dandage, Rohan},
year = {2024},
url = {https://doi.org/10.5281/zenodo.10703097},
version = {v0.0.1},
note = {The URL is a DOI link to the permanent archive of the software.},
}
-
Using citation information from CITATION.CFF file.
The package source is in parag/. The tutorials (examples/*.ipynb)
import from it; examples/ also holds the docs configuration, their
inputs and outputs.
uv pip install -e ".[dev]"
pytest # unit tests (tests/) and the tutorial notebooks
uvx ruff@0.17.2 check parag tests
quarto render examples # docs, into _docs/- Bump the version in
parag/__init__.py(__version__). - Update
versionanddate-releasedinCITATION.cff(checked bytests/test_metadata.py). - Push a tag (e.g.
git tag v0.0.2 && git push --tags); thereleaseworkflow publishes to PyPI.
- Showing degree counts in addition to the percentages
- Inferring the
defaultse.g. radii from the input data. - Bind
rotatesignal to the hypergraph andstart/endAngleto graph. - Set up
tidylayout. - Edge coloring by source and target nodes and setting
interactions. - CI for quicker testing use lighter example.
- More examples





