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 get_pts(self, x, y1, y2, width): w = width / 2 r = width / (3**.5) pts = [] pts += plot_cap((x, y1 + r), np.radians(range(210, 330)), r) pts += [[x + w, y1 + r / 2], [x + w, y2 - r / 2]] pts += plot_cap((x, y2 - r), np.radians(range(30, 150)), r) pts += [[x - w, y2 - r / 2], [x - w, y1 + r / 2]] return pts, r
def get_pts(self, x, y1, y2, width): w = width / 2 r = width / (3 ** .5) pts = [] pts += plot_cap((x, y1 + r), np.radians(range(210, 330)), r) pts += [[x + w, y1 + r / 2], [x + w, y2 - r / 2]] pts += plot_cap((x, y2 - r), np.radians(range(30, 150)), r) pts += [[x - w, y2 - r / 2], [x - w, y1 + r / 2]] return pts, r
def __init__(self, ax, x, y1, y2, width=.015, fc="k", fill=False, zorder=2): """ Chromosome with positions given in (x, y1) => (x, y2) """ 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))
def get_pts(self, x1, x2, y, height): h = height / 2 r = height / (3**.5) if x2 - x1 < 2 * height: # rectangle for small chromosomes return [[x1, y + h], [x1, y - h], [x2, y - h], [x2, y + h]], r pts = [] pts += plot_cap((x1 + r, y), np.radians(range(120, 240)), r) pts += [[x1 + r / 2, y - h], [x2 - r / 2, y - h]] pts += plot_cap((x2 - r, y), np.radians(range(-60, 60)), r) pts += [[x2 - r / 2, y + h], [x1 + r / 2, y + h]] return pts, r
def get_pts(self, x1, x2, y, height): h = height / 2 r = height / (3 ** .5) if x2 - x1 < 2 * height: # rectangle for small chromosomes return [[x1, y + h], [x1, y - h], [x2, y - h], [x2, y + h]], r pts = [] pts += plot_cap((x1 + r, y), np.radians(range(120, 240)), r) pts += [[x1 + r / 2, y - h], [x2 - r / 2, y - h]] pts += plot_cap((x2 - r, y), np.radians(range(-60, 60)), r) pts += [[x2 - r / 2, y + h], [x1 + r / 2, y + h]] return pts, r
def __init__(self, ax, x, y1, y2, y3, width=0.015, fc="k", fill=False, zorder=2): """ Chromosome with centromeres at y2 position """ pts = [] r = width * 0.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 * 0.5, fc="k", ec="k", zorder=zorder))
def amborella(args): """ %prog amborella seqids karyotype.layout mcscan.out all.bed synteny.layout Build a composite figure that calls graphics.karyotype and graphics.synteny. """ p = OptionParser(amborella.__doc__) p.add_option( "--tree", help="Display trees on the bottom of the figure [default: %default]") p.add_option( "--switch", help="Rename the seqid with two-column file [default: %default]") opts, args, iopts = p.set_image_options(args, figsize="8x7") if len(args) != 5: sys.exit(not p.print_help()) seqidsfile, klayout, datafile, bedfile, slayout = args switch = opts.switch tree = opts.tree fig = plt.figure(1, (iopts.w, iopts.h)) root = fig.add_axes([0, 0, 1, 1]) Karyotype(fig, root, seqidsfile, klayout) Synteny(fig, root, datafile, bedfile, slayout, switch=switch, tree=tree) # legend showing the orientation of the genes draw_gene_legend(root, .5, .68, .5) # annotate the WGD events fc = 'lightslategrey' x = .05 radius = .012 TextCircle(root, x, .86, '$\gamma$', radius=radius) TextCircle(root, x, .95, '$\epsilon$', radius=radius) root.plot([x, x], [.83, .9], ":", color=fc, lw=2) pts = plot_cap((x, .95), np.radians(range(-70, 250)), .02) x, y = zip(*pts) root.plot(x, y, ":", color=fc, lw=2) root.set_xlim(0, 1) root.set_ylim(0, 1) root.set_axis_off() pf = "amborella" image_name = pf + "." + iopts.format savefig(image_name, dpi=iopts.dpi, iopts=iopts)
def amborella(args): """ %prog amborella seqids karyotype.layout mcscan.out all.bed synteny.layout Build a composite figure that calls graphics.karyotype and graphics.synteny. """ p = OptionParser(amborella.__doc__) p.add_option("--tree", help="Display trees on the bottom of the figure [default: %default]") p.add_option("--switch", help="Rename the seqid with two-column file [default: %default]") opts, args, iopts = p.set_image_options(args, figsize="8x7") if len(args) != 5: sys.exit(not p.print_help()) seqidsfile, klayout, datafile, bedfile, slayout = args switch = opts.switch tree = opts.tree fig = plt.figure(1, (iopts.w, iopts.h)) root = fig.add_axes([0, 0, 1, 1]) Karyotype(fig, root, seqidsfile, klayout) Synteny(fig, root, datafile, bedfile, slayout, switch=switch, tree=tree) # legend showing the orientation of the genes draw_gene_legend(root, .5, .68, .5) # annotate the WGD events fc = 'lightslategrey' x = .05 radius = .012 TextCircle(root, x, .86, '$\gamma$', radius=radius) TextCircle(root, x, .95, '$\epsilon$', radius=radius) root.plot([x, x], [.83, .9], ":", color=fc, lw=2) pts = plot_cap((x, .95), np.radians(range(-70, 250)), .02) x, y = zip(*pts) root.plot(x, y, ":", color=fc, lw=2) root.set_xlim(0, 1) root.set_ylim(0, 1) root.set_axis_off() pf = "amborella" image_name = pf + "." + iopts.format savefig(image_name, dpi=iopts.dpi, iopts=iopts)