Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def toIgraph(self):
grlgML_file = open("tmp.graphml","w")
grlgML_file.write(self.toXml())
grlgML_file.close()
g_ig = ig.Graph.Read_GraphML("tmp.graphml")
os.remove("tmp.graphml")
return g_ig
def graphml_to_excel(self, id):
return
nets=model.get_networks(id)
if len(nets) > 1:
return # TODO
if nets[0].vertices >= 65536 or nets[0].edges >= 65536:
return
inputfile = model.get_dataset_filename(id)
inputfile = os.path.join("..", "data", id,
os.path.basename(inputfile))
graphmlext=model.get_format_extension('GraphML')
excelext=model.get_format_extension('Excel')
ungzip('%s%s' % (inputfile, graphmlext))
g=igraph.Graph.Read_GraphML(inputfile + graphmlext)
os.unlink('%s%s' % (inputfile, graphmlext))
ds=list(model.get_dataset(id))[0]
wb=xlwt.Workbook()
## The network
tags=list(model.get_tags(id))
papers=list(model.get_papers(id))
sh1=wb.add_sheet('Network')
sh1.write(0, 0, 'Name')
sh1.write(0, 1, ds.name)
sh1.write(1, 0, 'Vertices')
sh1.write(1, 1, ds.minv)
sh1.write(2, 0, 'Edges')
sh1.write(2, 1, ds.mine)
def calc_basic_stats(path):
# variable to hold network
ig_network = ig.Graph.Read_GraphML('../../data/networks/{}/network.graphml'.format(path))
# variable to hold network1
nx_network = nx.read_graphml('../../data/networks/{}/network.graphml'.format(path))
# variables to hold selectables
network_summary = ig_network.summary()
node_weights = ig_network.vs["Num"]
node_attr = ig_network.vertex_attributes()
node_degrees = ig_network.degree()
degree_dist = ig_network.degree_distribution()
edge_weights = ig_network.es["weight"]
edge_attr = ig_network.edge_attributes()
# variables to hold stats
node_count = ig_network.vcount()
edge_count = ig_network.ecount()
def plot_community_overview_manually():
# variables to hold path
path = 'topics/current/network-a'
edge_type = 'wnn'
method = 'louvain'
# variable to hold network
network = ig.Graph.Read_GraphML('../../data/networks/{}/network/graphml/'
'{}/{}/membership.graphml'.format(path, edge_type, method))
# variable to hold membership
membership = network.vs['membership']
# variable to hold edges
edges = [edge for edge in network.es() if membership[edge.tuple[0]] != membership[edge.tuple[1]]]
# delete edges
network.delete_edges(edges)
# variable to hold visual style
visual_style = {'vertex_label': network.vs['label'],
'vertex_size': network.vs['plot_size'],
'edge_width': network.es['plot_weight'],
'layout': 'kk',
D = DVN.DVN(filepath='/home/ayu/DVN/', dbnames=['patent', 'invpat', 'citation', 'class'], graphml = ['pat_2000.graphml', 'pat_2003.graphml'])
D.summary()
D.create_csv_file()
"""
self.filepath = filepath
self.data = {}
self.graphs = {}
self.begin = begin
self.end = end
self.increment = increment
for dbname in dbnames:
self.data[dbname] = SQLite.SQLite(filepath + dbname + '.sqlite3', dbname)
if graphml:
i = 0
for year in range(self.begin, self.end, self.increment):
self.graphs[year] = igraph.Graph.Read_GraphML(filepath+graphml[i])
i = i + 1
def analyse_network(edge_type, method, attr, threshold, path):
# variable to hold network
network = ig.Graph.Read_GraphML('../../data/networks/{}/network/graphml/network.graphml'.format(path))
####################################################################################################################
# rename columns
network = rename_columns(network)
####################################################################################################################
# if attributes equals to all
if attr == 'all':
# add normalized node number column to network
network.vs['norm_num'] = norm_vals(network.vs['num'], 20, 60)
# add normalized node value column to network
network.vs['norm_val'] = norm_vals(network.vs['val'], 20, 60)
# add normalized edge weight column to network
network.es['norm_weight'] = norm_vals(network.es['weight'], 1, 10)
def check_graphml(self, ds, networks, filename, tags, meta):
res=odict.odict()
## File exists
ex=os.path.exists(filename)
res['Data file exists'] = ex
if not ex:
return res
## File can be loaded
try:
tmp=os.path.join(tempfile.gettempdir(), "nexus")
shutil.rmtree(tmp, ignore_errors=True)
os.mkdir(tmp)
os.system("unzip -d %s %s" % (tmp, filename))
g=dict((n.sid, igraph.Graph.Read_GraphML('%s/%s.GraphML' %
(tmp, n.sid)))
for n in networks)
res['Data file can be loaded'] = True
shutil.rmtree(tmp)
except Exception, x:
print str(x)
res['Data file can be loaded'] = False
return res
res.update(self._check_igraph_graph(g, ds, networks, filename,
tags, meta))
return res
import networkx as nx
import igraph as ig
import Gralog as Gralog
n = 0
### import graph ## GRALOG ###
g = Gralog.Graph(None)
gralog_xml = g.getGraph("xml")
grlgML_file = open("tmp.graphml","w")
grlgML_file.write(gralog_xml)
grlgML_file.close()
graph = "tmp.graphml"
g.message("load")
### import graph to ## IGRAPH + NX ###
g_ig = ig.Graph.Read_GraphML(graph)
g_nx = nx.read_graphml(graph)
### compute center of point cloud ###
doc = ET.parse(graph)
nodes = doc.getroot().find('graph').findall('node')
x, y = [float(nodes[i].attrib['x']) for i in range(len(nodes))], [float(nodes[i].attrib['y']) for i in range(len(nodes))]
center = (int(sum(x)/len(x)), int(sum(y)/len(y)))
g.message("center: "+str(center))
### Compute new coords + write into graphml-file ## ET ###
nx_layouts = [nx.circular_layout(g_nx,10), nx.shell_layout(g_nx,None,7,None,2),
nx.spring_layout(g_nx,None,None, None,50,1e-4,None,7),
nx.kamada_kawai_layout(g_nx,None,None,'weight',10,None,2),
nx.spectral_layout(g_nx,'weight',20,None,2)]
nx_lay = nx_layouts[n]
nx_doc = ET.parse(graph)