Graph motifs are small connected induced subgraphs with a well-defined structure. These functions search a graph for various motifs.
Arguments
- graph
Graph object, the input graph.
- size
The size of the motif, currently sizes 3 and 4 are supported in directed graphs and sizes 3 to 6 in undirected graphs.
- cut.prob
Numeric vector giving the probabilities that the search graph is cut at a certain level. Its length should be the same as the size of the motif (the
sizeargument). IfNULL, the default, no cuts are made.- callback
Optional callback function to call for each motif found. The function should accept two arguments:
vids(integer vector of vertex IDs in the motif) andisoclass(the isomorphism class of the motif). The function should returnFALSEto continue the search orTRUEto stop it. IfNULL(the default), motif counts are returned as a numeric vector.Important limitation: Callback functions must NOT call any igraph functions (including simple queries like
vcount()orecount()). Doing so will cause R to crash due to reentrancy issues. Extract any needed graph information before calling the function with a callback, or use collector mode (the default) and process results afterward.
Value
When callback is NULL, motifs() returns a numeric vector,
the number of occurrences of each motif in the graph. The motifs are ordered
by their isomorphism classes. Note that for unconnected subgraphs, which are
not considered to be motifs, the result will be NA.
When callback is provided, the function returns NULL invisibly and calls
the callback function for each motif found.
Details
motifs() searches a graph for motifs of a given size and returns a
numeric vector containing the number of different motifs. The order of
the motifs is defined by their isomorphism class, see
isomorphism_class().
See also
Other graph motifs:
count_motifs(),
dyad_census(),
sample_motifs()
Examples
g <- sample_pa(100)
motifs(g, 3)
#> [1] NA NA 266 NA 80 0 0 0 0 0 0 0 0 0 0 0
count_motifs(g, 3)
#> [1] 346
sample_motifs(g, 3)
#> [1] 60
# Using callback to stop search after finding 5 motifs
count <- 0
motifs(g, 3, callback = function(vids, isoclass) {
count <<- count + 1
count < 5 # stop after 5 motifs
})
