igraph-help
[Top][All Lists]

## RE: [igraph] graph.motifs function in the R igraph library

 From: Coghlan, Avril Subject: RE: [igraph] graph.motifs function in the R igraph library Date: Mon, 8 Feb 2010 22:14:28 -0000

Dear Tamas,

I have written a little function that prints out all the motifs of a certain size in a graph.
I've don't know if it's useful to others too, but I've included it below in case you might be interested in including it as an extra function in "igraph".
By the way, "igraph" is a great library, I'm finding it extremely useful.

Regards, and thanks again,
Avril
Avril Coghlan
University College Cork, Ireland

# Function to find network motifs in a directed graph
findnetworkmotifs <- function(graph, motifsize)
{
library(igraph)
# Find network motifs in the graph "graph":
mygraphmotifs <- graph.motifs(graph, motifsize)
# Find which motifs occur:
nummotifs <- length(mygraphmotifs)
for (i in 1:nummotifs)
{
motif <- mygraphmotifs[i]
if (motif > 0) # There are some occurrences of this motif
{
# Find out what the motif looks like:
motifgraph <- graph.isocreate(size=motifsize, number=i-1, directed=TRUE)
edges <- E(motifgraph)
print(paste("This motif occurs",motif,"times:"))
print(edges)
}
}
}

-----Original Message-----
Sent: Sat 2/6/2010 11:40 PM
To: Help for igraph users
Cc: Coghlan, Avril
Subject: Re: [igraph] graph.motifs function in the R igraph library

> I am wondering if there is a way to finding out what are the motifs
> found by the graph.motifs() function in the igraph library?
Yes. Citing the manual (http://igraph.sourceforge.net/doc/R/graph.motifs.html):

"graph.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 graph.isoclass."

So, the first entry in the returned vector contains the number of motifs represented by graph.isocreate(size=3, number=0), the second entry corresponds to graph.isocreate(size=3, number=1), the third to graph.isocreate(size=3, number=2) and so on. Obviously use size=4 if you were looking for motifs of size 4. You can plot these graphs generated by graph.isocreate to see how they look like.

--
Tamas