Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphML support #3

Open
ungentilgarcon opened this issue Nov 26, 2016 · 4 comments
Open

GraphML support #3

ungentilgarcon opened this issue Nov 26, 2016 · 4 comments

Comments

@ungentilgarcon
Copy link

We need to add support for GraphML file format.

@clemsos
Copy link
Member

clemsos commented Nov 26, 2016

Support what, how ? why ?

@ungentilgarcon
Copy link
Author

Well GraphML is standard input for gephi like networks, standard output of R based stat tools.

this import function would enable to push large amount of graphml calculated files in topo .

for an example
https://github.com/uskudnik/GraphGL/blob/master/examples/graphml-to-json.py

@clemsos
Copy link
Member

clemsos commented Nov 26, 2016

Yes, GraphML is Gephi standard and already supported by NetworkX and other libs : https://networkx.github.io/documentation/networkx-1.10/reference/readwrite.graphml.html

No need for built-in support, you can just parse a graphML file with nx and push it to Topogram using Python.

Here an (untested) example

import networkx as nx
from topogram_client import TopogramAPIClient

# read graphML file
with open("network.graphml") as f:
    G = nx.read_graphml(f)

# passwords
TOPOGRAM_URL = "https://app.topogram.io" # "http://localhost:3000"
USER = "xxx@xxx.com"
PASSWORD = "xxx"

# connect to the topogram instance 
topogram = TopogramAPIClient(TOPOGRAM_URL)

# topogram.create_user(USER, PASSWORD)
topogram.user_login(USER, PASSWORD)

# create the graph
nodes = []
for n in G.nodes(data=True): 
    node = n[1]
    node["id"] = n[0]
    node["group"] = n[1]["type"]
    nodes.append(node)

print "creating %s nodes ..."%len(nodes)
r = topogram.create_nodes(topogram_ID, nodes)

edges = []
for e in G.edges(data=True): 
    edge = e[2]
    edge["source"] = e[0]
    edge["target"] = e[1]
    edges.append(edge)

print "creating %s edges ..."%len(edges)
r = topogram.create_edges(topogram_ID, edges)

print "done. Topogram is online at %s/topograms/%s"%(TOPOGRAM_URL,topogram_ID)

@clemsos
Copy link
Member

clemsos commented Nov 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants