Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
root.text((na + nb) / 2, .54, "ChrC02", ha="center")
HorizontalChromosome(root, na, nb, .5, height=.025,
fc=lsg, fill=True)
order = Bed(bed).order
fp = open(deletions)
scale = lambda x: na + x * (nb - na) / 52886895
for i, row in enumerate(fp):
i += 1
num, genes = row.split()
genes = genes.split("|")
ia, a = order[genes[0]]
ib, b = order[genes[-1]]
mi, mx = a.start, a.end
mi, mx = scale(mi), scale(mx)
root.add_patch(Rectangle((mi, .475), mx - mi, .05,
fc="red", ec="red"))
if i == 1: # offset between two adjacent regions for aesthetics
mi -= .015
elif i == 2:
mi += .015
TextCircle(root, mi, .44, str(i), fc="red")
for i, mi in zip(range(1, 4), (.83, .78, .73)):
TextCircle(root, mi, .2, str(i), fc="red")
root.set_xlim(0, 1)
root.set_ylim(0, 1)
root.set_axis_off()
image_name = deletion_genes + ".pdf"
savefig(image_name, dpi=iopts.dpi, iopts=iopts)
ax.plot((p, p), (.5, .5 - tick), "k-")
ax.text(p, .5 - 2.5 * tick, str(mya), ha="center", va="center")
ax.text((a + b) / 2, .5 - 5 * tick, "Time before present (million years)",
ha="center", va="center")
# Source:
# http://www.weston.org/schools/ms/biologyweb/evolution/handouts/GSAchron09.jpg
Geo = (("Neogene", 2.6, 23.0, "#fee400"),
("Paleogene", 23.0, 65.5, "#ff9a65"),
("Cretaceous", 65.5, 145.5, "#80ff40"),
("Jurassic", 145.5, 201.6, "#33fff3"))
h = .05
for era, start, end, color in Geo:
start, end = cv(start), cv(end)
end = max(a, end)
p = Rectangle((end, .5 + tick / 2), abs(start - end),
h, lw=1, ec="w", fc=color)
ax.text((start + end) / 2, .5 + (tick + h) / 2, era,
ha="center", va="center", size=9)
ax.add_patch(p)
logging.debug("xsize=%d ysize=%d" % (xsize, ysize))
qbreaks = qbed.get_breaks()
sbreaks = sbed.get_breaks()
xlim, ylim = plot_breaks_and_labels(fig, root, ax, gx, gy, xsize, ysize,
qbreaks, sbreaks, sep=sep, chrlw=chrlw,
sepcolor=sepcolor, minfont=minfont, stdpf=stdpf, chpf=chpf)
# create a diagonal to separate mirror image for self comparison
if is_self:
ax.plot(xlim, (0, ysize), 'm-', alpha=.5, lw=2)
if palette: # bottom-left has the palette, if available
colors = palette.colors
xstart, ystart = .1, .05
for category, c in sorted(colors.items()):
root.add_patch(Rectangle((xstart, ystart), .03, .02, lw=0, fc=c))
root.text(xstart + .04, ystart, category, color=c)
xstart += .1
if title is None:
title = "Inter-genomic comparison: {0} vs {1}".format(gx, gy)
if is_self:
title = "Intra-genomic comparison within {0}".format(gx)
npairs /= 2
title += " ({0} gene pairs)".format(thousands(npairs))
root.set_title(title, x=.5, y=.96, color="k")
if title:
logging.debug("Dot plot title: {}".format(title))
normalize_axes(root)
ax4.text(.1, .86, "Label: {0}".format(latex(accession)), color='m')
yy = .8
fw = must_open(opts.outfile, "w")
if not opts.noheader:
print(Seed.header(calibrate=calib), file=fw)
for o in objects:
if calib:
o.calibrate(pixel_cm_ratio, tr)
print(o, file=fw)
i = o.seedno
if i > 7:
continue
ax4.text(.01, yy, str(i), va="center", bbox=dict(fc='none', ec='k'))
ax4.text(.1, yy, o.pixeltag, va="center")
yy -= .04
ax4.add_patch(Rectangle((.1, yy - .025), .12, .05, lw=0,
fc=rgb_to_hex(o.rgb)))
ax4.text(.27, yy, o.hashtag, va="center")
yy -= .06
ax4.text(.1 , yy, "(A total of {0} objects displayed)".format(nb_labels),
color="darkslategray")
normalize_axes(ax4)
for ax in (ax1, ax2, ax3):
xticklabels = [int(x) for x in ax.get_xticks()]
yticklabels = [int(x) for x in ax.get_yticks()]
ax.set_xticklabels(xticklabels, family='Helvetica', size=8)
ax.set_yticklabels(yticklabels, family='Helvetica', size=8)
image_name = op.join(outdir, pf + "." + iopts.format)
savefig(image_name, dpi=iopts.dpi, iopts=iopts)
return objects
coords['d'] = (x + 1.5 * mgap , y)
coords['ab'] = join_nodes_vertical(root, coords, 'a', 'b', y + ygap / 2)
coords['cd'] = join_nodes_vertical(root, coords, 'c', 'd', y + ygap / 2)
coords['abcd'] = join_nodes_vertical(root, coords, 'ab', 'cd', y + ygap)
for n in 'abcd':
nx, ny = coords[n]
root.text(nx, ny - tip, n, ha="center")
coords[n] = (nx, ny - ygap / 2)
kdata = regions.get_karyotype(k)
for kd in kdata:
g = kd.group
gx, gy = coords[g]
gsize = ratio * kd.span
gy -= gsize
p = Rectangle((gx - gwidth / 2, gy),
gwidth, gsize, lw=0, color=set2[i])
root.add_patch(p)
root.text(gx, gy + gsize / 2, kd.chromosome,
ha="center", va="center", color='w')
coords[g] = (gx, gy - tip)
# Bottom panel shows the location of segments on chromosomes
# TODO: redundant code, similar to graphics.chromosome
ystart = .54
chr_number = len(sizes)
xstart, xend = xgap - 2 * mgap, 1 - xgap + 2 * mgap
xinterval = (xend - xstart - gwidth) / (chr_number - 1)
chrpos = {}
for a, (chr, clen) in enumerate(sorted(sizes.items())):
chr = get_number(chr)
xx = xstart + a * xinterval + gwidth / 2
mrange = 650.
m = lambda x: x / mrange * .7 + .1
for i, (ya, title) in enumerate(zip(titlepos, titles)):
yb = ya - .1
plt.plot((.1, .8), (ya, ya), "-", color="gray", lw=2, zorder=1)
plt.plot((.1, .8), (yb, yb), "-", color="gray", lw=2, zorder=1)
RoundLabel(root, .5, ya + 4 * ytip, title)
root.text(.9, ya, "A. thaliana", ha="center", va="center")
root.text(.9, yb, "B. rapa", ha="center", va="center")
myhsps = hsps
if i >= 1:
myhsps = hsps[:-1]
for (a, b), (c, d) in myhsps:
a, b, c, d = [m(x) for x in (a, b, c, d)]
r1 = Rectangle((a, ya - ytip), b - a, 2 * ytip, fc='r', lw=0, zorder=2)
r2 = Rectangle((c, yb - ytip), d - c, 2 * ytip, fc='r', lw=0, zorder=2)
r3 = Rectangle((a, ya - ytip), b - a, 2 * ytip, fill=False, zorder=3)
r4 = Rectangle((c, yb - ytip), d - c, 2 * ytip, fill=False, zorder=3)
r5 = Polygon(((a, ya - ytip), (c, yb + ytip),
(d, yb + ytip), (b, ya - ytip)),
fc='r', alpha=.2)
rr = (r1, r2, r3, r4, r5)
if i == 2:
rr = rr[:-1]
for r in rr:
root.add_patch(r)
# Gap pairs
hspa, hspb = zip(*myhsps)
gapa, gapb = [], []
for (a, b), (c, d) in pairwise(hspa):
gapa.append((b + 1, c - 1))
pos = .9 - pos * .8 / ysize
root.text(.91, pos, label, size=10,
va="center", color="grey")
# Highlight regions based on a list of BedLine
qhighlights = shighlights = None
if highlights:
if isinstance(highlights[0], BedLine):
shighlights = highlights
elif len(highlights) == 2:
qhighlights, shighlights = highlights
if qhighlights:
for hl in qhighlights:
hls = qsizes.get_position(hl.seqid, hl.start)
ax.add_patch(Rectangle((hls, 0), hl.span, ysize,\
fc="r", alpha=.2, lw=0))
if shighlights:
for hl in shighlights:
hls = ssizes.get_position(hl.seqid, hl.start)
ax.add_patch(Rectangle((0, hls), xsize, hl.span, \
fc="r", alpha=.2, lw=0))
if baseticks:
def increaseDensity(a, ratio=4):
assert len(a) > 1
stepsize = a[1] - a[0]
newstepsize = int(stepsize / ratio)
return np.arange(0, a[-1], newstepsize)
# Increase the density of the ticks
xticks = ax.get_xticks()
scale = width * 1. / chromsize
xstart, ystart = (1 - width) / 2, ymid - height / 2
bp_to_pos = lambda x: xstart + x * scale
in_acen = False
for chr, start, end, name, gie in data:
color, alpha = get_color(gie)
bplen = end - start
if "acen" in gie:
if in_acen:
xys = [(bp_to_pos(start), ymid), (bp_to_pos(end), ystart), (bp_to_pos(end), ystart + height)]
else:
xys = [(bp_to_pos(start), ystart), (bp_to_pos(start), ystart + height), (bp_to_pos(end), ymid)]
p = Polygon(xys, closed=True, ec='k', fc=color, alpha=alpha)
in_acen = True
else:
p = Rectangle((bp_to_pos(start), ystart), bplen * scale, height,
ec='k', fc=color, alpha=alpha)
#print bp_to_pos(end)
ax.add_patch(p)
ax.text(bp_to_pos((start + end) / 2), ymid + height * .8, name, rotation=40, color="lightslategray")
ax.text(.5, ystart - height, chrom, size=16, ha="center", va="center")
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_axis_off()