def write_xgmml(G, filename, name='THAPBI PICT edit-graph'):
    """Save graph in XGMML format suitable for Cytoscape import."""
    with open(filename, 'w') as handle:
        handle.write(
            '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n')
        handle.write(
            """<graph directed="0"  xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.cs.rpi.edu/XGMML">
"""
            )
        for n in G:
            node = G.nodes[n]
            try:
                label = node['label'].replace('\n', ';')
            except KeyError:
                label = None
            if not label:
                label = '{%s}' % n[:6]
            handle.write(f'  <node id="{n}" label="{label}">\n')
            color = node['color']
            size = node['size'] * 0.45 + 5.0
            handle.write(
                """    <graphics type="CIRCLE" fill="%s" outline="#000000" h="%0.2f" w="%0.2f"/>
"""
                 % (color, size, size))
            handle.write(f'    <att type="string" name="MD5" value="{n}"/>\n')
            handle.write(
                '    <att type="integer" name="Total-abundance" value="%i"/>\n'
                 % node.get('total_abundance', 0))
            handle.write(
                '    <att type="integer" name="Max-sample-abundance" value="%i"/>\n'
                 % node.get('max_sample_abundance', 0))
            handle.write(
                '    <att type="integer" name="Sample-count" value="%i"/>\n' %
                node.get('sample_count', 0))
            if node['genus']:
                handle.write(
                    '    <att type="string" name="Genus" value="%s"/>\n' %
                    node['genus'])
            if node['taxonomy']:
                handle.write(
                    '    <att type="string" name="Taxonomy" value="%s"/>\n' %
                    node['taxonomy'])
            handle.write('  </node>\n')
        for n1, n2 in G.edges():
            edge = G.edges[n1, n2]
            handle.write(
                '  <edge source="%s" target="%s" weight="%0.2f">\n' % (n1,
                n2, edge['weight']))
            handle.write('    <graphics fill="%s" width="%0.1f"/>\n' % (
                edge['color'], edge['width']))
            if 'edit_dist' in edge:
                handle.write(
                    '    <att type="integer" name="Edit-distance" value="%i"/>\n'
                     % edge['edit_dist'])
            handle.write(
                '    <att type="integer" name="Edit-distance-weight" value="%i"/>\n'
                 % edge['weight'])
            handle.write('  </edge>\n')
        handle.write('</graph>\n')
