Search code examples
pythonnetworkxgmlcytoscape

Networkx parse gml writing unusable gml files


I've been trying to parse in some additional attributes to a networkx gml for use later on, and I've run into an issue.

When given a gml file from Cytoscape, networkx outputs a gml file that it itself can't read.

I.e. Cytoscape -> Into networkx -> Output -> Into networkx -> Error:

pyparsing.ParseException: Expected "]" (at char 1116756), (line:71732, col:3)

Now that error requests an additional ] after the nodes (AKA making the graph ignore the edges), if you do this, the graph works. However, it no longer has any edges.

To fully test this I did the 'Cytoscape -> Into networkx -> Output' without changing the code at all, just:

DG = nx.read_gml("KeggComplete.gml", relabel = True)
nx.write_gml(DG, "KeggCompleteEng.gml")
exit()

and then read in with:

BasicGraph = nx.read_gml("KeggCompleteEng.gml", relabel = True)

And the error is still reproducible. So I assume it's to do with how networkx is writing gml files.

The two files I'm using are:

If someone could give some insight into why this might be happening it would be most appreciated!


Solution

  • This is a bug in NetworkX when generating nested attributes (edge graphics data in this case). An extra set of quotes was incorrectly added to the "Line" attribute.

    The fix has been merged as part of this pull request: https://github.com/networkx/networkx/pull/981