Networkx parse gml writing unusable gml files

2019-08-15 03:07发布

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!

2条回答
手持菜刀,她持情操
2楼-- · 2019-08-15 03:53

Pyparsing is not the smartest library when it comes to identifying when parsing errors occur. More recent versions of the library do support some better error identification, but they require some updates to the parsers to get this information.

Without seeing the parser, from your description, it sounds like the parser expects to see something like:

[
  [
  bunch of nodes...
  ]
  [
  optional bunch of edges...
  ]
]

What happens is that it successfully gets past the "bunch of nodes...", then finds some syntax problem in one of the edges in the "optional bunch of edges..." part. Since this is optional, things would still be valid if only there was a closing ']' after the nodes. That's why you get that pyparsing exception message. But the real problem is that one of the edges has a typo.

To diagnose this, try giving the parser just the first few edges. Then keep adding more and more edges until you get the pyparsing error - the most recently added edges contain the critical syntax error.

查看更多
ら.Afraid
3楼-- · 2019-08-15 03:58

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

查看更多
登录 后发表回答