1
votes

I have generated a graph with networkx, and exported it as a .dot file for vizualization.

The .dot file looks ok, there are the nodes and the node attributes I've created, as well as the edge data (via below), everything in place.

My problem is how to vizualize this data on linux? I've tried with gephi, it looks like the most capable among them, but it doesn't detect the edge attributes (via).

I need to be able to explore the data interactively.

Here is a simplified dot file which shows the same behavior

strict digraph G {
"README.md";
"src/modules/books/email_bk_title.php" [created="[466]"];
"functions/mysql/tmp" [created="[23, 43]"];
"src/modules/login/login_check.php" [created="[198]"];
"src/post_process_loader.php" [created="[178]"];
"src/style.css";
"src/templates/default/js/bootstrap-tooltip.js" [created="[8]"];
"src/webroot/templates/default/js/bootstrap-modal.js" [created="[23]"];
"src/webroot/templates/default/js/bootstrap-transition.js" [created="[23]"];
"src/templates/default/js/bootstrap-collapse.js" [created="[8]"];
"src/modules/books/tmp";
"src/templates/default/css/bootstrap.css" [created="[8]"];
"LICENSE.txt" [created="[6]"];
"src/templates/default/js/bootstrap.js" [created="[8]"];
"docs/app_skel_design.md" [created="[39]"];
"src/webroot/templates/default/js/bootstrap-button.js" [created="[23]"];
"src/templates/default/js/google-code-prettify/prettify.css" [created="[8]"];
"src/templates/default/js/bootstrap-tab.js" [created="[8]"];
"src/modules/logout/logout_bl.php" [created="[280]"];
"functions/books/tmp" [created="[23, 43]"];
"src/modules/admin/tmp";
"src/modules/register/tmp" [created="[73, 94]"];
"docs/database/db_constraints_behavior.md" [created="[38]"];
"src/webroot/templates/default/js/bootstrap-scrollspy.js" [created="[23]"];
"uploads/tmp" [created="[237]"];
"src/modules/login/login.php" [created="[127]"];
"src/resources/books/books.php" [created="[306, 366, 518]"];
"src/resource_holder.php" [created="[221, 250, 304, 428]"];
"src/modules/session/session_start.php" [created="[177]"];
"src/webroot/templates/default/index.html" [created="[23]"];
".gitignore" [created="[170, 289]"];
"src/functions/mysql/tmp" [created="[44]"];
"src/webroot/templates/default/js/bootstrap.js" [created="[23]"];
"src/modules/user/user_bl.php" [created="[142, 169, 439]"];
"src/modules/logout/logout.php" [created="[156, 270]"];
"src/webroot/templates/default/js/bootstrap-tooltip.js" [created="[23]"];
"src/modules/base/functions.php" [created="[64, 158, 232, 233, 254]"];
"src/resources/base/functions.php";
"docs/roadmap/v0.2.0-v0.4.0.txt" [created="[209]"];
"src/templates/default/js/bootstrap-typeahead.js" [created="[8]"];
"docs/database/mylibrary.sql" [created="[29]"];
"src/resource_holder.php.php" [created="[216]"];
"src/webroot/templates/default/js/bootstrap-popover.js" [created="[23]"];
"src/modules/register/register.php" [created="[93, 110, 455, 457]"];
"src/webroot/style.css" [created="[41, 46, 63, 126]"];
"src/webroot/templates/default/js/jquery.js" [created="[23]"];
"docs/install on windows.md" [created="[500, 501, 502, 503]"];
"src/webroot/templates/default/js/google-code-prettify/prettify.css" [created="[23]"];
"src/templates/default/js/bootstrap-alert.js" [created="[8]"];
"src/modules/books/books_bl.php" [created="[125, 514]"];
"src/webroot/module_holder.php" [created="[51, 89]"];
"src/webroot/templates/default/js/bootstrap-dropdown.js" [created="[23]"];
"src/templates/default/js/README.md" [created="[8]"];
"src/webroot/templates/default/js/bootstrap-typeahead.js" [created="[23]"];
"src/resources/register/register_BL.php" [created="[243]"];
"src/webroot/index.php" [created="[41, 52, 113, 136, 181]"];
"docs/wireframe/my-library.ep" [created="[7]"];
"webroot/uploads/tmp";
"src/functions/base/functions.php" [created="[48]"];
"src/webroot/templates/default/js/bootstrap.min.js" [created="[23]"];
"src/functions/admin/tmp" [created="[44]"];
"src/templates/default/js/bootstrap-carousel.js" [created="[8]"];
"src/modules/recover/tmp" [created="[72, 535]"];
"src/modules/register/content.php" [created="[92, 111]"];
"docs/roadmap/roadmap.md";
"src/resources/authentication/authentication.php" [created="[255, 277, 382, 449, 460, 462]"];
"src/webroot/templates/default/css/bootstrap-responsive.css" [created="[23]"];
"src/resources/admin/admin.php" [created="[403, 414, 419, 484, 487]"];
"src/webroot/templates/default/js/bootstrap-carousel.js" [created="[23]"];
"src/webroot/templates/default/js/bootstrap-collapse.js" [created="[23]"];
"src/modules/books/books.php" [created="[117, 440]"];
"src/functions/user/tmp" [created="[44]"];
"functions/user/tmp" [created="[23, 43]"];
"src/templates/default/js/bootstrap-scrollspy.js" [created="[8]"];
"webroot/style.css";
"src/modules/admin/admin.php" [created="[296, 303, 383, 397, 412, 421, 473, 491]"];
"functions/admin/tmp" [created="[23, 43]"];
"src/webroot/templates/default/js/bootstrap-alert.js" [created="[23]"];
"src/webroot/templates/default/js/google-code-prettify/prettify.js" [created="[23]"];
"src/functions/books/tmp" [created="[44]"];
"src/templates/default/js/bootstrap.min.js" [created="[8]"];
"src/webroot/layout.php" [created="[41, 45, 84]"];
"src/modules/admin/admin_bl.php" [created="[297, 369, 398, 438, 493]"];
"src/webroot/templates/default/css/docs.css" [created="[23]"];
"src/modules/user/tmp";
"src/modules/mysql/tmp";
"src/modules/mysql/connect.php" [created="[91]"];
"src/resources/upload/upload.php" [created="[290, 389]"];
"src/dependency_loader.php" [created="[95]"];
"docs/structure.md" [created="[16, 49]"];
"src/templates/default/js/bootstrap-button.js" [created="[8]"];
"config/mysql_credentials.php-dist" [created="[170]"];
"src/webroot/templates/default/js/README.md" [created="[23]"];
"src/templates/default/js/bootstrap-modal.js" [created="[8]"];
"src/templates/default/index.html" [created="[8]"];
"src/templates/default/js/bootstrap-popover.js" [created="[8]"];
"docs/roadmap/roadmap_gantt.gan" [created="[18]"];
"src/resources/autologin/autologin.php" [created="[241]"];
"src/templates/default/js/bootstrap-transition.js" [created="[8]"];
"src/resources/mysql/mysql.php";
"src/modules/mysql/mysql.php" [created="[82]"];
"src/resources_loader.php" [created="[214]"];
"src/modules/home/home.php" [created="[64]"];
"webroot/index.php";
"src/modules/user/user.php" [created="[141, 164]"];
"README.MD" [created="[0, 1]"];
"src/templates/default/css/docs.css" [created="[8]"];
"docs/features.md" [created="[4]"];
"src/modules/upload/upload_bl.php" [created="[236]"];
"src/templates/default/css/bootstrap-responsive.css" [created="[8]"];
"src/webroot/templates/default/js/application.js" [created="[23]"];
"src/layout.php";
"src/templates/default/js/google-code-prettify/prettify.js" [created="[8]"];
"src/modules/login/login_BL.php" [created="[146]"];
"src/empty" [created="[5, 8]"];
"src/resources/user/user.php" [created="[426, 434, 522]"];
"src/resources/session/session_start.php";
"src/modules/register/validation_mail_content.php" [created="[480]"];
"src/resources/login/login_bl.php" [created="[242]"];
"src/modules/login/login_bl.php";
"src/modules/session/session_destroy.php" [created="[177, 186]"];
"src/pre_process_loader.php" [created="[179]"];
"src/router.php" [created="[78]"];
"src/resources/session/session_destroy.php";
"src/modules/login/tmp" [created="[71, 124]"];
"src/moduleBL_loader.php" [created="[112]"];
"src/webroot/templates/default/js/bootstrap-tab.js" [created="[23]"];
"src/modules/register/register_BL.php" [created="[121, 448]"];
"src/templates/default/js/bootstrap-dropdown.js" [created="[8]"];
"src/module_holder.php";
"src/webroot/templates/default/css/bootstrap.css" [created="[23]"];
"src/modules/upload/upload.php" [created="[235]"];
"src/templates/default/js/jquery.js" [created="[8]"];
"src/templates/default/js/application.js" [created="[8]"];
"todo.txt" [created="[31]"];
"src/style.css" -> "src/webroot/style.css"  [via=99];
"uploads/tmp" -> "webroot/uploads/tmp"  [via=394];
"src/modules/session/session_start.php" -> "src/resources/session/session_start.php"  [via=212];
"src/functions/mysql/tmp" -> "src/modules/mysql/tmp"  [via=64];
"src/modules/base/functions.php" -> "src/resources/base/functions.php"  [via=257];
"docs/roadmap/v0.2.0-v0.4.0.txt" -> "docs/roadmap/roadmap.md"  [via=227];
"src/webroot/style.css" -> "src/style.css"  [via=86];
"src/webroot/style.css" -> "webroot/style.css"  [via=172];
"src/webroot/module_holder.php" -> "src/module_holder.php"  [via=86];
"src/resources/register/register_BL.php" -> "src/modules/register/register_BL.php"  [via=256];
"src/webroot/index.php" -> "webroot/index.php"  [via=172];
"src/functions/admin/tmp" -> "src/modules/admin/tmp"  [via=64];
"src/functions/user/tmp" -> "src/modules/user/tmp"  [via=64];
"src/functions/books/tmp" -> "src/modules/books/tmp"  [via=64];
"src/webroot/layout.php" -> "src/layout.php"  [via=86];
"src/modules/mysql/mysql.php" -> "src/resources/mysql/mysql.php"  [via=211];
"README.MD" -> "README.md"  [via=3];
"src/modules/login/login_BL.php" -> "src/modules/login/login_bl.php"  [via=173];
"src/resources/login/login_bl.php" -> "src/modules/login/login_bl.php"  [via=256];
"src/modules/session/session_destroy.php" -> "src/resources/session/session_destroy.php"  [via=212];
}

