-
Notifications
You must be signed in to change notification settings - Fork 10
Getting Started
To start using GrandIso with NetworkX, first install the library:
pip3 install grandiso
(If you are using a different network science library, see Not Using NetworkX.)
Let's count the number of triangles in a large Erdős–Rényi graph. First, we'll generate the host graph:
import networkx as nx
host = nx.fast_gnp_random_graph(50, 0.1)
Next we'll generate the motif graph:
motif = nx.complete_graph(3)
These graphs are both undirected. (For directed search, see below.) GrandIso will automatically determine if a motif search should be directed or undirected based upon the host and motif you pass to it.
Finally, we can perform the motif search:
from grandiso import find_motifs
results = find_motifs(motif, host)
Now, results
is a List of Dictionaries, where each item in the list is a mapping from motif to host:
[
{
"motif_id": "corresponding_host_id",
"motif_id": "corresponding_host_id",
"motif_id": "corresponding_host_id",
}
]
If you don't care about the node matches and just want to have the total count of motif instances, you can actually save a little bit of RAM! Just pass count_only=True
:
results = find_motifs(motif, host, count_only=True)
Now instead of a list of mappings, results
is an integer count.
If this tool is helpful to your research, please consider citing it with:
# https://doi.org/10.1038/s41598-021-91025-5
@article{Matelsky_Motifs_2021,
title={{DotMotif: an open-source tool for connectome subgraph isomorphism search and graph queries}},
volume={11},
ISSN={2045-2322},
url={http://dx.doi.org/10.1038/s41598-021-91025-5},
DOI={10.1038/s41598-021-91025-5},
number={1},
journal={Scientific Reports},
publisher={Springer Science and Business Media LLC},
author={Matelsky, Jordan K. and Reilly, Elizabeth P. and Johnson, Erik C. and Stiso, Jennifer and Bassett, Danielle S. and Wester, Brock A. and Gray-Roncal, William},
year={2021},
month={Jun}
}