motifs

Contents

motifs#

graph_tool.clustering.motifs(g, k, p=1.0, motif_list=None, return_maps=False)[git][source]#

Count the occurrence of k-size node-induced subgraphs (motifs). A tuple with two lists is returned: the list of motifs found, and the list with their respective counts.

Parameters:
gGraph

Graph to be used.

kint

number of vertices of the motifs

pfloat or float list (optional, default: 1.0)

uniform fraction of the motifs to be sampled. If a float list is provided, it will be used as the fraction at each depth \([1,\dots,k]\) in the algorithm. See [wernicke-efficient-2006] for more details.

motif_listlist of Graph objects (optional, default: None)

If supplied, the algorithms will only search for the motifs in this list (or isomorphisms).

return_mapsbool (optional, default: False)

If True, a list will be returned, which provides for each motif graph a list of vertex property maps which map the motif to its location in the main graph.

Returns:
motifslist of Graph objects

List of motifs of size k found in the Graph. Graphs are grouped according to their isomorphism class, and only one of each class appears in this list. The list is sorted according to the number of edges, then the out-degree sequence, then the in-degree sequence, and finally according to the canonical form of the motifs (see Notes), so that the order does not depend on the number of threads.

countslist of ints

The number of times the respective motif in the motifs list was counted

vertex_mapslist of lists of VertexPropertyMap objects

List for each motif graph containing the locations in the main graph. This is only returned if return_maps == True.

See also

motif_significance

Significance profile of motifs

local_clustering

Local clustering coefficient

global_clustering

Global clustering coefficient

extended_clustering

Extended (generalized) clustering coefficient

Notes

This function implements the ESU and RAND-ESU algorithms described in [wernicke-efficient-2006]. The subgraphs are classified by a canonical form of their adjacency matrices, which is exact also for subgraphs with parallel edges or self-loops. The vertices are first partitioned by color refinement, which gives an ordering of the classes that does not depend on the labeling, and the canonical form is the smallest, in lexicographical order, of the sequences

\[A_{00}, A_{11}, A_{10}, A_{01}, A_{22}, A_{20}, A_{02}, A_{21}, A_{12}, \dots, A_{k-1,k-1}, \dots, A_{k-1,k-2}, A_{k-2,k-1},\]

over the orderings of the vertices compatible with this partition, where \(A_{ij}\) is the number of edges from the \(i\)-th to the \(j\)-th vertex in the ordering. Two subgraphs have the same canonical form if and only if they are isomorphic. The motifs found are returned with the vertices in the canonical order, and the motifs given in motif_list are returned as they are.

The motifs are sorted in ascending order of their number of edges, then of their sorted out-degree sequences, then of their sorted in-degree sequences, and finally of their canonical forms, compared lexicographically. Isomorphic motifs in motif_list keep their relative order.

Parallel implementation.

If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.

References

[wernicke-efficient-2006] (1,2)

S. Wernicke, “Efficient detection of network motifs”, IEEE/ACM Transactions on Computational Biology and Bioinformatics (TCBB), Volume 3, Issue 4, Pages 347-359, 2006. DOI: 10.1109/TCBB.2006.51 [sci-hub, @tor]

Examples

>>> g = gt.random_graph(1000, lambda: (5,5))
>>> motifs, counts = gt.motifs(gt.GraphView(g, directed=False), 4)
>>> print(len(motifs))
11
>>> print(counts)
[115626, 390445, 662, 763, 2816, 1686, 776, 10, 3, 11, 5]