def write_dot_file(G, filename):
with io.open(filename, "<STR_LIT:w>") as fh:<EOL><INDENT>fh.write("<STR_LIT>")<EOL>edge_list = G.edges()<EOL>node_list = set(G.nodes())<EOL>if edge_list:<EOL><INDENT>for edge in sorted(edge_list):<EOL><INDENT>source, targ = edge<EOL>node_list = node_list - set(source)<EOL>node_list = node_list - set(targ)<EOL>line = '<STR_LIT>'<EOL>fh.write(line.format(source, targ))<EOL><DEDENT><DEDENT>if node_list:<EOL><INDENT>for node in sorted(node_list):<EOL><INDENT>line = '<STR_LIT>'.format(node)<EOL>fh.write(line)<EOL><DEDENT><DEDENT>fh.write("<STR_LIT:}>")<EOL><DEDENT>
Writes the graph G in dot file format for graphviz visualization.

Args:
    a Networkx graph
    A filename to name the dot files