Hi Tamas,
I tried the ways as you suggested. It works. However, the speed is a bottleneck. So I come out a method to avoid checking motifs for my case.
The oncoming questions are: what is the most efficient way to find the incident edges of the current edge?
Here is my solution:
CurrentEdgeId <- get.edge.ids( g_OriginGraph, motif_current ) # motif_current is just an edge
IncidentEdges <- incident_edges( g_OriginGraph, motif_current )
IncidentEdgeIds <- unlist( IncidentEdges )
IncidentEdgeIds = IncidentEdgeIds[ IncidentEdgeIds != CurrentEdgeId ]
The above code can give the neighboring edges of the current edge. However, it is much slower than directly indexing the edge list of the graph:
Edges <- as_edgelist( g_OriginGraph, FALSE )
Motifs_left <- rbind( Edges[Edges[,1] == motif_current[1],], Edges[Edges[,2] == motif_current[1],] )
Motifs_right <- rbind( Edges[Edges[,1] == motif_current[2],], Edges[Edges[,2] == motif_current[2],] )
NeighborMotifs <- rbind(Motifs_left, Motifs_right)
idx <- which( NeighborMotifs[,1] == motif_current[1] & NeighborMotifs[,2] == motif_current[2] )
NeighborMotifs <- NeighborMotifs[-idx,]
So I am wondering if there is some other functions from igraph to get the edges very fast.
Thanks a lot.
Cheers,
Phil