In [1]:
from py2cytoscape.data.cynetwork import CyNetwork
from py2cytoscape.data.cyrest_client import CyRestClient
from py2cytoscape.data.style import StyleUtil
import py2cytoscape.util.cytoscapejs as cyjs
import py2cytoscape.cytoscapejs as renderer

import networkx as nx
import pandas as pd
import json

import igraph as ig

import rpy2.robjects.packages as rpackages
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-ed5dda1dbc56> in <module>()
     11 import igraph as ig
     12 
---> 13 import rpy2.robjects.packages as rpackages

ImportError: No module named rpy2.robjects.packages
In [117]:
NUM_NODES = 100

g1 = ig.Graph.Barabasi(NUM_NODES, 2)
g2 = ig.Graph.GRG(NUM_NODES, 0.2)

cy = CyRestClient()
cy.network.create_from_igraph(g1)
cy.network.create_from_igraph(g2)
Out[117]:
<py2cytoscape.data.cynetwork.CyNetwork at 0x10b80dd50>
In [148]:
g2.vs['label'] = [-1]*NUM_NODES
fix = [False]*NUM_NODES


node0 = g2.vs[40]
node1 = g2.vs[57]


ne1= node0.neighbors()
ne2= node1.neighbors()

print(ne1)


g2.vs[40]['label'] = 1 
g2.vs[57]['label'] = 1 

for n in ne1:
    print(n.index)
    g2.vs[n.index]['label'] = 1
    
for n in ne2:
    print(n.index)
    g2.vs[n.index]['label'] = 1

fix[40] = True
fix[57] = True
[igraph.Vertex(<igraph.Graph object at 0x10a739ed8>,27,{'y': 0.4122450976155393, 'x': 0.26689583205779077, 'label': -1, 'community': 0, 'f1': None}), igraph.Vertex(<igraph.Graph object at 0x10a739ed8>,37,{'y': 0.4413342902926116, 'x': 0.4042221456555569, 'label': -1, 'community': 1, 'f1': None}), igraph.Vertex(<igraph.Graph object at 0x10a739ed8>,42,{'y': 0.3919489906377719, 'x': 0.4447844056662684, 'label': -1, 'community': 1, 'f1': None}), igraph.Vertex(<igraph.Graph object at 0x10a739ed8>,43,{'y': 0.4770437889078536, 'x': 0.4455614569474644, 'label': -1, 'community': 1, 'f1': None}), igraph.Vertex(<igraph.Graph object at 0x10a739ed8>,44,{'y': 0.7063847186804972, 'x': 0.4719754150531076, 'label': -1, 'community': 0, 'f1': None}), igraph.Vertex(<igraph.Graph object at 0x10a739ed8>,46,{'y': 0.4894698809295054, 'x': 0.48049028523140314, 'label': -1, 'community': 1, 'f1': None}), igraph.Vertex(<igraph.Graph object at 0x10a739ed8>,48,{'y': 0.4316934429074447, 'x': 0.48068638848412193, 'label': -1, 'community': 1, 'f1': None}), igraph.Vertex(<igraph.Graph object at 0x10a739ed8>,54,{'y': 0.5463835210708057, 'x': 0.5826852935480062, 'label': -1, 'community': 0, 'f1': None}), igraph.Vertex(<igraph.Graph object at 0x10a739ed8>,55,{'y': 0.4600141507637713, 'x': 0.5841189250955006, 'label': -1, 'community': 1, 'f1': None})]
27
37
42
43
44
46
48
54
55
39
47
50
59
64
67
69
In [149]:
res = g2.community_label_propagation(initial='label')

g2.vs['community'] = res.membership

cy.network.create_from_igraph(g2)
Out[149]:
<py2cytoscape.data.cynetwork.CyNetwork at 0x10b981410>
In [167]:
yhq = pd.read_csv('/Applications/Cytoscape_v3.2.1/sampleData/yeastHighQuality.sif', sep=' ', names=['s', 'itr', 't'])
yhq = yhq.drop('itr', 1)
yhq.head()

yhq.to_csv('yhq.el', sep=' ')
In [168]:
ig.Graph.Read_Edgelist('yhq.el')
---------------------------------------------------------------------------
InternalError                             Traceback (most recent call last)
<ipython-input-168-127fd4c64011> in <module>()
----> 1 ig.Graph.Read_Edgelist('yhq.el')

InternalError: Error at foreign.c:101: parsing edgelist file failed, Parse error