* *

Date: Mon, 5 May 2014 14:12:17 -0600

From: tiago@skewed.de

To: graph-tool@skewed.de

Subject: Re: [graph-tool] return maps from clustering.motifs

_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool

From: tiago@skewed.de

To: graph-tool@skewed.de

Subject: Re: [graph-tool] return maps from clustering.motifs

On 05/05/2014 07:21 AM, sandrine ollinger wrote:

> I've asked to graph-tool the motifs of this graph, with the following instruction:

>

>>>> motifs, counts, vertex_maps = gt.clustering.motifs(gt.GraphView(rlf, directed=False), 4, return_maps=True)

>

> So far, so good. This instruction returned me 3 variables. The first

> one is a list of graphs (motifs), the second one a list of numbers of

> counts, but the third is a bit mysterious for me.

>

> So, it's a list of list of Property maps and it's ok that every one of

> this map correspond with a count of motif. However, I expected that

> this property maps refer to my original graph, but it does not.

That's right, the property map points to the graph you passed to the

function, which is the graph view gt.GraphView(rlf, directed=False), *not*

the original graph rlf.

(note that this is not a problem, you can use these maps with the

original graph)

Allright, I was a little distracted.

> The first PropertyMap object refer to the motif and not to my original

> graph. And here, I don't understand. For a motif which occurs 10 times

> in my graph, I obtain 10 property maps. If I use get_graph on this 10

> maps, I obtain 10 identical graphs. What would be the value of

> returning the maps? I had hoped to obtain sub-graph with original

> vertex and edges properties.

This is useful for knowing where in the graph the motifs have

occurred.

> Is it something that I didn't understand? Is it possible to obtain

> sub-graph with original vertex and edges properties by using

> clustering.motifs?

Yes, you can get a subgraph of the original graph by constructing a

GraphView and filtering out the nodes which do not belong to the motif:

mask = g.new_vertex_property("bool")

m = motifs[0]

vmap = vertex_maps[0]

for v in m.vertices():

mask[g.vertex(vmap[v])] = True

m_g = GraphView(rlf, vfilt=mask)

# the edge and vertex properties of m_g will correspond to those of g

I make something slightly different, based on your proposition:

mask = g.new_vertex_property("bool")

m = motifs[0]

vmap = vertex_maps[0]

pmap = vmap[0]

parray = pmap.get_array()

for v in m.vertices():

mask[g.vertex(parray[v])] = True

It works! Wonderfull!

Thank you very much.

Best,

Sandrine

_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool