def merge(args): """ %prog merge graphs Merge multiple graphs together and visualize. """ p = OptionParser(merge.__doc__) p.add_option( "--colorlist", default="black,red,pink,blue,green", help="The color palette", ) opts, args = p.parse_args(args) if len(args) < 1: sys.exit(not p.print_help()) colorlist = opts.colorlist.split(",") assert len(colorlist) >= len(args), "Need more colors in --colorlist" g = BiGraph() for a, c in zip(args, colorlist): g.read(a, color=c) g.draw("merged.png")
def partition(args): """ %prog partition happy.txt synteny.graph Select edges from another graph and merge it with the certain edges built from the HAPPY mapping data. """ allowed_format = ("png", "ps") p = OptionParser(partition.__doc__) p.add_option("--prefix", help="Add prefix to the name [default: %default]") p.add_option("--namestart", default=0, type="int", help="Use a shorter name, starting index [default: %default]") p.add_option("--format", default="png", choices=allowed_format, help="Generate image of format [default: %default]") opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) happyfile, graphfile = args bg = BiGraph() bg.read(graphfile, color="red") prefix = opts.prefix fp = open(happyfile) for i, row in enumerate(fp): nns = happy_nodes(row, prefix=prefix) nodes = set(nns) edges = happy_edges(row, prefix=prefix) small_graph = BiGraph() for e, is_uncertain in edges: if is_uncertain: e.color = "gray" small_graph.add_edge(e) for (u, v), e in bg.edges.items(): # Grab edge if both vertices are on the same line if u in nodes and v in nodes: uv = (str(u), str(v)) if uv in small_graph.edges: e = small_graph.edges[uv] e.color = "blue" # supported by both evidences else: small_graph.add_edge(e) print >> sys.stderr, small_graph pngfile = "A{0:02d}.{1}".format(i + 1, opts.format) telomeres = (nns[0], nns[-1]) small_graph.draw(pngfile, namestart=opts.namestart, nodehighlight=telomeres, dpi=72) legend = ["Edge colors:"] legend.append("[BLUE] Experimental + Synteny") legend.append("[BLACK] Experimental certain") legend.append("[GRAY] Experimental uncertain") legend.append("[RED] Synteny only") legend.append("Rectangle nodes are telomeres.") print >> sys.stderr, "\n".join(legend)
def merge(args): """ %prog merge graphs Merge multiple graphs together and visualize. """ p = OptionParser(merge.__doc__) p.add_option("--colorlist", default="black,red,pink,blue,green", help="The color palette [default: %default]") opts, args = p.parse_args(args) if len(args) < 1: sys.exit(not p.print_help()) colorlist = opts.colorlist.split(",") assert len(colorlist) >= len(args), "Need more colors in --colorlist" g = BiGraph() for a, c in zip(args, colorlist): g.read(a, color=c) g.draw("merged.png")
def partition(args): """ %prog partition happy.txt synteny.graph Select edges from another graph and merge it with the certain edges built from the HAPPY mapping data. """ allowed_format = ("png", "ps") p = OptionParser(partition.__doc__) p.add_option("--prefix", help="Add prefix to the name") p.add_option( "--namestart", default=0, type="int", help="Use a shorter name, starting index", ) p.add_option( "--format", default="png", choices=allowed_format, help="Generate image of format", ) opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) happyfile, graphfile = args bg = BiGraph() bg.read(graphfile, color="red") prefix = opts.prefix fp = open(happyfile) for i, row in enumerate(fp): nns = happy_nodes(row, prefix=prefix) nodes = set(nns) edges = happy_edges(row, prefix=prefix) small_graph = BiGraph() for (a, b, oa, ob), is_uncertain in edges: color = "gray" if is_uncertain else "black" small_graph.add_edge(a, b, oa, ob, color=color) for (u, v), e in bg.edges.items(): # Grab edge if both vertices are on the same line if u in nodes and v in nodes: uv = (str(u), str(v)) if uv in small_graph.edges: e = small_graph.edges[uv] e.color = "blue" # supported by both evidences else: small_graph.add_edge(e) print(small_graph, file=sys.stderr) pngfile = "A{0:02d}.{1}".format(i + 1, opts.format) telomeres = (nns[0], nns[-1]) small_graph.draw( pngfile, namestart=opts.namestart, nodehighlight=telomeres, dpi=72 ) legend = [ "Edge colors:", "[BLUE] Experimental + Synteny", "[BLACK] Experimental certain", "[GRAY] Experimental uncertain", "[RED] Synteny only", "Rectangle nodes are telomeres.", ] print("\n".join(legend), file=sys.stderr)