def __init__(self, ax, x, y1, y2, y3, width=.015, fc="k", fill=False, zorder=2): """ Chromosome with centromeres at y2 position """ pts = [] r = width * .5 pts += plot_cap((x, y1 - r), np.radians(range(180)), r) pts += [[x - r, y1 - r], [x - r, y2 + r]] pts += plot_cap((x, y2 + r), np.radians(range(180, 360)), r) pts += [[x + r, y2 + r], [x + r, y1 - r]] ax.add_patch(Polygon(pts, fc=fc, fill=fill, zorder=zorder)) pts = [] pts += plot_cap((x, y2 - r), np.radians(range(180)), r) pts += [[x - r, y2 - r], [x - r, y3 + r]] pts += plot_cap((x, y3 + r), np.radians(range(180, 360)), r) pts += [[x + r, y3 + r], [x + r, y2 - r]] ax.add_patch(Polygon(pts, fc=fc, fill=fill, zorder=zorder)) ax.add_patch( CirclePolygon((x, y2), radius=r * .5, fc="k", ec="k", zorder=zorder))
def __init__(self, ax, x, y, label, radius=.02, fc="k", color="w", size=12, zorder=4, **kwargs): circle = CirclePolygon((x, y), radius, resolution=20, \ fc=fc, ec=fc, zorder=zorder, **kwargs) ax.add_patch(circle) ax.text(x, y, label, ha="center", va="center", color=color, size=size, zorder=zorder + 1, **kwargs)
def excision(args): """ %prog excision Illustrate the mechanism of illegitimate recombination. """ p = OptionParser(__doc__) opts, args = p.parse_args(args) fig = plt.figure(1, (5, 5)) root = fig.add_axes([0, 0, 1, 1]) plt.plot((0.2, 0.8), (0.6, 0.6), "r-", lw=3) plt.plot((0.4, 0.6), (0.6, 0.6), "b>-", mfc="g", mec="w", ms=12, lw=3) plt.plot((0.3, 0.7), (0.5, 0.5), "r-", lw=3) plt.plot((0.5, ), (0.5, ), "b>-", mfc="g", mec="w", ms=12, lw=3) # Circle excision plt.plot((0.5, ), (0.45, ), "b>-", mfc="g", mec="w", ms=12, lw=3) circle = CirclePolygon((0.5, 0.4), 0.05, fill=False, lw=3, ec="b") root.add_patch(circle) arrow_dist = 0.07 ar_xpos, ar_ypos = 0.5, 0.52 root.annotate(" ", (ar_xpos, ar_ypos), (ar_xpos, ar_ypos + arrow_dist), arrowprops=arrowprops) RoundLabel(root, 0.2, 0.64, "Gene") RoundLabel(root, 0.3, 0.54, "Excision") root.set_xlim(0, 1) root.set_ylim(0, 1) root.set_axis_off() figname = fname() + ".pdf" savefig(figname, dpi=300)
def __init__(self, ax, x, y, radius=.01, **kwargs): ax.add_patch( CirclePolygon((x, y), radius * 1.4, resolution=50, fc="w", ec="k")) ax.add_patch(CirclePolygon((x, y), radius, resolution=50, **kwargs))
def heatmap(args): """ %prog heatmap fastafile chr1 Combine stack plot with heatmap to show abundance of various tracks along given chromosome. Need to give multiple beds to --stacks and --heatmaps """ p = OptionParser(heatmap.__doc__) p.add_option( "--stacks", default="Exons,Introns,DNA_transposons,Retrotransposons", help="Features to plot in stackplot", ) p.add_option( "--heatmaps", default="Copia,Gypsy,hAT,Helitron,Introns,Exons", help="Features to plot in heatmaps", ) p.add_option("--meres", default=None, help="Extra centromere / telomere features") add_window_options(p) opts, args, iopts = p.set_image_options(args, figsize="8x5") if len(args) != 2: sys.exit(not p.print_help()) fastafile, chr = args window, shift, subtract, merge = check_window_options(opts) stacks = opts.stacks.split(",") heatmaps = opts.heatmaps.split(",") stackbeds = get_beds(stacks) heatmapbeds = get_beds(heatmaps) stackbins = get_binfiles(stackbeds, fastafile, shift, subtract=subtract, merge=merge) heatmapbins = get_binfiles(heatmapbeds, fastafile, shift, subtract=subtract, merge=merge) margin = 0.06 inner = 0.015 clen = Sizes(fastafile).mapping[chr] fig = plt.figure(1, (iopts.w, iopts.h)) root = fig.add_axes([0, 0, 1, 1]) # Gauge ratio = draw_gauge(root, margin, clen, rightmargin=4 * margin) yinterval = 0.3 xx = margin yy = 1 - margin yy -= yinterval xlen = clen / ratio cc = chr if "_" in chr: ca, cb = chr.split("_") cc = ca[0].upper() + cb root.add_patch(Rectangle((xx, yy), xlen, yinterval - inner, color=gray)) ax = fig.add_axes([xx, yy, xlen, yinterval - inner]) nbins = get_nbins(clen, shift) owindow = clen / 100 if owindow > window: window = owindow / shift * shift stackplot(ax, stackbins, nbins, palette, chr, window, shift) ax.text( 0.1, 0.9, cc, va="top", zorder=100, transform=ax.transAxes, bbox=dict(boxstyle="round", fc="w", alpha=0.5), ) # Legends xx += xlen + 0.01 yspace = (yinterval - inner) / (len(stackbins) + 1) yy = 1 - margin - yinterval for s, p in zip(stacks, palette): s = s.replace("_", " ") s = Registration.get(s, s) yy += yspace root.add_patch(Rectangle((xx, yy), inner, inner, color=p, lw=0)) root.text(xx + 1.5 * inner, yy, s, size=10) yh = 0.05 # Heatmap height # Heatmaps xx = margin yy = 1 - margin - yinterval - inner for s, p in zip(heatmaps, heatmapbins): s = s.replace("_", " ") s = Registration.get(s, s) yy -= yh m = stackarray(p, chr, window, shift) Y = np.array([m, m]) root.imshow( Y, extent=(xx, xx + xlen, yy, yy + yh - inner), interpolation="nearest", aspect="auto", cmap=iopts.cmap, ) root.text(xx + xlen + 0.01, yy, s, size=10) yy -= yh meres = opts.meres if meres: bed = Bed(meres) for b in bed: if b.seqid != chr: continue pos = (b.start + b.end) / 2 cpos = pos / ratio xx = margin + cpos accn = b.accn.capitalize() root.add_patch(CirclePolygon((xx, yy), radius=0.01, fc="m", ec="m")) root.text(xx + 0.014, yy, accn, va="center", color="m") root.set_xlim(0, 1) root.set_ylim(0, 1) root.set_axis_off() image_name = chr + "." + iopts.format savefig(image_name, dpi=iopts.dpi, iopts=iopts)
def __init__(self, ax, x, y, label, radius=.02, fc="k", color="w"): circle = CirclePolygon((x, y), radius, resolution=20, fc=fc, ec=fc) ax.add_patch(circle) ax.text(x, y, label, ha="center", va="center", color=color)