Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
p.set_outfile(outfile="Ks_plot.pdf")
add_plot_options(p)
opts, args, iopts = p.set_image_options(args, figsize="6x6")
if len(args) != 1:
sys.exit(not p.print_help())
layoutfile, = args
ks_min = opts.vmin
ks_max = opts.vmax
bins = opts.bins
fill = opts.fill
layout = Layout(layoutfile)
print(layout, file=sys.stderr)
fig = plt.figure(1, (iopts.w, iopts.h))
ax = fig.add_axes([.12, .1, .8, .8])
kp = KsPlot(ax, ks_max, bins, legendp=opts.legendp)
for lo in layout:
data = KsFile(lo.ksfile)
data = [x.ng_ks for x in data]
data = [x for x in data if ks_min <= x <= ks_max]
kp.add_data(data, lo.components, label=lo.label, \
color=lo.color, marker=lo.marker,
fill=fill, fitted=opts.fit)
kp.draw(title=opts.title, filename=opts.outfile)
args, figsize="16x8", style="white", cmap="coolwarm", format="png", dpi=120
)
if len(args) != 3:
sys.exit(not p.print_help())
tour, clmfile, anchorsfile = args
tour = tour.split(",")
image_name = opts.outfile or ("movieframe." + iopts.format)
label = opts.label or op.basename(image_name).rsplit(".", 1)[0]
clm = CLMFile(clmfile)
totalbins, bins, breaks = make_bins(tour, clm.tig_to_size)
M = read_clm(clm, totalbins, bins)
fig = plt.figure(1, (iopts.w, iopts.h))
root = fig.add_axes([0, 0, 1, 1]) # whole canvas
ax1 = fig.add_axes([0.05, 0.1, 0.4, 0.8]) # heatmap
ax2 = fig.add_axes([0.55, 0.1, 0.4, 0.8]) # dot plot
ax2_root = fig.add_axes([0.5, 0, 0.5, 1]) # dot plot canvas
# Left axis: heatmap
plot_heatmap(ax1, M, breaks, iopts)
# Right axis: synteny
qbed, sbed, qorder, sorder, is_self = check_beds(anchorsfile, p, opts, sorted=False)
dotplot(anchorsfile, qbed, sbed, fig, ax2_root, ax2, sep=False, title="")
root.text(0.5, 0.98, clm.name, color="g", ha="center", va="center")
root.text(0.5, 0.95, label, color="darkslategray", ha="center", va="center")
normalize_axes(root)
savefig(image_name, dpi=iopts.dpi, iopts=iopts)
def main():
p = OptionParser(__doc__)
p.add_option("--customfont", default="Airswing.ttf", choices=available_fonts,
help="Custom font name")
p.add_option("--color", default="limegreen",
help="Font color [default: %default]")
p.add_option("--size", default=36, type="int",
help="Font size [default: %default]")
opts, args, iopts = p.set_image_options(figsize='2x1', dpi=60, format='png')
if len(args) != 1:
sys.exit(not p.print_help())
text, = args
plt.rcdefaults()
fig = plt.figure(1, (iopts.w, iopts.h))
ax = fig.add_axes([0, 0, 1, 1])
ax.text(.5, .5, text, color=opts.color, ha="center", va="center")
fontprop(ax, opts.customfont, size=opts.size)
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_axis_off()
image_name = text + "." + iopts.format
savefig(image_name, dpi=iopts.dpi, iopts=iopts)
,Duos - Mendelian errors,Trios - Mendelian errors
SCA36,1.40%,0.60%
ULD,0.30%,1.50%
BPES,0.00%,1.80%
One TRED disease per line, followed by duo errors and trio errors.
"""
p = OptionParser(mendelian_errors.__doc__)
opts, args, iopts = p.set_image_options(args, figsize="6x6")
if len(args) != 1:
sys.exit(not p.print_help())
csvfile, = args
fig, ax = plt.subplots(ncols=1, nrows=1,
figsize=(iopts.w, iopts.h))
root = fig.add_axes([0, 0, 1, 1])
ymin = -.2
df = pd.read_csv(csvfile)
data = []
for i, d in df.iterrows():
if d['TRED'].split()[0] in ignore:
logging.debug("Ignore {}".format(d['TRED']))
continue
data.append(d)
treds, duos, trios = zip(*data)
ntreds = len(treds)
ticks = range(ntreds)
treds = [x.split()[0] for x in treds]
duos = [float(x.rstrip('%')) for x in duos]
linebeds = get_beds(lines)
if opts.bars:
bars = opts.bars.split(",")
barbeds = get_beds(bars)
if opts.altbars:
altbars = opts.altbars.split(",")
altbarbeds = get_beds(altbars)
linebins = get_binfiles(linebeds, fastafile, shift,
mode=opts.mode, merge=merge)
margin = .12
clen = Sizes(fastafile).mapping[chr]
nbins = get_nbins(clen, shift)
plt.rcParams["xtick.major.size"] = 0
plt.rcParams["ytick.major.size"] = 0
fig = plt.figure(1, (iopts.w, iopts.h))
root = fig.add_axes([0, 0, 1, 1])
root.text(.5, .95, chr, ha="center", color="darkslategray")
xstart, xend = margin, 1 - margin
xlen = xend - xstart
ratio = xlen / clen
# Line plots
ax = fig.add_axes([xstart, .6, xlen, .3])
lineplot(ax, linebins, nbins, chr, window, shift)
# Bar plots
yy = .5
M = symmetrize(M)
logging.debug("Write LD matrix to file `{0}`.".format(ldmatrix))
M.tofile(ldmatrix)
else:
nmarkers = len(Bed(markerbedfile))
M = np.fromfile(ldmatrix, dtype="float").reshape(nmarkers, nmarkers)
logging.debug("LD matrix `{0}` exists ({1}x{1})."\
.format(ldmatrix, nmarkers))
from jcvi.graphics.base import plt, savefig, Rectangle, draw_cmap
plt.rcParams["axes.linewidth"] = 0
fig = plt.figure(1, (iopts.w, iopts.h))
root = fig.add_axes([0, 0, 1, 1])
ax = fig.add_axes([.1, .1, .8, .8]) # the heatmap
ax.matshow(M, cmap=iopts.cmap)
# Plot chromosomes breaks
bed = Bed(markerbedfile)
xsize = len(bed)
extent = (0, nmarkers)
chr_labels = []
ignore_size = 20
for (seqid, beg, end) in bed.get_breaks():
ignore = abs(end - beg) < ignore_size
pos = (beg + end) / 2
chr_labels.append((seqid, pos, ignore))
def composite_ccn(df, size=(12, 8)):
""" Plot composite ccn figure
"""
fig = plt.figure(1, size)
ax1 = plt.subplot2grid((2, 2), (0, 0))
ax2 = plt.subplot2grid((2, 2), (0, 1))
ax3 = plt.subplot2grid((2, 2), (1, 0))
ax4 = plt.subplot2grid((2, 2), (1, 1))
chemistry = ["V1", "V2", "V2.5", float("nan")]
colors = sns.color_palette("Set2", 8)
color_map = dict(zip(chemistry, colors))
mf = df[df["hli_calc_gender"] == "Male"]
age_label = "Chronological age (yr)"
ax1.scatter(mf["hli_calc_age_sample_taken"], mf["ccn.chrX"],
s=10, marker='.',
color='lightslategray')
ax1.set_ylim(0.8, 1.1)
plot_fit_line(ax1, mf["hli_calc_age_sample_taken"], mf["ccn.chrX"])
ax1.set_ylabel("ChrX copy number")
qbed = Bed(qbed)
if sbed:
ssizes = ssizes or sizes([sbed])
sbed = Bed(sbed)
assert qsizes and ssizes, \
"You must specify at least one of --sizes of --bed"
qsizes = Sizes(qsizes, select=opts.qselect)
ssizes = Sizes(ssizes, select=opts.sselect)
blastfile, = args
image_name = op.splitext(blastfile)[0] + "." + opts.format
plt.rcParams["xtick.major.pad"] = 16
plt.rcParams["ytick.major.pad"] = 16
# Fix the width
xsize, ysize = qsizes.totalsize, ssizes.totalsize
# get highlight beds
qh, sh = opts.qh, opts.sh
qh = Bed(qh) if qh else None
sh = Bed(sh) if sh else None
highlights = (qh, sh) if qh or sh else None
ratio = ysize * 1. / xsize if proportional else 1
width = iopts.w
height = iopts.h * ratio
fig = plt.figure(1, (width, height))
root = fig.add_axes([0, 0, 1, 1]) # the whole canvas
ax = fig.add_axes([.1, .1, .8, .8]) # the dot plot
def plot_one_scaffold(scaffoldID, ssizes, sbed, trios, imagename, iopts):
ntrios = len(trios)
fig = plt.figure(1, (14, 8))
plt.cla()
plt.clf()
root = fig.add_axes([0, 0, 1, 1])
axes = [fig.add_subplot(1, ntrios, x) for x in range(1, ntrios + 1)]
scafsize = ssizes.get_size(scaffoldID)
for trio, ax in zip(trios, axes):
blastf, qsizes, qbed = trio
scaffolding(ax, scaffoldID, blastf, qsizes, ssizes, qbed, sbed)
root.text(.5, .95, _("{0} (size={1})".\
format(scaffoldID, thousands(scafsize))),
size=18, ha="center", color='b')
root.set_xlim(0, 1)
root.set_ylim(0, 1)
root.set_axis_off()
qseqids, sseqids = set(), set()
for pair in ac.iter_pairs():
q, s = pair[:2]
qi, q = qorder[q]
si, s = sorder[s]
qseqids.add(q.seqid)
sseqids.add(s.seqid)
if is_self:
qbed = sbed = subset_bed(qbed, qseqids)
else:
qbed = subset_bed(qbed, qseqids)
sbed = subset_bed(sbed, sseqids)
fig = plt.figure(1, (iopts.w, iopts.h))
root = fig.add_axes([0, 0, 1, 1]) # the whole canvas
ax = fig.add_axes([.1, .1, .8, .8]) # the dot plot
dotplot(anchorfile, qbed, sbed, fig, root, ax,
vmin=opts.vmin, vmax=opts.vmax, is_self=is_self,
synteny=opts.synteny, cmap_text=opts.cmaptext, cmap=iopts.cmap,
genomenames=opts.genomenames, sample_number=opts.sample_number,
minfont=opts.minfont, palette=palette, sep=(not opts.nosep),
title=opts.title, stdpf=(not opts.nostdpf), chpf=(not opts.nochpf))
image_name = opts.outfile or \
(op.splitext(anchorfile)[0] + "." + opts.format)
savefig(image_name, dpi=iopts.dpi, iopts=iopts)
fig.clear()