In networkx, I create it like this

filegraph = nx.DiGraph()

for cid, commit in enumerate(raw.commits):
    raw_creations = [info['path'] for info in raw.commits[cid]['info'] if info['type'] & RawRepo.TYPE_NEW]
    for path in raw_creations:
        if path in filegraph:
            attrs = filegraph.node[path]
            if 'created' in attrs:
                attrs['created'].append(cid)
            else:
                print("not in created")
        else:
            print("created", path)
            attrs = {'created': [cid]}
        filegraph.add_node(path, attr_dict=attrs)
    raw_renames = {info['from']:info['to'] for info in raw.commits[cid]['info'] if info['type'] & RawRepo.TYPE_RENAME}
    for fr, to in raw_renames.items():
        print("rename",fr,"->",to)
        filegraph.add_edge(fr, to)
        filegraph.edge[fr][to]['via'] = cid
        #filegraph.add_edge(fr, to, attr_dict={'via':cid})

nx.drawing.nx_pydot.write_dot(filegraph, 'filenames.dot')

The other viewer I've tried, ZGRViewer, doesn't show that data either.

Update

With cytoscape 3.0.0-beta1 it gives this error, and a similar error with cytoscape 2.8.3, when importing a GML file exported with networkx as

nx.readwrite.gml.write_gml(filegraph, 'filenames.gml')

