NetworkX produces GML files that include a numeric label on each node. These may be valid for the GML specification, but they are not readable by CytoScape. CytoScape is bomb, and we want to support opening our files in that tool. Therefore, we need to patch the GML files and remove the numeric labels. Here's an example function that does the job:
def patch_gml(filename):
with open(filename, "r+") as f:
content = f.read()
newcontent = re.sub("label (\S+)\s+", r'', content)
f.seek(0, 0)
f.truncate()
f.write(newcontent)
Once we begin working with very large GML files we may need something more efficient than "Put entire GML file in a string, apply regex, save back out to file", but the idea is the same.
NetworkX produces GML files that include a numeric
label
on each node. These may be valid for the GML specification, but they are not readable by CytoScape. CytoScape is bomb, and we want to support opening our files in that tool. Therefore, we need to patch the GML files and remove the numeric labels. Here's an example function that does the job:Once we begin working with very large GML files we may need something more efficient than "Put entire GML file in a string, apply regex, save back out to file", but the idea is the same.