DaylightingSociety / SocMap

Social Mapping Framework for Twitter
https://socmap.daylightingsociety.org/
BSD 3-Clause "New" or "Revised" License
18 stars 4 forks source link

Patch NetworkX GML files #6

Closed milo-trujillo closed 6 years ago

milo-trujillo commented 6 years ago

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.

milo-trujillo commented 6 years ago

Implemented and pushed.