The error is

java.text.ParseException: Bad value associated with key modified
        at org.cytoscape.io.internal.read.gml.GMLParser.parseList(GMLParser.java:192)
        at org.cytoscape.io.internal.read.gml.GMLParser.parseValue(GMLParser.java:293)
        at org.cytoscape.io.internal.read.gml.GMLParser.parseList(GMLParser.java:189)
        at org.cytoscape.io.internal.read.gml.GMLParser.parseValue(GMLParser.java:293)
        at org.cytoscape.io.internal.read.gml.GMLParser.parseList(GMLParser.java:189)
        at org.cytoscape.io.internal.read.gml.GMLNetworkReader.run(GMLNetworkReader.java:190)
        at org.cytoscape.work.internal.task.JDialogTaskManager$TaskThread.run(JDialogTaskManager.java:241)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)
pool-11-thread-1 WARN [org.cytoscape.work.internal.task.JDialogTaskManager] - Caught exception executing task.
java.lang.RuntimeException: Bad value associated with key modified
        at org.cytoscape.io.internal.read.gml.GMLNetworkReader.run(GMLNetworkReader.java:193)
        at org.cytoscape.work.internal.task.JDialogTaskManager$TaskThread.run(JDialogTaskManager.java:241)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)

The Error in cytoscape 2.8.3 looks like this:

enter image description here

2

2 Answers

0
votes

For interactive network visualization, manipulation, and analysis, I strongly recommend Cytoscape. It supports edge attributes, has a great UI, and active development community. However, it cannot import .dot files, so if you want to use Cytoscape, you'll need to go back to NetworkX and export as GML, which is easily done from NetworkX.

I should also say that although I haven't used Gephi, it sounded odd to me that it doesn't support edge attributes, and it turns out that it does support edge attributes. You can get some basic insight into this here.

-1
votes

I am using "render" from graphvis.

from graphviz import render

with the next function

nx.drawing.nx_pydot.write_dot(self, filename)
render(engine='dot', format=output_format, filepath=filename)

(the file name is the dot file and the output_format is 'svg' or other good format that can be parsed by regular applicaton). I ususaly use firefox to open the generated svg file.