In [1]:
import graph_tool as gt
from graph_tool.all import *
import motifwalk as mw
In [8]:
from motifwalk import utils as u
In [12]:
from motifwalk.motifs import Motif
In [13]:
from motifwalk.motifs import *
In [14]:
from motifwalk.motifs import analysis
In [ ]:
analysis.count_motif()
In [144]:
g = random_graph(1000, lambda: (5,5))
result = motifs(g, m.num_vertices(), motif_list=[m], return_maps=True)
In [12]:
mo, count, vmap = result
In [15]:
len(vmap[0])
Out[15]:
In [25]:
p = vmap[0][15]
In [39]:
graph = p.get_graph()
In [71]:
gt.draw.graph_draw(graph, output_size=(100,100))
Out[71]:
In [44]:
p[0]
Out[44]:
In [45]:
p[1]
Out[45]:
In [46]:
p[2]
Out[46]:
In [70]:
g.get_out_edges(151)
Out[70]:
In [72]:
g.get_out_edges(383)
Out[72]:
In [74]:
g.get_out_edges(562)
Out[74]:
In [75]:
m3_7.gt_motif.get_edges()
Out[75]:
In [76]:
p.get_graph().get_edges()
Out[76]:
In [77]:
p[0]
Out[77]:
In [79]:
g.get_out_edges(151)
Out[79]:
In [82]:
p.get_array()
Out[82]:
In [83]:
m = m3_9.gt_motif
gt.draw.graph_draw(m, output_size=(200,200))
Out[83]:
In [84]:
result = motifs(g, m.num_vertices(), motif_list=[m], return_maps=True)
In [85]:
mo, count, vmap = result
In [86]:
p = vmap[0][39]
In [87]:
p.get_array()
Out[87]:
In [89]:
m.get_edges()
Out[89]:
In [148]:
re = motifs(g, k=4, return_maps=True)
In [149]:
len(re)
Out[149]:
In [115]:
len(re[1])
Out[115]:
In [123]:
gt.draw.graph_draw(re[0][43], output_size=(100,200))
gt.draw.graph_draw(re[0][42], output_size=(100,200))
gt.draw.graph_draw(re[0][40], output_size=(100,200))
gt.draw.graph_draw(re[0][41], output_size=(100,200))
Out[123]:
In [111]:
re[0][3].get_edges()[:,0:2]
Out[111]:
In [112]:
[i for i in map(tuple, re[0][3].get_edges()[:,0:2])]
Out[112]:
In [120]:
for i, motifs in enumerate(re[0]):
arr = str([i for i in map(tuple, motifs.get_edges()[:,0:2])])
s = "m4_{} = Motif({}, is_directed=True, name='m4_{}')".format(i, arr, i)
print(s)
In [128]:
la = Graph()
In [129]:
na = nx.Graph()
In [130]:
na.size()
Out[130]:
In [134]:
from itertools import combinations
In [137]:
[i for i in combinations(p.get_array(), 2)]
Out[137]:
In [158]:
def construct_motif_graph(graph_container, vertex_maps=None, motif=None):
"""Construct and return a undirected gt graph containing
motif relationship. TODO: Add anchors nodes
Parameters:
graph_container - GraphContainer - Store the original network
vertex_map - list - contains PropertyMap that maps to vertices in motif
Returns:
m_graph - gt.Graph - Undirected graph for motif cooccurence
"""
if motif is not None and motif.anchors is not None:
print("Warning: TODO refactor anchor code.")
# graph_tool.Graph
m_graph = Graph(directed=False)
if vertex_maps is None:
_, _, vertex_maps = count_motif(graph_container, motif)
for prop in vertex_maps:
edges = [i for i in combinations(prop.get_array(), 2)]
m_graph.add_edge_listadd_edges_from(edges)
return m_graph
In [159]:
la = construct_motif_graph(None, vertex_maps=re[2][0])
In [176]:
graph_draw(m4_0.gt_motif, output_size=(100,100))
Out[176]:
In [177]:
graph_draw(m3_5.gt_motif, output_size=(100,100))
Out[177]:
In [184]:
m3_5_r = motifs(g,k=len(m3_5.gt_motif.get_vertices()),motif_list=[m3_5.gt_motif],return_maps=True)
In [189]:
m3_5_r[2][0][0].get_array()
Out[189]:
In [191]:
g.get_out_edges(216)
Out[191]:
In [192]:
g.get_out_edges(938)
Out[192]:
In [202]:
re = m3_5_r[2][0][0]
In [207]:
re.shrink_to_fit()
In [210]:
re[0]
Out[210]:
In [213]:
re = isomorphism(re.get_graph(), m3_5.gt_motif, isomap=True)
In [218]:
re[1][2]
Out[218]:
In [219]:
re = m3_5_r[2][0][0]
In [220]:
graph_draw(re.get_graph(), output_size=(100,100))
Out[220]:
In [221]:
re.get_graph().get_edges()
Out[221]:
In [222]:
re[0]
Out[222]:
In [223]:
re[1]
Out[223]:
In [224]:
re[2]
Out[224]:
In [228]:
g.get_out_edges(216)
Out[228]:
In [234]:
re.get_graph().get_edges()
Out[234]:
In [236]:
re[0], re[1], re[2]
Out[236]:
In [237]:
for i in _:
print(g.get_out_edges(i))
Since the Property map doesn't map exactly to the node id in the main graph, I have to use the induced subgraphs.
In [238]:
# select some vertices
vfilt = g.new_vertex_property('bool');
vfilt[216] = True
vfilt[756] = True
vfilt[938] = True
sub = GraphView(g, vfilt)
In [260]:
ka = isomorphism(sub, m3_5.gt_motif, isomap=True)
In [270]:
ka[1][216], ka[1][756], ka[1][938]
Out[270]:
In [271]:
[i for i in [216, 756, 938] if ka[1][i] in {0,1}]
Out[271]:
In [ ]: