def main(): out_fname = sys.argv[1] basedir = '/'.join(os.path.dirname(os.path.realpath(__file__)).split('/')[:-2]) mm9_methods = { '0 pseudo-counts':'%s/Analysis/hifive_mm9_ESC_bin_correlations.txt' % basedir, '1 pseudo-count':'%s/Analysis/hifive_mm9_ESC_binPC1_correlations.txt' % basedir, '3 pseudo-counts':'%s/Analysis/hifive_mm9_ESC_binPC3_correlations.txt' % basedir, '6 pseudo-counts':'%s/Analysis/hifive_mm9_ESC_binPC6_correlations.txt' % basedir, 'HiCPipe':'%s/Analysis/hicpipe_mm9_ESC_correlations.txt' % basedir, } mm9_data = load_data(mm9_methods) width = 16.8 spacer = 0.4 overall_width = (width - spacer * 2) / 2.6 c = canvas.canvas() prob_ranges_img, prob_ranges_height = plot_dataset_ranges(mm9_data, width) prob_ranges_img.text(0, prob_ranges_height, 'a', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(prob_ranges_img) overall_height = prob_ranges_height * 0.6 hifive_overall_img = plot_overall(mm9_data, overall_width, overall_height, 'cis') hifive_overall_img.text(0, overall_height + 0.1, 'b', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(hifive_overall_img, [trafo.translate(0, -overall_height - spacer)]) hifive_overall_img = plot_overall(mm9_data, overall_width, overall_height, 'trans') hifive_overall_img.text(0, overall_height + 0.1, 'c', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(hifive_overall_img, [trafo.translate(width - overall_width, -overall_height - spacer)]) c.insert(plot_key(overall_width * 0.6 + 0.4, overall_height, mm9_data), [trafo.translate(overall_width + spacer + 0.6, -overall_height - spacer)]) c.writePDFfile(out_fname)
def main(): out_fname = sys.argv[1] basedir = '/'.join(os.path.dirname(os.path.realpath(__file__)).split('/')[:-2]) mm9_methods = { 'HiFive-Probability':'%s/Analysis/hifive_mm9_ESC_prob_correlations.txt' % basedir, 'HiFive-Express':'%s/Analysis/hifive_mm9_ESC_exp_correlations.txt' % basedir, 'HiFive-Binning':'%s/Analysis/hifive_mm9_ESC_bin_correlations.txt' % basedir, } dist_methods = { 'HiFive-Probability':'%s/Analysis/hifive_mm9_ESC_probnodist_correlations.txt' % basedir, 'HiFive-Express':'%s/Analysis/hifive_mm9_ESC_expnodist_correlations.txt' % basedir, 'HiFive-Binning':'%s/Analysis/hifive_mm9_ESC_binnodist_correlations.txt' % basedir, } mm9_data = load_data(mm9_methods) dist_data = load_data(dist_methods) width = 16.8 spacer = 0.4 range_width = (width - spacer) / 3.0 c = canvas.canvas() mm9_ranges_img = plot_dataset_ranges(mm9_data, dist_data, range_width) c.insert(mm9_ranges_img) mm9_overall_img = plot_overall(mm9_data, dist_data, range_width, range_width) mm9_overall_img.text(0, range_width, 'b', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(mm9_overall_img, [trafo.translate(range_width * 2 + spacer, range_width)]) c.insert(plot_key(range_width / 2, range_width / 2), [trafo.translate(range_width * 2.25 + spacer, range_width * 0.25)]) c.writePDFfile(out_fname)
def makebinaries(number, y0): size = 0.4 dist = 0.1 for n in range(32): c.stroke(path.rect(n*size+(n/8)*dist, y0, size, size)) c.text((n+0.5)*size+(n/8)*dist, y0+0.07, r"\sffamily %i" % ((number >> 31-n) & 1), [text.halign.center]) if number >> 31: c.text(32.2*size+5*dist, y0+0.07, r"\sffamily = -%i" % ((number ^ 0xffffffff)+1)) else: c.text(32.2*size+5*dist, y0+0.07, r"\sffamily = %i" % number) p = path.path(path.moveto(0.2*size, size+0.03), path.lineto(0.2*size, size+0.07), path.lineto(3.8*size, size+0.07), path.lineto(3.8*size, size+0.03)) for n in range(4): c.stroke(p, [trafo.translate(n*(8*size+dist), y0)]) c.text(n*(8*size+dist)+2*size, size+0.14+y0, r"\sffamily %X" % ((number >> ((3-n)*8+4)) & 15), [text.halign.center]) c.stroke(p, [trafo.translate(n*(8*size+dist)+4*size, y0)]) c.text(n*(8*size+dist)+6*size, size+0.14+y0, r"\sffamily %X" % ((number >> ((3-n)*8)) & 15), [text.halign.center])
def main(): width = 16.8 out_fname = sys.argv[1] basedir = "%s/Analysis/Timing" % '/'.join(os.path.dirname(os.path.realpath(__file__)).split('/')[:-2]) data_fnames = { "HiFive-Probability":{'0':"%s/hifive_data" % basedir, '1':"%s/hifive_project" % basedir, '3':'%s/hifive_prob' % basedir, '4':"%s/hifive_prob_heatmap" % basedir}, "HiFive-Binning":{'0':"%s/hifive_data" % basedir, '1':"%s/hifive_project_nodist" % basedir, '3':'%s/hifive_bin' % basedir, '4':"%s/hifive_bin_heatmap" % basedir}, "HiFive-Express":{'0':"%s/hifive_data" % basedir, '1':"%s/hifive_project" % basedir, '3':'%s/hifive_exp' % basedir, '4':"%s/hifive_exp_heatmap" % basedir}, "HiFive-ExpressKR":{'0':"%s/hifive_data" % basedir, '1':"%s/hifive_project_nodist" % basedir, '3':'%s/hifive_expKR' % basedir, '4':"%s/hifive_expKR_heatmap" % basedir}, "HiFive-ExpressKR w/distance":{'0':"%s/hifive_data" % basedir, '1':"%s/hifive_project" % basedir, '3':'%s/hifive_expKRdist' % basedir, '4':"%s/hifive_expKRdist_heatmap" % basedir}, "HiCPipe":{'0':"%s/bam2raw" % basedir, '1':"%s/hicpipe_data" % basedir, '2':'%s/hicpipe_binning' % basedir, '3':'%s/hicpipe_norm' % basedir, '4':'%s/hicpipe_heatmap' % basedir}, "HiCLib":{'0':"%s/hiclib_mapping" % basedir, '1':'%s/hiclib_data' % basedir, '3':"%s/hiclib_norm" % basedir, '4':'%s/hiclib_heatmap' % basedir}, "HiCNorm":{'0':"%s/bam2raw" % basedir, '1':"%s/hicpipe_data" % basedir, "2":"%s/hicnorm_data" % basedir, '3':'%s/hicnorm_norm' % basedir}, } data = load_data(data_fnames) c = canvas.canvas() c.insert(plot_bargraph(data, width, 4.0), [trafo.translate(4.0, 0)]) c.insert(plot_key(width * 0.3, 1.5), [trafo.translate(width * 0.75 - 1.0, 0.2)]) c.writePDFfile(out_fname)
def paint(self, canvas, data, axis, axispos): if self.breaklinesattrs is not None: breaklinesdist_pt = unit.topt(self.breaklinesdist) breaklineslength_pt = unit.topt(self.breaklineslength) breaklinesextent_pt = (0.5*breaklinesdist_pt*math.fabs(self.cos) + 0.5*breaklineslength_pt*math.fabs(self.sin)) if canvas.extent_pt < breaklinesextent_pt: canvas.extent_pt = breaklinesextent_pt for v in [data.subaxes[name].vminover for name in data.names[1:]]: # use a tangent of the basepath (this is independent of the tickdirection) p = axispos.vbasepath(v, None).normpath() breakline = p.tangent(0, length=self.breaklineslength) widthline = p.tangent(0, length=self.breaklinesdist).transformed(trafomodule.rotate(self.breaklinesangle+90, *breakline.atbegin())) # XXX Uiiii tocenter = map(lambda x: 0.5*(x[0]-x[1]), zip(breakline.atbegin(), breakline.atend())) towidth = map(lambda x: 0.5*(x[0]-x[1]), zip(widthline.atbegin(), widthline.atend())) breakline = breakline.transformed(trafomodule.translate(*tocenter).rotated(self.breaklinesangle, *breakline.atbegin())) breakline1 = breakline.transformed(trafomodule.translate(*towidth)) breakline2 = breakline.transformed(trafomodule.translate(-towidth[0], -towidth[1])) canvas.layer("baseline").fill(path.path(path.moveto_pt(*breakline1.atbegin_pt()), path.lineto_pt(*breakline1.atend_pt()), path.lineto_pt(*breakline2.atend_pt()), path.lineto_pt(*breakline2.atbegin_pt()), path.closepath()), [color.gray.white]) canvas.layer("baseline").stroke(breakline1, self.defaultbreaklinesattrs + self.breaklinesattrs) canvas.layer("baseline").stroke(breakline2, self.defaultbreaklinesattrs + self.breaklinesattrs) _title.paint(self, canvas, data, axis, axispos)
def timeslice(x, y, transparency=0.0, label="", W=3): dopath( [(-1.1, y0), (-0.1, y1), (W + 0.2, y1), (W - 0.8, y0)], fill=[shade, color.transparency(0.3)], extra=[trafo.translate(x, y)], closepath=True, ) if label: c.text(W + 0.2, 0.0, label, west + [trafo.translate(x, y)])
def main(): out_fname = sys.argv[1] basedir = '/'.join(os.path.dirname(os.path.realpath(__file__)).split('/')[:-2]) hic_fname1 = "%s/Data/HiC/HiFive/mm9_ESC_NcoI_prob.hcp" % basedir hic_fname2 = "%s/Data/HiC/HiFive/mm9_ESC_HindIII_prob.hcp" % basedir fivec_fnames = { "Prob_Phillips":"%s/Data/FiveC/HiFive/Phillips_ESC_prob.fcp" % basedir, "Prob_Nora":"%s/Data/FiveC/HiFive/Nora_ESC_male_E14_prob.fcp" % basedir, "Bin_Phillips":"%s/Data/FiveC/HiFive/Phillips_ESC_bin.fcp" % basedir, "Bin_Nora":"%s/Data/FiveC/HiFive/Nora_ESC_male_E14_bin.fcp" % basedir, "Exp_Phillips":"%s/Data/FiveC/HiFive/Phillips_ESC_exp.fcp" % basedir, "Exp_Nora":"%s/Data/FiveC/HiFive/Nora_ESC_male_E14_exp.fcp" % basedir, "Exp-KR_Phillips":"%s/Data/FiveC/HiFive/Phillips_ESC_expKR.fcp" % basedir, "Exp-KR_Nora":"%s/Data/FiveC/HiFive/Nora_ESC_male_E14_expKR.fcp" % basedir, } hic1 = hifive.HiC(hic_fname1) hic2 = hifive.HiC(hic_fname2) hic_hm = { 'Phillips': {} } fc = hifive.FiveC(fivec_fnames["Prob_Phillips"]) fragments = fc.frags['fragments'][...] regions = fc.frags['regions'][...] for i in range(fc.frags['regions'].shape[0]): binbounds = numpy.hstack(( fragments['start'][regions['start_frag'][i]:regions['stop_frag'][i]].reshape(-1, 1), fragments['stop'][regions['start_frag'][i]:regions['stop_frag'][i]].reshape(-1, 1))) binbounds = binbounds[numpy.where(fc.filter[regions['start_frag'][i]:regions['stop_frag'][i]])[0], :] hic_hm['Phillips'][i] = dynamically_bin(hic1, hic2, regions['chromosome'][i], binbounds) fc = hifive.FiveC(fivec_fnames["Prob_Nora"]) fragments = fc.frags['fragments'][...] regions = fc.frags['regions'][...] binbounds = numpy.hstack(( fragments['start'][regions['start_frag'][0]:regions['stop_frag'][0]].reshape(-1, 1), fragments['stop'][regions['start_frag'][0]:regions['stop_frag'][0]].reshape(-1, 1))) binbounds = binbounds[numpy.where(fc.filter[regions['start_frag'][0]:regions['stop_frag'][0]])[0], :] hic_hm['Nora'] = dynamically_bin(hic1, hic2, regions['chromosome'][0], binbounds) dist_corr = find_correlations( hic_hm, fivec_fnames, out_fname, True ) nodist_corr = find_correlations( hic_hm, fivec_fnames, out_fname, False ) c = canvas.canvas() width = 16.8 spacer = 0.4 plot_width = (width - spacer * 2) / 2.5 plot_height = plot_width key_width = width - (plot_width + spacer) * 2 phillips_img = plot_correlation_diffs(dist_corr, nodist_corr, 'Phillips', plot_width, plot_height) nora_img = plot_correlation_diffs(dist_corr, nodist_corr, 'Nora', plot_width, plot_height) key_img = plot_key(key_width, plot_height) c.insert(phillips_img) c.insert(nora_img, [trafo.translate(plot_width + spacer, 0)]) c.insert(key_img, [trafo.translate((plot_width + spacer) * 2, 0)]) c.text(0, plot_height, "a", [text.halign.left, text.valign.top, text.size(-1)]) c.text(plot_width + spacer, plot_height, "b", [text.halign.left, text.valign.top, text.size(-1)]) c.writePDFfile(out_fname)
def main(): out_fname = sys.argv[1] basedir = '/'.join(os.path.dirname(os.path.realpath(__file__)).split('/')[:-2]) mm9_methods = { 'HiFive-Probability':'%s/Analysis/hifive_mm9_ESC_prob_correlations.txt' % basedir, 'HiFive-Express':'%s/Analysis/hifive_mm9_ESC_exp_correlations.txt' % basedir, 'HiFive-Binning':'%s/Analysis/hifive_mm9_ESC_bin_correlations.txt' % basedir, 'HiCNorm':'%s/Analysis/hicnorm_mm9_ESC_correlations.txt' % basedir, 'HiCPipe':'%s/Analysis/hicpipe_mm9_ESC_correlations.txt' % basedir, 'Matrix-Balancing':'%s/Analysis/mb_mm9_ESC_correlations.txt' % basedir, } hg19_methods = { 'HiFive-Probability':'%s/Analysis/hifive_hg19_GM12878_prob_correlations.txt' % basedir, 'HiFive-Express':'%s/Analysis/hifive_hg19_GM12878_exp_correlations.txt' % basedir, 'HiFive-Binning':'%s/Analysis/hifive_hg19_GM12878_bin_correlations.txt' % basedir, 'HiCNorm':'%s/Analysis/hicnorm_hg19_GM12878_correlations.txt' % basedir, 'HiCPipe':'%s/Analysis/hicpipe_hg19_GM12878_correlations.txt' % basedir, 'Matrix-Balancing':'%s/Analysis/mb_hg19_GM12878_correlations.txt' % basedir, } mm9_data = load_data(mm9_methods) hg19_data = load_data(hg19_methods) width = 16.8 spacer = 0.4 overall_width = (width - spacer * 2) / 2.6 c = canvas.canvas() mm9_ranges_img, mm9_ranges_height = plot_dataset_ranges(mm9_data, width, "MM9 ESC") mm9_ranges_img.text(0, mm9_ranges_height, 'a', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(mm9_ranges_img) hg19_ranges_img, hg19_ranges_height = plot_dataset_ranges(hg19_data, width, "HG19 GM12878") hg19_ranges_img.text(0, hg19_ranges_height, 'b', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(hg19_ranges_img, [trafo.translate(0, -hg19_ranges_height - spacer)]) overall_height = mm9_ranges_height * 0.6 mm9_overall_img = plot_overall(mm9_data, overall_width, overall_height, "MM9 ESC") mm9_overall_img.text(0, overall_height + 0.1, 'c', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(mm9_overall_img, [trafo.translate(0, -hg19_ranges_height - overall_height - spacer * 2)]) hg19_overall_img = plot_overall(hg19_data, overall_width, overall_height, "HG19 GM12878") hg19_overall_img.text(0, overall_height + 0.1, 'd', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(hg19_overall_img, [trafo.translate(overall_width * 1.6 + spacer * 2, -hg19_ranges_height - overall_height - spacer * 2)]) c.insert(plot_key(overall_width * 0.6 + 0.4, overall_height), [trafo.translate(overall_width + spacer + 0.6, -hg19_ranges_height - overall_height - spacer * 2)]) c.writePDFfile(out_fname)
def main(): out_fname = sys.argv[1] basedir = '/'.join(os.path.dirname(os.path.realpath(__file__)).split('/')[:-2]) mm9_methods = { 'distance-corrected':'%s/Analysis/hifive_mm9_ESC_exp_correlations.txt' % basedir, 'raw':'%s/Analysis/hifive_mm9_ESC_expdist_correlations.txt' % basedir, } mm9_data = load_data(mm9_methods) width = 16.8 spacer = 0.4 plot_width = (width - spacer * 4) / 5 c = canvas.canvas() mm9_ranges_img, mm9_ranges_height = plot_dataset_ranges(mm9_data, plot_width, spacer) mm9_ranges_img.text(0, mm9_ranges_height, 'b', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(mm9_ranges_img, [trafo.translate(plot_width + spacer, 0)]) mm9_overall_img = plot_overall(mm9_data, plot_width - spacer, (mm9_ranges_height - spacer) - 0.3) c.text(0, mm9_ranges_height, 'a', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(mm9_overall_img, [trafo.translate(0, 0.4)]) c.writePDFfile(out_fname)
def plot_overall(data, width, height, name): vo = 0.55 ho = 0.7 plot_width = width - ho plot_height = height - vo - 0.3 c = canvas.canvas() methods = data.keys() methods.sort() bar_colors = [] cis_binsizes = numpy.unique(data[methods[0]]['binsize'][numpy.where(data[methods[0]]['interaction'] == 'cis')]) trans_binsizes = numpy.unique(data[methods[0]]['binsize'][numpy.where(data[methods[0]]['interaction'] == 'trans')]) Y = numpy.zeros((len(methods), cis_binsizes.shape[0] + trans_binsizes.shape[0]), dtype=numpy.float32) for i, method in enumerate(methods): for j, binsize in enumerate(cis_binsizes): where = numpy.where((data[method]['binsize'] == binsize) * (data[method]['interaction'] == 'cis') * (data[method]['range'] == 0)) if where[0].shape[0] > 0: Y[i, j] = data[method]['correlation'][where] for j, binsize in enumerate(trans_binsizes): where = numpy.where((data[method]['binsize'] == binsize) * (data[method]['interaction'] == 'trans') * (data[method]['range'] == 0)) if where[0].shape[0] > 0: Y[i, j + cis_binsizes.shape[0]] = data[method]['correlation'][where] bar_colors.append(method_colors[method]) Y = numpy.array(Y) g = graph.graphxy(width=plot_width, height=plot_height, x=graph.axis.nestedbar(painter=graph.axis.painter.bar(nameattrs=None)), y=graph.axis.lin(painter=painter), x2=graph.axis.lin(parter=None, min=0, max=1), y2=graph.axis.lin(parter=None, min=0, max=1)) for i in range(len(methods)): g.plot(graph.data.points(zip(zip(range(Y.shape[1]), [i] * Y.shape[1]), Y[i, :]), xname=1, y=2), [graph.style.changebar([method_colors[methods[i]]])]) c.insert(g, [trafo.translate(ho, vo)]) for i, label in enumerate(["10Kb", "50Kb", "250Kb", "1Mb", "250Kb", "1Mb"]): c.text(ho + plot_width * (i + 0.5) / 6.0, vo - 0.05, "%s" % label, [text.halign.center, text.valign.top, text.size(-3)]) c.text(ho + plot_width * 2.0 / 6.0, 0.05, "cis", [text.halign.center, text.valign.bottom, text.size(-3)]) c.stroke(path.line(ho + 0.2, vo * 0.5, ho - 0.2 + plot_width * 4.0 / 6.0, vo * 0.5), [style.linewidth.THin]) c.text(ho + plot_width * 5.0 / 6.0, 0.05, "trans", [text.halign.center, text.valign.bottom, text.size(-3)]) c.stroke(path.line(ho + 0.2 + plot_width * 4.0 / 6.0, vo * 0.5, ho - 0.2 + plot_width, vo * 0.5), [style.linewidth.THin]) c.text(0, plot_height * 0.5 + vo, "Correlation", [text.halign.center, text.valign.top, text.size(-3), trafo.rotate(90)]) c.text(plot_width * 0.5 + ho, height, name, [text.halign.center, text.valign.top, text.size(-3)]) return c
def plot_overall(data, width, height, int_type): methods = data.keys() methods.sort() vo = 0.3 ho = 0.8 plot_width = width - ho plot_height = height - vo - 0.3 c = canvas.canvas() bar_colors = [] binsizes = numpy.unique(data[methods[0]]['binsize'][numpy.where(data[methods[0]]['interaction'] == int_type)]) Y = numpy.zeros((len(methods), binsizes.shape[0]), dtype=numpy.float32) for i, method in enumerate(methods): for j, binsize in enumerate(binsizes): where = numpy.where((data[method]['binsize'] == binsize) * (data[method]['interaction'] == int_type) * (data[method]['range'] == 0)) if where[0].shape[0] > 0: Y[i, j] = data[method]['correlation'][where] bar_colors.append(method_colors[method]) Y = numpy.array(Y) minY = numpy.amin(Y) maxY = numpy.amax(Y) spanY = maxY - minY minY -= spanY * 0.05 maxY += spanY * 0.05 g = graph.graphxy(width=plot_width, height=plot_height, x=graph.axis.nestedbar(painter=graph.axis.painter.bar(nameattrs=None)), y=graph.axis.lin(painter=painter, min=minY, max=maxY), x2=graph.axis.lin(parter=None, min=0, max=1), y2=graph.axis.lin(parter=None, min=0, max=1)) for i in range(len(methods)): g.plot(graph.data.points(zip(zip(range(Y.shape[1]), [i] * Y.shape[1]), Y[i, :]), xname=1, y=2), [graph.style.changebar([method_colors[methods[i]]])]) c.insert(g, [trafo.translate(ho, vo)]) if int_type == 'cis': for i, label in enumerate(["10Kb", "50Kb", "250Kb", "1Mb"]): c.text(ho + plot_width * (i + 0.5) / 4.0, vo - 0.05, "%s" % label, [text.halign.center, text.valign.top, text.size(-3)]) c.text(ho + plot_width * 0.5, height, "Cis", [text.halign.center, text.valign.top, text.size(-2)]) else: for i, label in enumerate(["250Kb", "1Mb"]): c.text(ho + plot_width * (i + 0.5) / 2.0, vo - 0.05, "%s" % label, [text.halign.center, text.valign.top, text.size(-3)]) c.text(ho + plot_width * 0.5, height, "Trans", [text.halign.center, text.valign.top, text.size(-2)]) c.text(0, plot_height * 0.5 + vo, "Correlation", [text.halign.center, text.valign.top, text.size(-3), trafo.rotate(90)]) return c
def braid_id(x0=0., y0=0., H=3.0, t0="", t1=""): tr = [trafo.translate(x0, y0)] timeslice(x0, y0, 0., t0) for i in range(3): x = i*w c.stroke(path.line(x, 0., x, H), st_Thick+tr) timeslice(x0, y0+H, 0.3, t1) for i in range(3): c.fill(path.circle(i*w, 0., 0.06), tr) c.fill(path.circle(i*w, H, 0.06), tr)
def braid_1(x0=0., y0=0., H=3.0, t0="", t1="", inverse=False): if inverse: rev = lambda x : list(reversed(x)) rev1 = lambda ps : [(x, H-y) for (x, y) in reversed(ps)] else: rev = list rev1 = list tr = [trafo.translate(x0, y0)] ps0 = [] ps1 = [] ps2 = [] for i in range(N+1): r = 1.*i/N y = r*H r1 = bump(r) x = 0.5*(w - w*cos(2*pi*r1)) ps0.append((x, y)) x = w + w*(sin(0.5*pi*r)) ps1.append((x, y)) x = 1*w + w*cos(1.5*pi*r1) ps2.append((x, y)) ps0 = rev1(ps0) ps1 = rev1(ps1) ps2 = rev1(ps2) if not inverse: # HACK timeslice(x0, y0, 0., t0) for ps in draw(ps0, [ps1, ps2], rev([True, False])): dopath(ps, st_Thick+tr) for ps in draw(ps1, [ps0, ps2], rev([False])): dopath(ps, st_Thick+tr) for ps in draw(ps2, [ps0, ps1], rev([True, False, True])): dopath(ps, st_Thick+tr) timeslice(x0, y0+H, 0.3, t1) for i in range(3): c.fill(path.circle(i*w, 0., 0.06), tr) c.fill(path.circle(i*w, H, 0.06), tr)
def main(): out_fname = sys.argv[1] basedir = '/'.join(os.path.dirname(os.path.realpath(__file__)).split('/')[:-2]) bin_file = '%s/Analysis/hifive_mm9_ESC_prob_correlations.txt' % basedir pois_file = '%s/Analysis/hifive_mm9_ESC_probpois_correlations.txt' % basedir bin_data = load_data(bin_file) pois_data = load_data(pois_file) width = 16.8 spacer = 0.4 range_width = (width - spacer) / 5.0 range_height = range_width * 1.4 c = canvas.canvas() ranges_img = plot_dataset_ranges(bin_data, pois_data, range_width * 4, range_height) c.insert(ranges_img) overall_img = plot_overall(bin_data, pois_data, range_width, range_height) c.insert(overall_img, [trafo.translate(range_width * 4 + spacer, 0)]) c.writePDFfile(out_fname)
def plot_single_range(data, binsize, width, height): plot_width = width - 0.4 plot_height = height - 0.8 c = canvas.canvas() xmax = 0.0 methods = data.keys() methods.sort() for method in methods: where = numpy.where((data[method]['binsize'] == binsize) * (data[method]['interaction'] == 'cis') * (data[method]['range'] > 0)) if where[0].shape[0] > 0: xmax = max(xmax, numpy.amax(data[method]['range'][where])) X = data[method]['range'][where] X = numpy.r_[0, X] X[0] = X[1] ** 2.0 / X[2] xmin = X[0] g = graph.graphxy(width=plot_width, height=plot_height, x=graph.axis.log(painter=painter, min=X[0], max=xmax), y=graph.axis.lin(painter=painter), x2=graph.axis.lin(parter=None, min=0, max=1), y2=graph.axis.lin(parter=None, min=0, max=1)) for x in X[1:-1]: pos = ((log(x) - log(xmin)) / (log(xmax) - log(xmin)) * plot_width) g.stroke(path.line(pos, 0, pos, plot_height), [style.linestyle.dotted, style.linewidth.THin]) X = (X[1:] ** 0.5) * (X[:-1] ** 0.5) for method in methods: where = numpy.where((data[method]['binsize'] == binsize) * (data[method]['interaction'] == 'cis') * (data[method]['range'] > 0)) if where[0].shape[0] > 0: Y = data[method]['correlation'][where] g.plot(graph.data.points(zip(X, Y), x=1, y=2), [graph.style.line(lineattrs=[method_colors[method], style.linewidth.Thick])]) if binsize / 1000000 > 0: binstring = "%iMb" % (binsize / 1000000) elif binsize / 1000 > 0: binstring = "%iKb" % (binsize / 1000) else: binstring = str(binsize) g.text(plot_width / 2, plot_height + 0.05, "%s Binning" % (binstring), [text.halign.center, text.valign.bottom, text.size(-2)]) c.insert(g, [trafo.translate(0.4, 0.4)]) return c
def plot_overall(data, width, height): plot_width = width - 0.4 plot_height = height - 0.4 c = canvas.canvas() methods = data.keys() methods.sort() bar_colors = [] cis_binsizes = numpy.unique(data[methods[0]]['binsize'][numpy.where(data[methods[0]]['interaction'] == 'cis')]) trans_binsizes = numpy.unique(data[methods[0]]['binsize'][numpy.where(data[methods[0]]['interaction'] == 'trans')]) Y = numpy.zeros((len(methods), cis_binsizes.shape[0] + trans_binsizes.shape[0]), dtype=numpy.float32) for i, method in enumerate(methods): for j, binsize in enumerate(cis_binsizes): where = numpy.where((data[method]['binsize'] == binsize) * (data[method]['interaction'] == 'cis') * (data[method]['range'] == 0)) if where[0].shape[0] > 0: Y[i, j] = data[method]['correlation'][where] for j, binsize in enumerate(trans_binsizes): where = numpy.where((data[method]['binsize'] == binsize) * (data[method]['interaction'] == 'trans') * (data[method]['range'] == 0)) if where[0].shape[0] > 0: Y[i, j + cis_binsizes.shape[0]] = data[method]['correlation'][where] bar_colors.append(method_colors[method]) Y = numpy.array(Y) g = graph.graphxy(width=plot_width, height=plot_height, x=graph.axis.nestedbar(painter=graph.axis.painter.bar(nameattrs=None)), y=graph.axis.lin(painter=painter), x2=graph.axis.lin(parter=None, min=0, max=1), y2=graph.axis.lin(parter=None, min=0, max=1)) for i in range(len(methods)): g.plot(graph.data.points(zip(zip(range(Y.shape[1]), [i] * Y.shape[1]), Y[i, :]), xname=1, y=2), [graph.style.changebar([method_colors[methods[i]]])]) step = plot_width / (cis_binsizes.shape[0] + trans_binsizes.shape[0]) for i, binsize in enumerate(cis_binsizes): g.text(step * (0.5 + i), -0.05, "%s cis" % (str(binsize/1000) + 'Kb').replace('000Kb', 'Mb'), [text.halign.right, text.valign.middle, text.size(-4), trafo.rotate(45)]) for i, binsize in enumerate(trans_binsizes): g.text(step * (0.5 + i + cis_binsizes.shape[0]), -0.05, "%s trans" % (str(binsize/1000) + 'Kb').replace('000Kb', 'Mb'), [text.halign.right, text.valign.middle, text.size(-4), trafo.rotate(45)]) c.insert(g, [trafo.translate(0.7, 0.4)]) c.text(0, plot_height / 2.0 + 0.4, "Dataset Correlation", [text.halign.center, text.valign.top, text.size(-3), trafo.rotate(90)]) return c
def plot_dataset_ranges(data, width, spacer): methods = data.keys() binsizes = numpy.unique(data[methods[0]]['binsize']) plot_width = width - 0.4 plot_height = plot_width + 0.2 c = canvas.canvas() for i, binsize in enumerate(binsizes): img = plot_single_range(data, binsize, plot_width, plot_height) c.insert(img, [trafo.translate((plot_width + spacer) * i + 0.4, 0.4 + spacer * 0.5)]) c.text(0, plot_height * 0.5 + 0.2 + spacer * 0.75, "Dataset correlation", [text.halign.center, text.valign.top, text.size(-3), trafo.rotate(90)]) c.text(plot_width * 2 + spacer * 1.5 + 0.4, 0.35, "Interaction range (bp)", [text.halign.center, text.valign.bottom, text.size(-3)]) c.fill(path.rect(0.4, 0.025, 0.2, 0.2), [color.rgb.black]) c.text(0.7, 0.125, "HiFive-Express using raw reads", [text.halign.left, text.valign.middle, text.size(-2)]) c.fill(path.rect(plot_width * 2 + spacer * 1.5, 0.025, 0.2, 0.2), [color.rgb.red]) c.text(plot_width * 2 + spacer * 1.5 + 0.3, 0.125, "HiFive-Express using distance-corrected reads", [text.halign.left, text.valign.middle, text.size(-2)]) return c, plot_height + 0.4 + spacer
def plot_dataset_ranges(data, width): methods = data.keys() methods.sort() binsizes = numpy.unique(data[methods[0]]['binsize']) ho = 0.4 ho2 = 0.4 vo = 0.6 spacer = 0.25 plot_width = (width - ho - (binsizes.shape[0] - 1) * spacer) / binsizes.shape[0] - ho2 plot_height = plot_width c = canvas.canvas() for i, binsize in enumerate(binsizes): img = plot_single_range(data, binsize, plot_width, plot_width, methods) c.insert(img, [trafo.translate((plot_width + spacer) * i + ho2 * (i + 1) + ho, vo)]) c.text(0, plot_height * 0.5 + vo, "Correlation", [text.halign.center, text.valign.top, text.size(-3), trafo.rotate(90)]) c.text((plot_width + ho2) * 2 + spacer * 1.5 + ho, 0, "Interaction Range (bp)", [text.halign.center, text.valign.bottom, text.size(-3)]) return c, plot_height + vo + 0.3
def plot_dataset_ranges(data0, data1, width, height): binsizes = numpy.unique(data0['binsize']) ho = 1.1 ho2 = 0.2 vo = 1.0 plot_width = (width - ho - ho2 * 3) / 4.0 plot_height = height - vo c = canvas.canvas() for i, binsize in enumerate(binsizes): if i == 0: ylabel = True else: ylabel = False img = plot_single_range(data0, data1, binsize, plot_width, plot_height, ylabel) c.insert(img, [trafo.translate(ho + i * (plot_width + ho2), vo - 0.3)]) c.text(0, plot_height * 0.5 + vo - 0.3, r"$r_{Poisson} - r_{binomial}$", [text.halign.center, text.valign.top, text.size(-2), trafo.rotate(90)]) c.text(plot_width * 2 + ho + 1.5 * ho2, 0, "Interaction Range (bp)", [text.halign.center, text.valign.bottom, text.size(-3)]) c.text(0, height, 'a', [text.halign.left, text.valign.top, text.size(-1)]) return c
def plot_correlation_diffs(corr1, corr2, name, width, height): ho = 1.2 vo = 0.4 plot_width = width - ho plot_height = height - vo diffs = {} ymin = numpy.inf ymax = -numpy.inf for n in ['Phillips', 'Nora']: for meth in meth_names.keys(): cname = "%s_%s" % (meth, n) diff = corr2[cname] - corr1[cname] ymin = min(ymin, diff) ymax = max(ymax, diff) for meth in meth_names.keys(): cname = "%s_%s" % (meth, name) diffs[meth] = corr2[cname] - corr1[cname] yspan = ymax - ymin ymin -= yspan * 0.05 ymax += yspan * 0.05 yspan = ymax - ymin c = canvas.canvas() g = graph.graphxy(width=plot_width, height=plot_height, x=graph.axis.bar(painter=graph.axis.painter.bar(nameattrs=None)), y=graph.axis.lin(painter=painter, min=ymin, max=ymax), x2=graph.axis.lin(parter=None, min=0, max=1), y2=graph.axis.lin(parter=None, min=0, max=1)) w = plot_width / float(len(meth_names) + 1) y0 = -ymin / yspan * plot_height for i, meth in enumerate(methods): col = method_colors[meth] g.stroke( path.rect((i + 0.5) * w, y0, w, diffs[meth] / yspan * plot_height), [deco.filled([col])]) g.stroke( path.line(0, y0, plot_width, y0), [style.linestyle.dotted, style.linewidth.THin]) c.insert(g, [trafo.translate(ho, vo)]) c.text(0, plot_height * 0.5 + vo, r"$r_{0K} - r_{50K}$", [text.halign.center, text.valign.top, text.size(-3), trafo.rotate(90)]) c.text(plot_width * 0.5 + ho, vo * 0.5, name, [text.halign.center, text.valign.middle, text.size(-3)]) return c
def checkall(): # <<< c = None for knots, refpoints in [curve1(), curve2(), curve3(), curve4(-90), curve4(0), curve4(70), curve5(), curve6a(), curve6b(), curve6c(), curve7(), curve8a(), curve8b(), curve9(), curve10()]: #print myprint(knots) mp_make_choices(knots, epsilon) #print myprint(knots) cc = canvas.canvas() cc.stroke(mypath(knots), [deco.shownormpath(), deco.earrow.normal]) if c is None: c = canvas.canvas() c.insert(cc) else: c.insert(cc, [trafo.translate(0, c.bbox().bottom() - cc.bbox().top()-0.5)]) check(knots, refpoints) c.writePDFfile() c.writeEPSfile() c.writeSVGfile()
def plot_bar(data, ranges, height, scale, split): c = canvas.canvas() pos = 0.0 x1 = 0.0 for i in range(5): if str(i) in data: x2 = data[str(i)] / 60.0 + pos pos2 = x2 for j in range(1, ranges.shape[0]): if x2 > ranges[j, 0] and x2 < ranges[j, 1]: for k in range(j): x2 -= ranges[k + 1, 0] - ranges[k, 1] break c.fill(path.rect(x1 * scale, 0, (x2 - x1) * scale, height), [step_colors[i]]) split_pos = ranges[0, 1] * scale for j in range(ranges.shape[0] - 1): if pos2 > ranges[j, 1]: c.insert(split, [trafo.translate(split_pos, height * 0.5)]) split_pos += (ranges[j + 1, 1] - ranges[j + 1, 0]) * scale pos += data[str(i)] / 60.0 x1 = x2 return c
def plot_dataset_ranges(data0, data1, width): methods = data0.keys() binsizes = numpy.unique(data0[methods[0]]['binsize']) ho = 0.8 ho2 = 0.25 vo = 0.7 vo2 = 0.4 spacer = 0.0 plot_width = (2 * width - ho * 2 - ho2 - spacer) / 2 plot_height = width - vo - vo2 c = canvas.canvas() for i, binsize in enumerate(binsizes): img = plot_single_range(data0, data1, binsize, plot_width, plot_width, vo, vo2) c.insert(img, [trafo.translate((plot_width + spacer + ho) * (i % 2) + ho2 + ho, (1 - i / 2) * (plot_height + spacer + vo + vo2) + vo)]) c.text(0, plot_height + 0.5 * spacer + vo + vo2, r"$r_{0K} - r_{500K}$", [text.halign.center, text.valign.top, text.size(-2), trafo.rotate(90)]) c.text(plot_width + ho2 + spacer * 0.5 + ho, 0, "Interaction Range (bp)", [text.halign.center, text.valign.bottom, text.size(-3)]) c.text(0, width * 2 + spacer, 'a', [text.halign.left, text.valign.top, text.size(-1)]) return c
def interface(): # <<< c = None for p in [ # ordinary open path: mppath.path([beginknot(0,0), curve(), knot(6,4), curve(), knot(4,9), curve(), knot(1,7), curve(), endknot(3,5)], epsilon), # path containing two open subpaths: mppath.path([beginknot(0,0), curve(), endknot(6,4), beginknot(4,9), curve(), knot(1,7), curve(), endknot(3,5)], epsilon), # closed path: mppath.path([knot(0,0), curve(), knot(6,4), curve(), knot(4,9), curve(), knot(1,7), curve(), knot(3,5), curve()], epsilon), # open path, but with endpoints in the middle: mppath.path([knot(0,0), curve(), knot(6,4), curve(), endknot(4,9), beginknot(1,7), curve(), knot(3,5), curve()], epsilon), # the same path in the right order mppath.path([beginknot(1,7), curve(), knot(3,5), curve(), knot(0,0), curve(), knot(6,4), curve(), endknot(4,9)], epsilon), # include a line mppath.path([knot(0,0), curve(), knot(6,4), curve(), roughknot(4,9), line(), roughknot(1,7), curve(), knot(3,5), curve()], epsilon), # XXX the endpoints have "open" at their other sides, not "curl" as in the open example above mppath.path([knot(0,0), curve(), knot(6,4), curve(), knot(4,9), line(), knot(1,7), curve(), knot(3,5), curve()], epsilon), mppath.path([knot(0,0), curve(), knot(6,4), line(), knot(3,5), curve()], epsilon), mppath.path([knot(0,0), curve(), knot(6,4), curve(), knot(3,5), curve()], epsilon), # TODO the internal mp_make_choices treats this as closed, but the last curve is not plotted: mppath.path([knot(0,0), curve(), knot(6,4), curve(), knot(4,9), line(), knot(1,7), curve(), knot(3,5)], epsilon), # include a line with given angles mppath.path([knot(0,0), curve(), knot(6,4), curve(), knot(4,9), line(keepangles=True), knot(1,7), curve(), knot(3,5), curve()], epsilon), # include rough knots mppath.path([beginknot(0,0), curve(), roughknot(6,4,langle=90), curve(), roughknot(4,9,langle=-90), line(keepangles=True), roughknot(1,7,lcurl=3), curve(), endknot(3,5,angle=0)], epsilon), ]: cc = canvas.canvas() cc.stroke(p, [deco.shownormpath(), deco.earrow.normal]) if c is None: c = cc else: c.insert(cc, [trafo.translate(c.bbox().right() - cc.bbox().left() + 0.5, 0)]) c.writePDFfile() c.writeEPSfile() c.writeSVGfile()
def main(): out_fname = sys.argv[1] basedir = '/'.join(os.path.dirname(os.path.realpath(__file__)).split('/')[:-2]) hic_phillips_fname1 = "%s/Data/HiC/HiCPipe/HM/mm9_ESC_NcoI_Phillips.hch" % basedir hic_phillips_fname2 = "%s/Data/HiC/HiCPipe/HM/mm9_ESC_HindIII_Phillips.hch" % basedir hic_nora_fname1 = "%s/Data/HiC/HiCPipe/HM/mm9_ESC_NcoI_Nora.hch" % basedir hic_nora_fname2 = "%s/Data/HiC/HiCPipe/HM/mm9_ESC_HindIII_Nora.hch" % basedir hic_phillips1 = h5py.File(hic_phillips_fname1, 'r') hic_phillips2 = h5py.File(hic_phillips_fname2, 'r') hic_nora1 = h5py.File(hic_nora_fname1, 'r') hic_nora2 = h5py.File(hic_nora_fname2, 'r') hm_phillips = {} hm_nora = {} for key in hic_phillips1.keys(): if key.count('unbinned_counts') == 0: continue region = int(key.split('.')[0]) hm_phillips[region] = dynamically_bin(hic_phillips1, hic_phillips2, region) for key in hic_nora1.keys(): if key.count('unbinned_counts') == 0: continue region = int(key.split('.')[0]) hm_nora[region] = dynamically_bin(hic_nora1, hic_nora2, region) fivec_fnames = { "Prob_Phillips":"%s/Data/FiveC/HiFive/Phillips_ESC_probnodist.fcp" % basedir, "Prob_Nora":"%s/Data/FiveC/HiFive/Nora_ESC_male_E14_probnodist.fcp" % basedir, "Bin_Phillips":"%s/Data/FiveC/HiFive/Phillips_ESC_binnodist.fcp" % basedir, "Bin_Nora":"%s/Data/FiveC/HiFive/Nora_ESC_male_E14_binnodist.fcp" % basedir, "Exp_Phillips":"%s/Data/FiveC/HiFive/Phillips_ESC_expnodist.fcp" % basedir, "Exp_Nora":"%s/Data/FiveC/HiFive/Nora_ESC_male_E14_expnodist.fcp" % basedir, "Exp-KR_Phillips":"%s/Data/FiveC/HiFive/Phillips_ESC_expKRnodist.fcp" % basedir, "Exp-KR_Nora":"%s/Data/FiveC/HiFive/Nora_ESC_male_E14_expKRnodist.fcp" % basedir, } data = {} imgs = {} ratio1 = 0 ratio2 = 0 for meth in ['Prob', 'Bin', 'Exp', 'Exp-KR']: fc = hifive.FiveC(fivec_fnames["%s_Phillips" % meth]) fragments = fc.frags['fragments'][...] regions = fc.frags['regions'][...] counts = numpy.zeros(0, dtype=numpy.float64) expected = numpy.zeros(0, dtype=numpy.float64) hic_counts = numpy.zeros(0, dtype=numpy.float64) hic_expected = numpy.zeros(0, dtype=numpy.float64) skipped = [] for i in range(fc.frags['regions'].shape[0]): temp = fc.cis_heatmap(i, datatype='fragment', arraytype='compact', binsize=0, skipfiltered=True) if temp is None: skipped.append(i) continue counts = numpy.hstack((counts, temp[:, :, 0].ravel())) expected = numpy.hstack((expected, temp[:, :, 1].ravel())) if i == 6: ratio1 = temp.shape[1] / float(temp.shape[0]) imgs["%s_Phillips" % meth] = hifive.plotting.plot_full_array(temp, symmetricscaling=False) if meth == 'Prob': temp1 = numpy.zeros((temp.shape[0], temp.shape[1]), dtype=numpy.float32) temp1[numpy.where(temp[:, :, 0] > 0.0)] = 1 if i == 6: imgs["Raw_Phillips"] = hifive.plotting.plot_full_array( numpy.dstack((temp[:, :, 0], temp1)), symmetricscaling=False) binbounds = numpy.hstack(( fragments['start'][regions['start_frag'][i]:regions['stop_frag'][i]].reshape(-1, 1), fragments['stop'][regions['start_frag'][i]:regions['stop_frag'][i]].reshape(-1, 1))) valid = numpy.where(fc.filter[regions['start_frag'][i]:regions['stop_frag'][i]])[0] binbounds = binbounds[valid, :] temp = hm_phillips[i] strands = fragments['strand'][regions['start_frag'][i]:regions['stop_frag'][i]][valid] temp = temp[numpy.where(strands == 0)[0], :, :][:, numpy.where(strands == 1)[0], :] hic_counts = numpy.hstack((hic_counts, temp[:, :, 0].ravel())) hic_expected = numpy.hstack((hic_expected, temp[:, :, 1].ravel())) if i == 6: imgs["HiC_Phillips"] = hifive.plotting.plot_full_array(temp, symmetricscaling=False) if meth == 'Prob': data["Raw_Phillips"] = numpy.copy(counts) where = numpy.where(hic_expected > 0.0)[0] hic_counts[where] /= hic_expected[where] data["HiC_Phillips"] = numpy.copy(hic_counts) where = numpy.where(expected > 0.0)[0] counts[where] /= expected[where] data["%s_Phillips" % meth] = numpy.copy(counts) fc = hifive.FiveC(fivec_fnames["%s_Nora" % meth]) temp = fc.cis_heatmap(0, datatype='fragment', arraytype='compact', binsize=0, skipfiltered=True) ratio2 = temp.shape[1] / float(temp.shape[0]) imgs["%s_Nora" % meth] = hifive.plotting.plot_full_array(temp, symmetricscaling=False) counts = temp[:, :, 0].ravel() expected = temp[:, :, 1].ravel() if meth == 'Prob': temp1 = numpy.zeros((temp.shape[0], temp.shape[1]), dtype=numpy.float32) temp1[numpy.where(temp[:, :, 0] > 0.0)] = 1 imgs["Raw_Nora"] = hifive.plotting.plot_full_array( numpy.dstack((temp[:, :, 0], temp1)), symmetricscaling=False) data["Raw_Nora"] = numpy.copy(counts) fragments = fc.frags['fragments'][...] regions = fc.frags['regions'][...] binbounds = numpy.hstack(( fragments['start'][regions['start_frag'][0]:regions['stop_frag'][0]].reshape(-1, 1), fragments['stop'][regions['start_frag'][0]:regions['stop_frag'][0]].reshape(-1, 1))) binbounds = binbounds[numpy.where(fc.filter[regions['start_frag'][0]:regions['stop_frag'][0]])[0], :] temp = hm_nora[0] strands = fragments['strand'][regions['start_frag'][0]:regions['stop_frag'][0]] temp = temp[numpy.where(strands==0)[0], :, :][:, numpy.where(strands == 1)[0], :] imgs["HiC_Nora"] = hifive.plotting.plot_full_array(temp, symmetricscaling=False) hic_counts = temp[:, :, 0].ravel() hic_expected = temp[:, :, 1].ravel() where = numpy.where(hic_expected > 0.0)[0] hic_counts[where] /= hic_expected[where] data["HiC_Nora"] = numpy.copy(hic_counts) where = numpy.where(expected > 0.0)[0] counts[where] /= expected[where] data["%s_Nora" % meth] = numpy.copy(counts) correlations = {} output = open(out_fname.replace('pdf', 'txt'), 'w') print >> output, "Method\tPhillips\tNora" for meth in methods: temp = [meth] for name in ["Phillips", "Nora"]: valid = numpy.where((data["%s_%s" % (meth, name)] > 0.0) * (data["HiC_%s" % name] > 0.0)) correlations["%s_%s" % (meth, name)] = numpy.corrcoef(numpy.log(data["%s_%s" % (meth, name)][valid]), numpy.log(data["HiC_%s" % name][valid]))[0, 1] temp.append(str(correlations["%s_%s" % (meth, name)])) print >> output, '\t'.join(temp) output.close() width = 16.8 spacer = 0.3 c = canvas.canvas() plot_width = (width - spacer * 3.0 - 0.4) / 4.0 for i, meth in enumerate(["Raw", "Prob", "HiC"]): meth_names = {"Raw":"Raw", "Prob":"HiFive", "HiC":"HiC"} c.text(plot_width * (i + 1.5) + spacer * (i + 1), (ratio1 + ratio2) * plot_width + spacer + 0.1, "%s" % meth_names[meth], [text.halign.center, text.valign.bottom, text.size(-2)]) c.insert(bitmap.bitmap(0, 0, imgs["%s_Phillips" % meth], width=plot_width), [trafo.translate((i + 1) * (plot_width + spacer), plot_width * ratio2 + spacer)]) c.insert(bitmap.bitmap(0, 0, imgs["%s_Nora" % meth], width=plot_width), [trafo.translate((i + 1) * (plot_width + spacer), 0)]) g = graph.graphxy(width=plot_width - 0.8, height=plot_width * ratio1, x=graph.axis.nestedbar(painter=graph.axis.painter.bar(nameattrs=None)), y=graph.axis.lin(painter=painter), x2=graph.axis.lin(parter=None, min=0, max=1), y2=graph.axis.lin(parter=None, min=0, max=1)) for i, meth in enumerate(methods): Y = numpy.zeros(2, dtype=numpy.float32) col = method_colors[meth] for j, name in enumerate(["Phillips", "Nora"]): Y[j] = correlations["%s_%s" % (meth, name)] g.plot(graph.data.points(zip(zip(range(Y.shape[0]), [i] * Y.shape[0]), Y), xname=1, y=2), [graph.style.changebar([col])]) g.text(-0.8, plot_width * ratio1 * 0.5, "Correlation", [text.halign.center, text.valign.top, text.size(-3), trafo.rotate(90)]) g.text((plot_width - 0.8) * 0.25, -0.1, "Phillips", [text.halign.center, text.valign.top, text.size(-3)]) g.text((plot_width - 0.8) * 0.75, -0.1, "Nora", [text.halign.center, text.valign.top, text.size(-3)]) c.insert(g, [trafo.translate(0.8, plot_width * ratio2 + spacer)]) c.text(width, (ratio1 + ratio2 * 0.5) * plot_width + spacer, "Phillips", [text.halign.center, text.valign.top, trafo.rotate(-90), text.size(-2)]) c.text(width, ratio1 * 0.5 * plot_width, "Nora", [text.halign.center, text.valign.top, trafo.rotate(-90), text.size(-2)]) meth_names = {"Raw":"Raw", "Prob":"HiFive-Probability", "Exp":"HiFive-Express", "Bin":"HiFive-Binning", "Exp-KR":"HiFive-ExpressKR", "Exp-KR-dist":"HiFive-ExpressKR-dist"} for i, meth in enumerate(methods): c.fill(path.rect(1.0, plot_width * ratio1 - 1.0 - i * 0.5, 0.2, 0.2), [method_colors[meth]]) c.text(1.3, plot_width * ratio1 - 0.9 - i * 0.5, "%s" % meth_names[meth], [text.halign.left, text.valign.middle, text.size(-3)]) c.writePDFfile(out_fname)
pyplot.show() quit() from pyx import canvas, graph, text, color, style, trafo, unit from pyx.graph import axis, key text.set(mode="latex") text.preamble(r"\usepackage{txfonts}") figwidth = 12 gkey = key.key(pos=None, hpos=0.05, vpos=0.8) xaxis = axis.linear(title=r"Time, \(t\)") yaxis = axis.linear(title="Signal", min=-5, max=17) g = graph.graphxy(width=figwidth, x=xaxis, y=yaxis, key=gkey) plotdata = [graph.data.values(x=t, y=signal+offset, title=label) for label, signal, offset in (r"\(A(t) = \mathrm{square}(2\pi t/T)\)", A, 2.5), (r"\(B(t) = \mathrm{sawtooth}(\phi + 2 \pi t/T)\)", B, -2.5)] linestyles = [style.linestyle.solid, style.linejoin.round, style.linewidth.Thick, color.gradient.Rainbow, color.transparency(0.5)] plotstyles = [graph.style.line(linestyles)] g.plot(plotdata, plotstyles) g.plot(graph.data.values(x=t, y=listX, title="Blah"), plotstyles) g.text(10*unit.x_pt, 0.56*figwidth, r"\textbf{Cross correlation of noisy anharmonic signals}") g.text(10*unit.x_pt, 0.33*figwidth, "Phase shift: input \(\phi = %.2f \,\pi\), recovered \(\phi = %.2f \,\pi\)" % (phase_shift/pi, recovered_phase_shift/pi)) xxaxis = axis.linear(title=r"Time Lag, \(\Delta t\)", min=-1.5, max=1.5) yyaxis = axis.linear(title=r"\(A(t) \star B(t)\)") gg = graph.graphxy(width=0.2*figwidth, x=xxaxis, y=yyaxis) plotstyles = [graph.style.line(linestyles + [color.rgb(0.2,0.5,0.2)])] #gg.plot(graph.data.values(x=dt, y=xcorr), plotstyles) gg.plot(graph.data.values(x=dt, y=xcorr, title="Blah"), plotstyles) gg.stroke(gg.xgridpath(recovered_time_shift), [style.linewidth.THIck, color.gray(0.5), color.transparency(0.7)]) ggtrafos = [trafo.translate(0.75*figwidth, 0.45*figwidth)] g.insert(gg, ggtrafos) g.writePDFfile("so-xcorr-pyx")
c.stroke(path.rect(x0 + 8 * size, y0, 4 * size, size), [deco.filled([codecolor])]) c.stroke(path.rect(x0 + 12 * size, y0, 6 * size, size), [deco.filled([codecolor])]) c.stroke(path.rect(x0 + 18 * size, y0, 6 * size, size), [deco.filled([codecolor])]) for n in range(len(codepointbinary)): c.text(x0 + (n + 0.5) * size, y0 + dy, r"\sffamily %i" % codepointbinary[n], [text.halign.center]) p = path.path(path.moveto(0.2 * size, size + 0.03), path.lineto(0.2 * size, size + 0.07), path.lineto(3.8 * size, size + 0.07), path.lineto(3.8 * size, size + 0.03)) for n in range(bits // 4): c.stroke(p, [trafo.translate(4 * n * size, y0)]) c.text((4 * n + 2) * size, size + 0.14 + y0, r"\sffamily %X" % (codepoint >> (bits // 4 - n - 1) * 4 & 0x0f), [text.halign.center]) utf8code = 0xE08080 \ + (((codepoint >> 12) & 0x0f) << 16) \ + (((codepoint >> 6) & 0x3f) << 8) \ + (codepoint & 0x3f) utf8codebinary = [(utf8code & 2**n) / 2**n for n in range(bits)] utf8codebinary.reverse() y1 = 2 c.fill(path.rect(x0, y1, 4 * size, size), [utf8markercolor, deco.stroked([utf8markercolor])]) c.fill(path.rect(x0 + 8 * size, y1, 2 * size, size),
text.preamble(r'\usepackage{color}') text.preamble(r'\definecolor{axis0}{rgb}{%s, %s, %s}' % (color0.r, color0.g, color0.b)) text.preamble(r'\definecolor{axis1}{rgb}{%s, %s, %s}' % (color1.r, color1.g, color1.b)) unit.set(xscale=1.2, wscale=1.5) c = canvas.canvas() m1 = np.arange(4).reshape(2, 2) c_m1 = matrix_22(m1) m2 = np.arange(4, 8).reshape(2, 2) c_m2 = matrix_22(m2) m3 = np.dot(m1, m2) c_m3 = matrix_22(m3, dx=0.7) c.insert(c_m1) c.insert(c_m2, [trafo.translate(c_m1.bbox().width() + 0.1, 0)]) end = c_m1.bbox().right() + c_m2.bbox().width() + 0.1 dist2 = 0.6 c.insert(c_m3, [trafo.translate(end + dist2 - c_m3.bbox().left(), 0)]) ycenter = 0.5 * (c_m1.bbox().top() + c_m1.bbox().bottom()) for dy in (-0.05, 0.05): c.stroke( path.line(end + 0.15, ycenter + dy, end + dist2 - 0.15, ycenter + dy)) c_tot = canvas.canvas() for y in range(4): c_tot.insert(c, [trafo.translate(0, 1.5 * y)]) dx = 0.2 colorprops = [color.rgb(0.8, 0.2, 0), color.transparency(0.2)] arrowprops = [deco.earrow] + colorprops
def plot_bargraph(data, width, height): methods = [ 'HiCLib', 'HiCPipe', 'HiCNorm', 'HiFive-Probability', 'HiFive-Binning', 'HiFive-Express', 'HiFive-ExpressKR', 'HiFive-ExpressKR w/distance' ] ho = 4.0 left_width = (width - ho) * 0.45 mid_width1 = (width - ho) * 0.3 mid_width2 = (width - ho) * 0.125 right_width = (width - ho) * 0.125 bar_height = height / len(methods) - 0.1 data_totals = {} ranges = numpy.zeros((4, 2), dtype=numpy.float32) for meth in data: data_totals[meth] = find_total(data[meth]) if meth == 'HiCPipe': ranges[1, 1] = data_totals[meth] elif meth == 'HiCNorm': ranges[2, 1] = data_totals[meth] elif meth == 'HiFive-Probability': ranges[3, 1] = data_totals[meth] else: ranges[0, 1] = max(ranges[0, 1], data_totals[meth]) ranges /= 60.0 ranges[0, 1] = 28.0 ranges[1, 0] = ranges[1, 1] - ranges[0, 1] / 0.45 * 0.3 * 0.9 ranges[1, 1] = ranges[1, 1] + ranges[0, 1] / 0.45 * 0.3 * 0.1 ranges[2, 0] = ranges[2, 1] - ranges[0, 1] / 0.45 * 0.125 * 0.5 ranges[2, 1] = ranges[2, 1] + ranges[0, 1] / 0.45 * 0.125 * 0.5 ranges[3, 0] = ranges[3, 1] - ranges[0, 1] / 0.45 * 0.125 * 0.5 ranges[3, 1] = ranges[3, 1] + ranges[0, 1] / 0.45 * 0.125 * 0.5 c = canvas.canvas() g1 = graph.graphxy(width=left_width, height=height, x=graph.axis.lin(painter=painter, min=0, max=ranges[0, 1]), x2=graph.axis.lin(parter=None, min=0, max=ranges[0, 1]), y=graph.axis.lin(parter=None, min=0, max=1), y2=graph.axis.lin(painter=None, min=0, max=1)) c.insert(g1) g2 = graph.graphxy(width=mid_width1, height=height, x=graph.axis.lin(painter=painter, min=ranges[1, 0], max=ranges[1, 1]), x2=graph.axis.lin(parter=None, min=ranges[1, 0], max=ranges[1, 1]), y2=graph.axis.lin(painter=None, min=0, max=1), y=graph.axis.lin(painter=None, min=0, max=1)) c.insert(g2, [trafo.translate(left_width, 0)]) g3 = graph.graphxy(width=mid_width2, height=height, x=graph.axis.lin(painter=painter, min=ranges[2, 0], max=ranges[2, 1]), x2=graph.axis.lin(parter=None, min=ranges[2, 0], max=ranges[2, 1]), y2=graph.axis.lin(painter=None, min=0, max=1), y=graph.axis.lin(painter=None, min=0, max=1)) c.insert(g3, [trafo.translate(left_width + mid_width1, 0)]) g4 = graph.graphxy(width=right_width, height=height, x=graph.axis.lin(painter=painter, min=ranges[3, 0], max=ranges[3, 1]), x2=graph.axis.lin(parter=None, min=ranges[3, 0], max=ranges[3, 1]), y2=graph.axis.lin(parter=None, min=0, max=1), y=graph.axis.lin(painter=None, min=0, max=1)) c.insert(g4, [trafo.translate(left_width + mid_width1 + mid_width2, 0)]) split = canvas.canvas() split.fill( path.path(path.moveto(-0.15, -0.2), path.lineto(0.05, 0.2), path.lineto(.15, 0.2), path.lineto(-0.05, -0.2), path.closepath()), [color.cmyk.White]) split.stroke(path.line(-0.15, -0.2, 0.05, 0.2)) split.stroke(path.line(-0.05, -0.2, 0.15, 0.2)) c.insert(split, [trafo.translate(left_width, 0)]) c.insert(split, [trafo.translate(left_width, height)]) c.insert(split, [trafo.translate(left_width + mid_width1, 0)]) c.insert(split, [trafo.translate(left_width + mid_width1, height)]) c.insert(split, [trafo.translate(left_width + mid_width1 + mid_width2, 0)]) c.insert(split, [trafo.translate(left_width + mid_width1 + mid_width2, height)]) for i, meth in enumerate(methods): c.insert( plot_bar(data[meth], ranges, bar_height, left_width / ranges[0, 1], split), [ trafo.translate(0, height - 0.05 - bar_height * (i + 1) - i * 0.1) ]) c.text(-0.1, height * (len(methods) - i - 0.5) / len(methods), meth, [text.halign.right, text.valign.middle, text.size(-2)]) c.text((width - ho) / 2.0, -0.35, "Runtime (minutes)", [text.halign.center, text.valign.top, text.size(-2)]) return c
from pyx import canvas, color, deformer, path, text, trafo, unit text.set(text.LatexRunner) text.preamble(r'''\usepackage[scaled=0.85,lining]{FiraMono} \usepackage[utf8]{inputenc}''') unit.set(xscale=1.2) c = canvas.canvas() dx = 0.3 h = 4 w = 6.5 p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx) p = deformer.smoothed(0.5).deform(p) c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)]) c.fill(p, [color.grey(0.9)]) c1 = canvas.canvas() boxwd = 0.7 for n in range(-5, 6): x = (n - 0.5) * boxwd c1.stroke(path.line(x, -0.5 * h - dx, x, 0.5 * h + dx)) for n in range(-5, 6): y = (n - 0.5) * boxwd c1.stroke(path.line(-0.5 * w - dx, y, 0.5 * w + dx, y)) highlight = color.rgb(0.7, 0, 0) template = r'\texttt{{\bfseries{}}}' pos = [0, 0] number = 1 c1.text(*pos, template.format(number), [text.halign.center, text.valign.middle, highlight])
julia_c = -0.8 + 0.156j schwelle = 50000 maxit = 600 julia_daten = [] for y in np.linspace(ymin, ymax, seitenlaenge): for x in np.linspace(xmin, xmax, seitenlaenge): iterationen = julia_iteration(x, y, julia_c, schwelle, maxit) julia_daten.append((x, y, iterationen / maxit)) c = canvas.canvas() dx = 0.3 h = 4 w = 6.5 p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx) p = deformer.smoothed(0.5).deform(p) c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)]) c1 = canvas.canvas([canvas.clip(p)]) g = graph.graphxy(height=8, width=8, x=graph.axis.linear(min=xmin, max=xmax), y=graph.axis.linear(min=ymin, max=ymax)) g.plot(graph.data.points(julia_daten, x=1, y=2, color=3, title="iterations"), [graph.style.density(gradient=color.rgbgradient.Rainbow)]) c1.insert(g, [trafo.translate(-0.1 * w, -0.5 * h)]) c.insert(c1) c.writeGSfile(device="png16m", resolution=300)
(2.5, -0.1, -0.5, graph.graphxyz.central(5, 210, -30))): for direction in range(3): for coord11, coord12 in zip(coordinates[:-1], coordinates[1:]): for coord21, coord22 in zip(coordinates[:-1], coordinates[1:]): pt1[direction] = side pt1[(direction + 1) % 3] = coord11 pt1[(direction + 2) % 3] = coord21 pt2[direction] = side pt2[(direction + 1) % 3] = coord12 pt2[(direction + 2) % 3] = coord21 pt3[direction] = side pt3[(direction + 1) % 3] = coord12 pt3[(direction + 2) % 3] = coord22 pt4[direction] = side pt4[(direction + 1) % 3] = coord11 pt4[(direction + 2) % 3] = coord22 p = path.path(path.moveto(*projector.point(*pt1)), path.lineto(*projector.point(*pt2)), path.lineto(*projector.point(*pt3)), path.lineto(*projector.point(*pt4)), path.closepath()) rgbcolor = [0, 0, 0] rgbcolor[direction] = side + 0.5 rgbcolor[(direction + 1) % 3] = (coord11 + coord12 + 1) / 2 rgbcolor[(direction + 2) % 3] = (coord21 + coord22 + 1) / 2 c.fill(p, [color.rgb(*rgbcolor), trafo.translate(x0, y0)]) filename = os.path.splitext(sys.argv[0])[0] + '.png' c.writeGSfile(filename, resolution=200)
x = baseprime % 25 y = 2 - (baseprime // 25) c.fill(path.rect(x, y, 1, -1), [primecolor]) c.text(x + 0.5, y - 0.5, r'\textbf{%s}' % baseprime, [text.halign.center, text.valign.middle, color.grey(1)]) for n in range(baseprime**2, 50, baseprime): if not n in cancelled: cancelled.add(n) x = n % 25 y = 2 - (n // 25) c.stroke(path.line(x, y - 1, x + 1, y), [primecolor]) c.stroke(path.line(x, y, x + 1, y - 1), [primecolor]) draw_grid() cc = canvas.canvas() cc.items = c.items[:] cgesamt.insert(cc, [trafo.translate(0, -2.3 * (nr + 1))]) for n in range(50): if not n in cancelled: x = n % 25 y = 2 - (n // 25) c.fill(path.rect(x, y, 1, -1), [color.hsb(0.15, 1, 0.8)]) c.text(x + 0.5, y - 0.5, r'\textbf{%s}' % n, [text.halign.center, text.valign.middle, color.grey(1)]) draw_grid() cgesamt.insert(c, [trafo.translate(0, -2.3 * (nr + 2))]) cgesamt.writePDFfile() cgesamt.writeGSfile(device="png16m", resolution=600)
pathsegments = [path.path(path.moveto(qi, 0), path.lineto(qf, 0)), path.path(path.moveto(qf, 0), path.lineto(width-radius, 0), path.arc(width-radius, radius, radius, -90, 90), path.lineto(qf, 2*radius)), path.path(path.moveto(qf, 0), path.lineto(qi, 0)), path.path(path.moveto(qi, 0), path.lineto(radius, 0), path.arcn(radius, radius, radius, 270, 90), path.lineto(qi, 2*radius))] anzahl_segmente = (1, 2, 2, 3) ypos = 0.5*dy for n in range(1, ntraj+1): offset = 0 if n % 2 == 0: offset = -1 nsegmente = anzahl_segmente[(n-1) % 4] + (n-1)//4*4 for nsegment in range(1, nsegmente+1): yshift = (-offset+nsegment-1)//2*2*radius c.stroke(pathsegments[(offset+nsegment-1) % 4], [trafo.translate(0, ypos+yshift), linecolor, style.linewidth.Thick]) c.stroke(path.circle(qi, ypos, 0.06), [style.linewidth.thick, linecolor, deco.filled([color.grey(1)])]) c.stroke(path.circle(qf, ypos+n//2*2*radius, 0.06), [style.linewidth.thick, linecolor, deco.filled([color.grey(1)])]) ypos = ypos + dy + (n//2)*2*radius c.writePDFfile()
arange = None drawgrid(c, 4, 3, 0, gridcolor, arange=arange) if hlshape is not None: c.stroke(path.rect(0, 3, hlshape[1], -hlshape[0]), [deco.filled([color.rgb(1, 0.8, 0.4)])]) drawgrid(c, hlshape[1], hlshape[0], 3 - hlshape[0], arange=False) if arange is None: alertcolor = color.rgb(0.6, 0, 0) c.stroke(path.line(0, 0, 4, 3), [alertcolor, style.linewidth.Thick]) c.stroke(path.line(0, 3, 4, 0), [alertcolor, style.linewidth.Thick]) return c text.set(text.LatexRunner) text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}') unit.set(xscale=1.2, wscale=1.5) xcells = 4 ycells = 3 gridcolor = color.grey(0.5) c = canvas.canvas() c.insert(array34(True)) c.insert(array34(False, (1, )), [trafo.translate(5, 0)]) c.insert(array34(False, (4, )), [trafo.translate(10, 0)]) c.insert(array34(False, (3, )), [trafo.translate(5, -4.5)]) c.insert(array34(False, (3, 1)), [trafo.translate(10, -4.5)]) c.writePDFfile()
def main(): out_fname = sys.argv[1] basedir = '/'.join( os.path.dirname(os.path.realpath(__file__)).split('/')[:-2]) hic_fname1 = "%s/Data/HiC/HiFive/mm9_ESC_NcoI_prob.hcp" % basedir hic_fname2 = "%s/Data/HiC/HiFive/mm9_ESC_HindIII_prob.hcp" % basedir fivec_fnames = { "Prob_Phillips": "%s/Data/FiveC/HiFive/Phillips_ESC_prob.fcp" % basedir, "Prob_Nora": "%s/Data/FiveC/HiFive/Nora_ESC_male_E14_prob.fcp" % basedir, "Bin_Phillips": "%s/Data/FiveC/HiFive/Phillips_ESC_bin.fcp" % basedir, "Bin_Nora": "%s/Data/FiveC/HiFive/Nora_ESC_male_E14_bin.fcp" % basedir, "Exp_Phillips": "%s/Data/FiveC/HiFive/Phillips_ESC_exp.fcp" % basedir, "Exp_Nora": "%s/Data/FiveC/HiFive/Nora_ESC_male_E14_exp.fcp" % basedir, "Exp-KR_Phillips": "%s/Data/FiveC/HiFive/Phillips_ESC_expKR.fcp" % basedir, "Exp-KR_Nora": "%s/Data/FiveC/HiFive/Nora_ESC_male_E14_expKR.fcp" % basedir, } hic1 = hifive.HiC(hic_fname1) hic2 = hifive.HiC(hic_fname2) hic_hm = {'Phillips': {}} fc = hifive.FiveC(fivec_fnames["Prob_Phillips"]) fragments = fc.frags['fragments'][...] regions = fc.frags['regions'][...] for i in range(fc.frags['regions'].shape[0]): binbounds = numpy.hstack( (fragments['start'] [regions['start_frag'][i]:regions['stop_frag'][i]].reshape(-1, 1), fragments['stop'] [regions['start_frag'][i]:regions['stop_frag'][i]].reshape(-1, 1))) binbounds = binbounds[numpy.where( fc.filter[regions['start_frag'][i]:regions['stop_frag'][i]])[0], :] hic_hm['Phillips'][i] = dynamically_bin(hic1, hic2, regions['chromosome'][i], binbounds) fc = hifive.FiveC(fivec_fnames["Prob_Nora"]) fragments = fc.frags['fragments'][...] regions = fc.frags['regions'][...] binbounds = numpy.hstack( (fragments['start'] [regions['start_frag'][0]:regions['stop_frag'][0]].reshape(-1, 1), fragments['stop'] [regions['start_frag'][0]:regions['stop_frag'][0]].reshape(-1, 1))) binbounds = binbounds[numpy.where( fc.filter[regions['start_frag'][0]:regions['stop_frag'][0]])[0], :] hic_hm['Nora'] = dynamically_bin(hic1, hic2, regions['chromosome'][0], binbounds) dist_corr = find_correlations(hic_hm, fivec_fnames, out_fname, True) nodist_corr = find_correlations(hic_hm, fivec_fnames, out_fname, False) c = canvas.canvas() width = 16.8 spacer = 0.4 plot_width = (width - spacer * 2) / 2.5 plot_height = plot_width key_width = width - (plot_width + spacer) * 2 phillips_img = plot_correlation_diffs(dist_corr, nodist_corr, 'Phillips', plot_width, plot_height) nora_img = plot_correlation_diffs(dist_corr, nodist_corr, 'Nora', plot_width, plot_height) key_img = plot_key(key_width, plot_height) c.insert(phillips_img) c.insert(nora_img, [trafo.translate(plot_width + spacer, 0)]) c.insert(key_img, [trafo.translate((plot_width + spacer) * 2, 0)]) c.text(0, plot_height, "a", [text.halign.left, text.valign.top, text.size(-1)]) c.text(plot_width + spacer, plot_height, "b", [text.halign.left, text.valign.top, text.size(-1)]) c.writePDFfile(out_fname)
c.fill(p, [clientcolor, trafo.translate(0, -1.3 * r)]) return c arrowcolor = color.grey(0.5) text.set(text.LatexRunner) text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}') unit.set(xscale=1.3) c = canvas.canvas() pos = [(0, 1), (sin(2 * pi / 3), cos(2 * pi / 3)), (-sin(2 * pi / 3), cos(2 * pi / 3))] sfak = 1.5 for x, y in pos: c.insert(server(0.3), [trafo.translate(sfak * x, sfak * y)]) c.insert(client(), [trafo.scale(0.5).translated(3 * x, 3 * y + 0.15)]) c.stroke(path.line(2.7 * x, 2.7 * y, 1.9 * x, 1.9 * y), [ arrowcolor, deco.earrow.large, deco.barrow.large, style.linewidth.THick ]) for phi in (0, 120, 240): c.stroke( path.curve(-sfak * sin(2 * pi / 3) + 0.4, -0.5 * sfak + 0.15, -sfak * sin(2 * pi / 3) + 0.8, -0.5 * sfak + 0.35, sfak * sin(2 * pi / 3) - 0.8, -0.5 * sfak + 0.35, sfak * sin(2 * pi / 3) - 0.4, -0.5 * sfak + 0.15), [ arrowcolor, deco.earrow.large, deco.barrow.large, style.linewidth.THick, trafo.rotate(phi) ]) c.insert(server(0.5, color.hsb(0.5, 0.8, 0.5), 0.13))
from pyx import metapost from pyx.metapost.path import beginknot, endknot, smoothknot, tensioncurve x0, y0 = tx0, ty0 = x, y dx, dy = 1.5, 1.5 # Grid for i in range(3): c.stroke(path.line(x0+0.5*dx, y0-(i+1.0)*dy, x0+3.5*dx, y0-(i+1.0)*dy)) c.stroke(path.line(x0+(i+1.0)*dx, y0-0.5*dy, x0+(i+1.0)*dx, y0-3.5*dy)) c.stroke(path.rect(1.*dx + pip, -2.*dy + pip, dx-2*pip, dy-2*pip), [green, style.linewidth.Thick, style.linestyle.dashed, trafo.translate(tx0, ty0)]) def pair((x0, y0), (x1, y1), clr=None): extra = [clr or blue, style.linewidth.Thick, style.linecap.round, trafo.translate(tx0, ty0)] c.stroke(path.line(x0, y0, x1, y1), extra) c.stroke(path.circle(x0, y0, 1.3*pip), extra) c.stroke(path.circle(x1, y1, 1.3*pip), extra) points0 = [ (1.3*dx, -1.7*dy), (1.3*dx, -2.5*dy), (2.6*dx, -1.4*dy), (3.4*dx, -1.4*dy), (1.7*dx, -1.7*dy), (1.7*dx, -2.5*dy)] points = list(points0)
for nr, (label, boxcolor, symbolcolor, status) in enumerate( (('working directory', color.hsb(0.87, 1, 0.6), color.rgb(0.6, 0, 0), 'modified'), ('staging area', color.hsb(0.2, 1, 0.6), color.rgb(0, 0.5, 0), 'staged'), ('repository (.git)', color.hsb(0.53, 1, 0.6), color.grey(0.3), 'committed'))): xmid = nr * (wd + hdist) + 0.5 * wd c.stroke(path.rect(nr * (wd + hdist), 0, wd, ht), [deformer.smoothed(0.3), boxcolor, style.linewidth.Thick]) c.fill(path.rect(nr * (wd + hdist), ht + vdist, wd, htlabel), [deformer.smoothed(0.3), boxcolor]) c.text(xmid, ht + vdist + 0.5 * htlabel, label, [text.halign.center, text.valign.middle, color.grey(1)]) c.insert(filesymbol(size, symbolcolor), [trafo.translate(xmid, 0.55 * (ht - htlabel))]) c.text(xmid, 0.2 * (ht - htlabel), status, [text.halign.center, symbolcolor]) ht = ht - htlabel for nr, operation in enumerate(('git add', 'git commit')): xmid = nr * (wd + hdist) + 0.5 * wd c.stroke( path.line(xmid + 0.5 * size + 0.1, 0.55 * ht, xmid + wd + hdist - 0.5 * size - 0.1, 0.55 * ht), [deco.earrow.large, style.linewidth.Thick]) cop = canvas.canvas() optext = text.text(0, 0, operation, [text.halign.center, text.valign.middle]) tblarge = optext.bbox().enlarged(0.1) cop.fill(tblarge.path(), [deco.stroked([color.grey(0)]), color.grey(0.9)])
r'$\phi_\text{f}$')): c.text((tick_outer + 0.3) * cos(_angle), (tick_outer + 0.3) * sin(_angle), label, [text.halign.center, text.valign.middle, endpointcolor]) if windingnumber: c.text(0, -radius - 0.3, '$n={}$'.format(n), [text.halign.center, text.valign.top]) c.stroke(spiral(radius, angle, n), [pathcolor, style.linewidth.Thick]) return c radius = 1.5 text.set(engine=text.LatexEngine) text.preamble(r'''\usepackage[sfdefault,lining,scaled=.85]{FiraSans} \usepackage{newtxsf}''') unit.set(vscale=1.2, wscale=1.3, xscale=1.3) basename = os.path.splitext(sys.argv[0])[0] c = canvas.canvas() dx = 3.5 * radius for nr, n in enumerate((0, -1)): c.insert(winding(n, radius), [trafo.translate(nr * dx, 0)]) c.writePDFfile('{}_1'.format(basename)) c = canvas.canvas() for nr, n in enumerate((1, -2, 2)): c.insert(winding(n, radius, windingnumber=True), [trafo.translate(nr * dx, 0)]) c.writePDFfile('{}_2'.format(basename))
'pentadecathlon': [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] } text.set(text.LatexRunner) unit.set(xscale=4, wscale=2) c = canvas.canvas() xpos = 0 for k in ('blinker', 'beacon', 'toad', 'glider', 'pentadecathlon', 'pulsar'): c.insert(draw_config(k), [trafo.translate(xpos, 0)]) wd = len(configs[k][0]) c.text(xpos+0.5*wd, -0.5, r'\sffamily {}'.format(k), [text.halign.center, text.valign.top]) xpos = xpos+wd+1 filename = os.path.splitext(sys.argv[0])[0]+'.png' c.writeGSfile(filename, resolution=200)
c.stroke(path.curve(x-dist/3, -0.5*dist, x+0.5*wd, -5*dist, x+(lowerstride-0.5)*wd+lowerstride*dist, -5*dist, x+lowerstride*wd+(lowerstride-0.7)*dist, -0.5*dist), [deco.earrow.large]) c.text(x+0.5*lowerstride*wd+dist,-5.2*dist, r'\Large %i' % (lowerstride*8), [text.halign.center, text.valign.top, textcolor]) return c text.set(text.LatexRunner) text.preamble(r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}') unit.set(xscale=1.6, wscale=1.5) c = canvas.canvas() for nr, stride in enumerate((2, 3, 0)): c.insert(make_stride_figure(stride), [trafo.translate(0, 6*nr)]) s1 = 8*stride if stride: s = ', '.join([str(s1), '8']) else: s = '8,' c.text(0, 6*nr+2.5, '\\Large ({})'.format(s)) xoff = -5 yoff = 1 for nr, matrix in enumerate((r'$\begin{{pmatrix}}{} & {}\\{} & {}\\{} & {}\end{{pmatrix}}$', r'$\begin{{pmatrix}}{} & {} & {}\\{} & {} & {}\end{{pmatrix}}$', r'$\begin{{pmatrix}}{} & {} & {} & {} & {} & {}\end{{pmatrix}}$')): m = matrix.format(*map(lambda x: '\\text{}'.format(x), range(6))) c.text(xoff, 6*nr+yoff, '\\Large '+m, [text.halign.center, text.valign.middle])
gitlabfgcolor = color.grey(0.4) gitlabbgcolor = color.grey(0.97) maintainercolor = color.hsb(0.7, 1, 0.5) usercolor = color.hsb(0.05, 1, 0.5) c.stroke(path.rect(0, 0, wd, ht), [ deformer.smoothed(0.1), gitlabfgcolor, style.linewidth.Thick, deco.filled([gitlabbgcolor]) ]) clabel = canvas.canvas() labeltext = text.text(0, 0, r'\textsf{\bfseries Gitlab}', [color.grey(1)]) extrawd = 0.15 labelbox = labeltext.bbox().enlarged(extrawd) clabel.fill(labelbox.path(), [gitlabfgcolor, deformer.smoothed(0.1)]) clabel.insert(labeltext) c.insert(clabel, [trafo.translate(extrawd, ht + extrawd)]) c.text(wd + 0.4, ht - 0.5, r'\footnotesize\textsf{read/write permissions}') c.insert(read(1, usercolor), [trafo.translate(wd + 0.7, ht - 0.9)]) c.insert(write(1, usercolor), [trafo.translate(wd + 1.05, ht - 0.9)]) c.text(wd + 1.5, ht - 1.0, r'\footnotesize\textsf{user}', [usercolor]) c.insert(write(1, maintainercolor), [trafo.translate(wd + 1.05, ht - 1.3)]) c.insert(read(1, maintainercolor), [trafo.translate(wd + 0.7, ht - 1.3)]) c.text(wd + 1.5, ht - 1.4, r'\footnotesize\textsf{maintainer}', [maintainercolor]) c.insert(repo('upstream', color.hsb(0.55, 1, 0.6), color.hsb(0.55, 0.1, 1)), [trafo.translate(0.5, 2.8)]) c.insert(read(1, maintainercolor), [trafo.translate(0.85, 2.3)]) c.insert(write(1, maintainercolor), [trafo.translate(1.2, 2.3)]) c.insert(read(1, usercolor), [trafo.translate(1.65, 2.3)])
[text.halign.center, text.valign.middle]) c.stroke(path.rect(0, baseshape[0], shape[1], -shape[0])) for nx in range(1, shape[1]): c.stroke(path.line(nx, baseshape[0], nx, baseshape[0] - shape[0])) for ny in range(1, shape[0]): c.stroke(path.line(0, ny, shape[1], ny)) if not (shape == baseshape): for nx in range(shape[1]): for ny in range(shape[0]): c.text(nx + 0.5, baseshape[0] - ny - 0.5, str(baseshape[1] * ny + nx + 1), [text.halign.center, text.valign.middle]) return c text.set(text.LatexRunner) text.preamble( r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}') unit.set(xscale=1.6, wscale=1.5) c = canvas.canvas() c.insert(array((3, 4))) c.insert(array((1, )), [trafo.translate(5, 0)]) c.insert(array((4, )), [trafo.translate(10, 0)]) c.insert(array((3, )), [trafo.translate(5, -4.5)]) c.insert(array((3, 1)), [trafo.translate(10, -4.5)]) c.writePDFfile() c.writeGSfile(device="png16m", resolution=600)
def main(): out_fname = sys.argv[1] basedir = '/'.join( os.path.dirname(os.path.realpath(__file__)).split('/')[:-2]) mm9_methods = { 'HiFive-Probability': '%s/Analysis/hifive_mm9_ESC_prob_correlations.txt' % basedir, 'HiFive-Express': '%s/Analysis/hifive_mm9_ESC_exp_correlations.txt' % basedir, 'HiFive-Binning': '%s/Analysis/hifive_mm9_ESC_bin_correlations.txt' % basedir, 'HiCNorm': '%s/Analysis/hicnorm_mm9_ESC_correlations.txt' % basedir, 'HiCPipe': '%s/Analysis/hicpipe_mm9_ESC_correlations.txt' % basedir, 'Matrix-Balancing': '%s/Analysis/mb_mm9_ESC_correlations.txt' % basedir, } hg19_methods = { 'HiFive-Probability': '%s/Analysis/hifive_hg19_GM12878_prob_correlations.txt' % basedir, 'HiFive-Express': '%s/Analysis/hifive_hg19_GM12878_exp_correlations.txt' % basedir, 'HiFive-Binning': '%s/Analysis/hifive_hg19_GM12878_bin_correlations.txt' % basedir, 'HiCNorm': '%s/Analysis/hicnorm_hg19_GM12878_correlations.txt' % basedir, 'HiCPipe': '%s/Analysis/hicpipe_hg19_GM12878_correlations.txt' % basedir, 'Matrix-Balancing': '%s/Analysis/mb_hg19_GM12878_correlations.txt' % basedir, } mm9_data = load_data(mm9_methods) hg19_data = load_data(hg19_methods) width = 16.8 spacer = 0.4 overall_width = (width - spacer * 2) / 2.6 c = canvas.canvas() mm9_ranges_img, mm9_ranges_height = plot_dataset_ranges( mm9_data, width, "MM9 ESC") mm9_ranges_img.text(0, mm9_ranges_height, 'a', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(mm9_ranges_img) hg19_ranges_img, hg19_ranges_height = plot_dataset_ranges( hg19_data, width, "HG19 GM12878") hg19_ranges_img.text(0, hg19_ranges_height, 'b', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(hg19_ranges_img, [trafo.translate(0, -hg19_ranges_height - spacer)]) overall_height = mm9_ranges_height * 0.6 mm9_overall_img = plot_overall(mm9_data, overall_width, overall_height, "MM9 ESC") mm9_overall_img.text(0, overall_height + 0.1, 'c', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(mm9_overall_img, [ trafo.translate(0, -hg19_ranges_height - overall_height - spacer * 2) ]) hg19_overall_img = plot_overall(hg19_data, overall_width, overall_height, "HG19 GM12878") hg19_overall_img.text(0, overall_height + 0.1, 'd', [text.halign.left, text.valign.top, text.size(-1)]) c.insert(hg19_overall_img, [ trafo.translate(overall_width * 1.6 + spacer * 2, -hg19_ranges_height - overall_height - spacer * 2) ]) c.insert(plot_key(overall_width * 0.6 + 0.4, overall_height), [ trafo.translate(overall_width + spacer + 0.6, -hg19_ranges_height - overall_height - spacer * 2) ]) c.writePDFfile(out_fname)
def plot_bargraph(data, width, height): methods = ['HiCLib', 'HiCPipe', 'HiCNorm', 'HiFive-Probability', 'HiFive-Binning', 'HiFive-Express', 'HiFive-ExpressKR', 'HiFive-ExpressKR w/distance'] ho = 4.0 left_width = (width - ho) * 0.45 mid_width1 = (width - ho) * 0.3 mid_width2 = (width - ho) * 0.125 right_width = (width - ho) * 0.125 bar_height = height / len(methods) - 0.1 data_totals = {} ranges = numpy.zeros((4, 2), dtype=numpy.float32) for meth in data: data_totals[meth] = find_total(data[meth]) if meth == 'HiCPipe': ranges[1, 1] = data_totals[meth] elif meth == 'HiCNorm': ranges[2, 1] = data_totals[meth] elif meth == 'HiFive-Probability': ranges[3, 1] = data_totals[meth] else: ranges[0, 1] = max(ranges[0, 1], data_totals[meth]) ranges /= 60.0 ranges[0, 1] = 28.0 ranges[1, 0] = ranges[1, 1] - ranges[0, 1] / 0.45 * 0.3 * 0.9 ranges[1, 1] = ranges[1, 1] + ranges[0, 1] / 0.45 * 0.3 * 0.1 ranges[2, 0] = ranges[2, 1] - ranges[0, 1] / 0.45 * 0.125 * 0.5 ranges[2, 1] = ranges[2, 1] + ranges[0, 1] / 0.45 * 0.125 * 0.5 ranges[3, 0] = ranges[3, 1] - ranges[0, 1] / 0.45 * 0.125 * 0.5 ranges[3, 1] = ranges[3, 1] + ranges[0, 1] / 0.45 * 0.125 * 0.5 c = canvas.canvas() g1 = graph.graphxy(width=left_width, height=height, x=graph.axis.lin(painter=painter, min=0, max=ranges[0, 1]), x2=graph.axis.lin(parter=None, min=0, max=ranges[0, 1]), y=graph.axis.lin(parter=None, min=0, max=1), y2=graph.axis.lin(painter=None, min=0, max=1)) c.insert(g1) g2 = graph.graphxy(width=mid_width1, height=height, x=graph.axis.lin(painter=painter, min=ranges[1, 0], max=ranges[1, 1]), x2=graph.axis.lin(parter=None, min=ranges[1, 0], max=ranges[1, 1]), y2=graph.axis.lin(painter=None, min=0, max=1), y=graph.axis.lin(painter=None, min=0, max=1)) c.insert(g2, [trafo.translate(left_width, 0)]) g3 = graph.graphxy(width=mid_width2, height=height, x=graph.axis.lin(painter=painter, min=ranges[2, 0], max=ranges[2, 1]), x2=graph.axis.lin(parter=None, min=ranges[2, 0], max=ranges[2, 1]), y2=graph.axis.lin(painter=None, min=0, max=1), y=graph.axis.lin(painter=None, min=0, max=1)) c.insert(g3, [trafo.translate(left_width + mid_width1, 0)]) g4 = graph.graphxy(width=right_width, height=height, x=graph.axis.lin(painter=painter, min=ranges[3, 0], max=ranges[3, 1]), x2=graph.axis.lin(parter=None, min=ranges[3, 0], max=ranges[3, 1]), y2=graph.axis.lin(parter=None, min=0, max=1), y=graph.axis.lin(painter=None, min=0, max=1)) c.insert(g4, [trafo.translate(left_width + mid_width1 + mid_width2, 0)]) split = canvas.canvas() split.fill(path.path(path.moveto(-0.15, -0.2), path.lineto(0.05, 0.2), path.lineto(.15, 0.2), path.lineto(-0.05, -0.2), path.closepath()), [color.cmyk.White]) split.stroke(path.line(-0.15, -0.2, 0.05, 0.2)) split.stroke(path.line(-0.05, -0.2, 0.15, 0.2)) c.insert(split, [trafo.translate(left_width, 0)]) c.insert(split, [trafo.translate(left_width, height)]) c.insert(split, [trafo.translate(left_width + mid_width1, 0)]) c.insert(split, [trafo.translate(left_width + mid_width1, height)]) c.insert(split, [trafo.translate(left_width + mid_width1 + mid_width2, 0)]) c.insert(split, [trafo.translate(left_width + mid_width1 + mid_width2, height)]) for i, meth in enumerate(methods): c.insert(plot_bar(data[meth], ranges, bar_height, left_width / ranges[0, 1], split), [trafo.translate(0, height - 0.05 - bar_height * (i + 1) - i * 0.1)]) c.text(-0.1, height * (len(methods) - i - 0.5) / len(methods), meth, [text.halign.right, text.valign.middle, text.size(-2)]) c.text((width - ho) / 2.0, -0.35, "Runtime (minutes)", [text.halign.center, text.valign.top, text.size(-2)]) return c
def plot_overall(data, width, height, name): vo = 0.55 ho = 0.7 plot_width = width - ho plot_height = height - vo - 0.3 c = canvas.canvas() methods = data.keys() methods.sort() bar_colors = [] cis_binsizes = numpy.unique(data[methods[0]]['binsize'][numpy.where( data[methods[0]]['interaction'] == 'cis')]) trans_binsizes = numpy.unique(data[methods[0]]['binsize'][numpy.where( data[methods[0]]['interaction'] == 'trans')]) Y = numpy.zeros( (len(methods), cis_binsizes.shape[0] + trans_binsizes.shape[0]), dtype=numpy.float32) for i, method in enumerate(methods): for j, binsize in enumerate(cis_binsizes): where = numpy.where((data[method]['binsize'] == binsize) * (data[method]['interaction'] == 'cis') * (data[method]['range'] == 0)) if where[0].shape[0] > 0: Y[i, j] = data[method]['correlation'][where] for j, binsize in enumerate(trans_binsizes): where = numpy.where((data[method]['binsize'] == binsize) * (data[method]['interaction'] == 'trans') * (data[method]['range'] == 0)) if where[0].shape[0] > 0: Y[i, j + cis_binsizes.shape[0]] = data[method]['correlation'][where] bar_colors.append(method_colors[method]) Y = numpy.array(Y) g = graph.graphxy( width=plot_width, height=plot_height, x=graph.axis.nestedbar(painter=graph.axis.painter.bar(nameattrs=None)), y=graph.axis.lin(painter=painter), x2=graph.axis.lin(parter=None, min=0, max=1), y2=graph.axis.lin(parter=None, min=0, max=1)) for i in range(len(methods)): g.plot( graph.data.points(zip(zip(range(Y.shape[1]), [i] * Y.shape[1]), Y[i, :]), xname=1, y=2), [graph.style.changebar([method_colors[methods[i]]])]) c.insert(g, [trafo.translate(ho, vo)]) for i, label in enumerate(["10Kb", "50Kb", "250Kb", "1Mb", "250Kb", "1Mb"]): c.text(ho + plot_width * (i + 0.5) / 6.0, vo - 0.05, "%s" % label, [text.halign.center, text.valign.top, text.size(-3)]) c.text(ho + plot_width * 2.0 / 6.0, 0.05, "cis", [text.halign.center, text.valign.bottom, text.size(-3)]) c.stroke( path.line(ho + 0.2, vo * 0.5, ho - 0.2 + plot_width * 4.0 / 6.0, vo * 0.5), [style.linewidth.THin]) c.text(ho + plot_width * 5.0 / 6.0, 0.05, "trans", [text.halign.center, text.valign.bottom, text.size(-3)]) c.stroke( path.line(ho + 0.2 + plot_width * 4.0 / 6.0, vo * 0.5, ho - 0.2 + plot_width, vo * 0.5), [style.linewidth.THin]) c.text( 0, plot_height * 0.5 + vo, "Correlation", [text.halign.center, text.valign.top, text.size(-3), trafo.rotate(90)]) c.text(plot_width * 0.5 + ho, height, name, [text.halign.center, text.valign.top, text.size(-3)]) return c
def main(): width = 16.8 out_fname = sys.argv[1] basedir = "%s/Analysis/Timing" % '/'.join( os.path.dirname(os.path.realpath(__file__)).split('/')[:-2]) data_fnames = { "HiFive-Probability": { '0': "%s/hifive_data" % basedir, '1': "%s/hifive_project" % basedir, '3': '%s/hifive_prob' % basedir, '4': "%s/hifive_prob_heatmap" % basedir }, "HiFive-Binning": { '0': "%s/hifive_data" % basedir, '1': "%s/hifive_project_nodist" % basedir, '3': '%s/hifive_bin' % basedir, '4': "%s/hifive_bin_heatmap" % basedir }, "HiFive-Express": { '0': "%s/hifive_data" % basedir, '1': "%s/hifive_project" % basedir, '3': '%s/hifive_exp' % basedir, '4': "%s/hifive_exp_heatmap" % basedir }, "HiFive-ExpressKR": { '0': "%s/hifive_data" % basedir, '1': "%s/hifive_project_nodist" % basedir, '3': '%s/hifive_expKR' % basedir, '4': "%s/hifive_expKR_heatmap" % basedir }, "HiFive-ExpressKR w/distance": { '0': "%s/hifive_data" % basedir, '1': "%s/hifive_project" % basedir, '3': '%s/hifive_expKRdist' % basedir, '4': "%s/hifive_expKRdist_heatmap" % basedir }, "HiCPipe": { '0': "%s/bam2raw" % basedir, '1': "%s/hicpipe_data" % basedir, '2': '%s/hicpipe_binning' % basedir, '3': '%s/hicpipe_norm' % basedir, '4': '%s/hicpipe_heatmap' % basedir }, "HiCLib": { '0': "%s/hiclib_mapping" % basedir, '1': '%s/hiclib_data' % basedir, '3': "%s/hiclib_norm" % basedir, '4': '%s/hiclib_heatmap' % basedir }, "HiCNorm": { '0': "%s/bam2raw" % basedir, '1': "%s/hicpipe_data" % basedir, "2": "%s/hicnorm_data" % basedir, '3': '%s/hicnorm_norm' % basedir }, } data = load_data(data_fnames) c = canvas.canvas() c.insert(plot_bargraph(data, width, 4.0), [trafo.translate(4.0, 0)]) c.insert(plot_key(width * 0.3, 1.5), [trafo.translate(width * 0.75 - 1.0, 0.2)]) c.writePDFfile(out_fname)
def plot_overall(data0, data1, width, height): vo = 1.15 ho = 1.15 plot_width = width - ho plot_height = height - vo c = canvas.canvas() cis_binsizes = numpy.unique( data0['binsize'][numpy.where(data0['interaction'] == 'cis')]) trans_binsizes = numpy.unique( data0['binsize'][numpy.where(data0['interaction'] == 'trans')]) ymin = numpy.inf ymax = -numpy.inf Y = numpy.zeros((cis_binsizes.shape[0] + trans_binsizes.shape[0]), dtype=numpy.float32) for j, binsize in enumerate(cis_binsizes): where = numpy.where( (data0['binsize'] == binsize) * (data0['interaction'] == 'cis') * (data0['range'] < 0)) where1 = numpy.where( (data1['binsize'] == binsize) * (data1['interaction'] == 'cis') * (data1['range'] < 0)) if where[0].shape[0] > 0: Y[j] = (data1['correlation'][where1] - data0['correlation'][where]) ymin = min(ymin, Y[j]) ymax = max(ymax, Y[j]) for j, binsize in enumerate(trans_binsizes): where = numpy.where( (data0['binsize'] == binsize) * (data0['interaction'] == 'trans') * (data0['range'] < 0)) where1 = numpy.where( (data1['binsize'] == binsize) * (data1['interaction'] == 'trans') * (data1['range'] < 0)) if where[0].shape[0] > 0: Y[j + cis_binsizes.shape[0]] = (data1['correlation'][where1] - data0['correlation'][where]) ymin = min(ymin, Y[j + cis_binsizes.shape[0]]) ymax = max(ymax, Y[j + cis_binsizes.shape[0]]) yspan = ymax - ymin ymin -= yspan * 0.05 ymax += yspan * 0.05 Y = numpy.array(Y) g = graph.graphxy( width=plot_width, height=plot_height, x=graph.axis.bar(painter=graph.axis.painter.bar(nameattrs=None)), y=graph.axis.lin(painter=painter, min=ymin, max=ymax), x2=graph.axis.lin(parter=None, min=0, max=1), y2=graph.axis.lin(parter=None, min=0, max=1)) y0 = plot_height * (-ymin) / (ymax - ymin) g.stroke( path.line(0, plot_height * (-ymin) / (ymax - ymin), plot_width, plot_height * (-ymin) / (ymax - ymin)), [style.linestyle.dotted, style.linewidth.THin]) w0 = plot_width / Y.shape[0] w1 = w0 / 1.5 for j in range(Y.shape[0]): x = j * w0 + 0.25 * w1 y = plot_height * (Y[j] - ymin) / (ymax - ymin) g.fill(path.rect(x, y0, w1, y - y0)) c.insert(g, [trafo.translate(ho, vo)]) for i, label in enumerate(["10Kb", "50Kb", "250Kb", "1Mb", "250Kb", "1Mb"]): c.text(ho + plot_width * (i + 0.5) / 6.0, vo - 0.05, "%s" % label, [ text.halign.right, text.valign.middle, text.size(-3), trafo.rotate(90) ]) c.text(ho + plot_width * 2.0 / 6.0, 0, "cis", [text.halign.center, text.valign.bottom, text.size(-3)]) c.stroke(path.line(ho + 0.2, 0.3, ho - 0.2 + plot_width * 4.0 / 6.0, 0.3), [style.linewidth.THin]) c.text(ho + plot_width * 5.0 / 6.0, 0, "trans", [text.halign.center, text.valign.bottom, text.size(-3)]) c.stroke( path.line(ho + 0.2 + plot_width * 4.0 / 6.0, 0.3, ho - 0.2 + plot_width, 0.3), [style.linewidth.THin]) c.text( 0, plot_height * 0.5 + vo, r"$r_{Poisson} - r_{binomial}$", [text.halign.center, text.valign.top, text.size(-2), trafo.rotate(90)]) c.text(0, height, 'b', [text.halign.left, text.valign.top, text.size(-1)]) return c
y0 = 3 dy = 0.07 c.fill(path.rect(x0, y0, 5*size, size), [color.grey(0.5), deco.stroked([color.grey(0.5)])]) c.stroke(path.rect(x0+5*size, y0, 5*size, size)) c.stroke(path.rect(x0+10*size, y0, 6*size, size)) for n in range(len(codepointbinary)): c.text(x0+(n+0.5)*size, y0+dy, r"\sffamily %i" % codepointbinary[n], [text.halign.center]) p = path.path(path.moveto(0.2*size, size+0.03), path.lineto(0.2*size, size+0.07), path.lineto(3.8*size, size+0.07), path.lineto(3.8*size, size+0.03)) for n in range(bits//4): c.stroke(p, [trafo.translate(4*n*size, y0)]) c.text((4*n+2)*size, size+0.14+y0, r"\sffamily %X" % (codepoint >> (bits//4-n-1)*4 & 0x0f), [text.halign.center]) utf8code = 0xC080 \ + (((codepoint >> 6) & 0x1f) << 8) \ + (codepoint & 0x3f) utf8codebinary = [(utf8code & 2**n)/2**n for n in range(bits)] utf8codebinary.reverse() y1 = 2 c.fill(path.rect(x0, y1, 3*size, size), [color.grey(0.8), deco.stroked([color.grey(0.8)])]) c.fill(path.rect(x0+8*size, y1, 2*size, size), [color.grey(0.8), deco.stroked([color.grey(0.8)])])
def plot_overall(data0, data1, width, height): vo = 0.55 ho = 1.1 plot_width = width - ho plot_height = height - vo c = canvas.canvas() methods = data0.keys() methods.sort() bar_colors = [] cis_binsizes = numpy.unique(data0[methods[0]]['binsize'][numpy.where( data0[methods[0]]['interaction'] == 'cis')]) trans_binsizes = numpy.unique(data0[methods[0]]['binsize'][numpy.where( data0[methods[0]]['interaction'] == 'trans')]) ymin = numpy.inf ymax = -numpy.inf Y = numpy.zeros( (len(methods), cis_binsizes.shape[0] + trans_binsizes.shape[0]), dtype=numpy.float32) for i, method in enumerate(methods): for j, binsize in enumerate(cis_binsizes): where = numpy.where((data0[method]['binsize'] == binsize) * (data0[method]['interaction'] == 'cis') * (data0[method]['range'] < 0)) where1 = numpy.where((data1[method]['binsize'] == binsize) * (data1[method]['interaction'] == 'cis') * (data1[method]['range'] < 0)) if where[0].shape[0] > 0: Y[i, j] = (data1[method]['correlation'][where1] - data0[method]['correlation'][where]) ymin = min(ymin, Y[i, j]) ymax = max(ymax, Y[i, j]) for j, binsize in enumerate(trans_binsizes): where = numpy.where((data0[method]['binsize'] == binsize) * (data0[method]['interaction'] == 'trans') * (data0[method]['range'] < 0)) where1 = numpy.where((data1[method]['binsize'] == binsize) * (data1[method]['interaction'] == 'trans') * (data1[method]['range'] < 0)) if where[0].shape[0] > 0: Y[i, j + cis_binsizes.shape[0]] = ( data1[method]['correlation'][where1] - data0[method]['correlation'][where]) ymin = min(ymin, Y[i, j + cis_binsizes.shape[0]]) ymax = max(ymax, Y[i, j + cis_binsizes.shape[0]]) bar_colors.append(method_colors[method]) yspan = ymax - ymin ymin -= yspan * 0.05 ymax += yspan * 0.05 Y = numpy.array(Y) g = graph.graphxy( width=plot_width, height=plot_height, x=graph.axis.nestedbar(painter=graph.axis.painter.bar(nameattrs=None)), y=graph.axis.lin(painter=painter, min=ymin, max=ymax), x2=graph.axis.lin(parter=None, min=0, max=1), y2=graph.axis.lin(parter=None, min=0, max=1)) y0 = plot_height * (-ymin) / (ymax - ymin) g.stroke( path.line(0, plot_height * (-ymin) / (ymax - ymin), plot_width, plot_height * (-ymin) / (ymax - ymin)), [style.linestyle.dotted, style.linewidth.THin]) w0 = plot_width / Y.shape[1] w1 = w0 / (len(methods) + 0.5) for i in range(len(methods)): for j in range(Y.shape[1]): x = j * w0 + (i + 0.25) * w1 y = plot_height * (Y[i, j] - ymin) / (ymax - ymin) g.stroke(path.rect(x, y0, w1, y - y0), [deco.filled([method_colors[methods[i]]])]) c.insert(g, [trafo.translate(ho, vo)]) for i, label in enumerate(["10Kb", "50Kb", "250Kb", "1Mb", "250Kb", "1Mb"]): c.text(ho + plot_width * (i + 0.5) / 6.0, vo - 0.05, "%s" % label, [text.halign.center, text.valign.top, text.size(-3)]) c.text(ho + plot_width * 2.0 / 6.0, 0.05, "cis", [text.halign.center, text.valign.bottom, text.size(-3)]) c.stroke( path.line(ho + 0.2, vo * 0.5, ho - 0.2 + plot_width * 4.0 / 6.0, vo * 0.5), [style.linewidth.THin]) c.text(ho + plot_width * 5.0 / 6.0, 0.05, "trans", [text.halign.center, text.valign.bottom, text.size(-3)]) c.stroke( path.line(ho + 0.2 + plot_width * 4.0 / 6.0, vo * 0.5, ho - 0.2 + plot_width, vo * 0.5), [style.linewidth.THin]) c.text( 0, plot_height * 0.5 + vo, r"$r_{0K} - r_{500K}$", [text.halign.center, text.valign.top, text.size(-2), trafo.rotate(90)]) return c
def interface(): # <<< c = None for p in [ # ordinary open path: mppath.path([ beginknot(0, 0), curve(), knot(6, 4), curve(), knot(4, 9), curve(), knot(1, 7), curve(), endknot(3, 5) ], epsilon), # path containing two open subpaths: mppath.path([ beginknot(0, 0), curve(), endknot(6, 4), beginknot(4, 9), curve(), knot(1, 7), curve(), endknot(3, 5) ], epsilon), # closed path: mppath.path([ knot(0, 0), curve(), knot(6, 4), curve(), knot(4, 9), curve(), knot(1, 7), curve(), knot(3, 5), curve() ], epsilon), # open path, but with endpoints in the middle: mppath.path([ knot(0, 0), curve(), knot(6, 4), curve(), endknot(4, 9), beginknot(1, 7), curve(), knot(3, 5), curve() ], epsilon), # the same path in the right order mppath.path([ beginknot(1, 7), curve(), knot(3, 5), curve(), knot(0, 0), curve(), knot(6, 4), curve(), endknot(4, 9) ], epsilon), # include a line mppath.path([ knot(0, 0), curve(), knot(6, 4), curve(), roughknot(4, 9), line(), roughknot(1, 7), curve(), knot(3, 5), curve() ], epsilon), # XXX the endpoints have "open" at their other sides, not "curl" as in the open example above mppath.path([ knot(0, 0), curve(), knot(6, 4), curve(), knot(4, 9), line(), knot(1, 7), curve(), knot(3, 5), curve() ], epsilon), mppath.path( [knot(0, 0), curve(), knot(6, 4), line(), knot(3, 5), curve()], epsilon), mppath.path([ knot(0, 0), curve(), knot(6, 4), curve(), knot(3, 5), curve() ], epsilon), # TODO the internal mp_make_choices treats this as closed, but the last curve is not plotted: mppath.path([ knot(0, 0), curve(), knot(6, 4), curve(), knot(4, 9), line(), knot(1, 7), curve(), knot(3, 5) ], epsilon), # include a line with given angles mppath.path([ knot(0, 0), curve(), knot(6, 4), curve(), knot(4, 9), line(keepangles=True), knot(1, 7), curve(), knot(3, 5), curve() ], epsilon), # include rough knots mppath.path([ beginknot(0, 0), curve(), roughknot(6, 4, langle=90), curve(), roughknot(4, 9, langle=-90), line(keepangles=True), roughknot(1, 7, lcurl=3), curve(), endknot(3, 5, angle=0) ], epsilon), ]: cc = canvas.canvas() cc.stroke(p, [deco.shownormpath(), deco.earrow.normal]) if c is None: c = cc else: c.insert(cc, [ trafo.translate(c.bbox().right() - cc.bbox().left() + 0.5, 0) ]) c.writePDFfile() c.writeEPSfile() c.writeSVGfile()
path.closepath()) c.fill(p, [clientcolor, trafo.translate(0, -1.3*r)]) return c random.seed(812357) arrowcolor = color.grey(0.5) text.set(text.LatexRunner) text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}') unit.set(xscale=1.3) c = canvas.canvas() pos = [(0, 1), (sin(2*pi/3), cos(2*pi/3)), (-sin(2*pi/3), cos(2*pi/3))] for x, y in pos: c.insert(server(0.3), [trafo.translate(1.5*x, 1.5*y)]) c.insert(client(), [trafo.scale(0.5).translated(3*x, 3*y+0.15)]) c.stroke(path.line(2.7*x, 2.7*y, 1.9*x, 1.9*y), [arrowcolor, deco.earrow.large, deco.barrow.large, style.linewidth.THick]) pos.append(pos[0]) fak = 0.3 for (x1, y1), (x2,y2) in zip(pos[:-1], pos[1:]): c.stroke(path.line(1.5*x1+fak*(x2-x1), 1.5*y1+fak*(y2-y1), 1.5*x2-fak*(x2-x1), 1.5*y2-fak*(y2-y1)), [arrowcolor, deco.earrow.Large, deco.barrow.Large, style.linewidth.THIck]) dy = 0.8 dx = 1.5 versionoff = 1.5 cf = canvas.canvas() hueoff = 0.17
def update(self, *args): """update the population in self.world """ n = signal.convolve2d(self.world, self.v, mode='same', boundary='wrap') self.world = self.world & (n == 2) self.world = self.world | (n == 3) c = canvas.canvas() dx = 0.3 h = 4 w = 6.5 p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx) p = deformer.smoothed(0.5).deform(p) c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)]) c1 = canvas.canvas([canvas.clip(p)]) c1.fill(p, [color.grey(0.9)]) np.random.seed = 42 game = Conway(300) for _ in range(15): game.update() world = game.world xoff = -0.5 * w - dx yoff = -0.5 * h - dx delta = 0.1 for nx in range(game.size): for ny in range(game.size): if world[nx, ny]:
myblue = color.rgb(0, 0, 0.8) for c, start in ((frontplane, 0), (backplane, xcells * ycells)): c.stroke( path.rect(0, 0, 4, 3), [deco.filled([color.grey(1), color.transparency(0.2)])]) for x in range(1, xcells): c.stroke(path.line(x, 0, x, ycells)) for y in range(1, ycells): c.stroke(path.line(0, y, xcells, y)) for entry in range(xcells * ycells): x = entry % 4 y = ycells - entry // 4 c.text(x + 0.5, y - 0.5, str(start + entry), [text.halign.center, text.valign.middle]) c = canvas.canvas() c.insert(backplane, [trafo.translate(xshift, yshift)]) for x, y in product((0, xcells), (0, ycells)): c.stroke(path.line(x, y, x + xshift, y + yshift)) c.insert(frontplane) dx = -dist * yshift / sqrt(xshift**2 + yshift**2) dy = dist * xshift / sqrt(xshift**2 + yshift**2) c.stroke(path.line(dx, ycells + dy, dx + xshift, ycells + dy + yshift), [deco.earrow, myred]) c.text(0.5 * xshift + 2 * dx, ycells + 0.5 * yshift + 2 * dy, 'axis 0', [ text.halign.center, myred, trafo.rotate(180 / pi * atan2(yshift, xshift)) ]) c.stroke(path.line(-dist, ycells, -dist, 0), [deco.earrow, mygreen]) c.text(-2 * dist, 0.5 * ycells, 'axis 1', [text.halign.center, mygreen, trafo.rotate(90)])
from pyx import canvas, color, deco, deformer, graph, path, style, trafo def ellipse(r, scaley, fillcolor): ce = canvas.canvas() ce.fill(path.circle(0, 0, r), [trafo.scale(1, scaley), fillcolor]) return ce c = canvas.canvas() dx = 0.3 h = 4 w = 6.5 p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx) p = deformer.smoothed(0.5).deform(p) c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)]) c1 = canvas.canvas([canvas.clip(p)]) c1.fill(p, [color.grey(0.9)]) r = 1 brown1 = color.rgb(148 / 255, 77 / 255, 48 / 255) brown2 = color.rgb(193 / 255, 91 / 255, 49 / 255) red1 = color.rgb(200 / 255, 0, 0) red2 = color.rgb(220 / 255, 0.5, 0.5) flame = color.rgb(248 / 255, 212 / 255, 27 / 255) c2 = canvas.canvas() c2.insert(ellipse(r, 0.5, brown1)) c2.fill(path.rect(-r, 0, 2 * r, 0.5 * r), [brown1]) c2.insert(ellipse(r, 0.5, brown2), [trafo.translate(0, 0.5 * r)]) c2.insert(ellipse(0.2 * r, 0.5, red1), [trafo.translate(0, 0.5 * r)])
for nr, (label, boxcolor, symbolcolor, status) in enumerate( (('working directory', color.hsb(0.87, 1, 0.6), color.rgb(0.6, 0, 0), 'modified'), ('staging area', color.hsb(0.2, 1, 0.6), color.rgb(0, 0.5, 0), 'staged'), ('repository (.git)', color.hsb(0.53, 1, 0.6), color.grey(0.3), 'committed'))): xmid = nr * (wd + hdist) + 0.5 * wd c.stroke(path.rect(nr * (wd + hdist), 0, wd, ht), [deformer.smoothed(0.3), boxcolor, style.linewidth.Thick]) c.fill(path.rect(nr * (wd + hdist), ht + vdist, wd, htlabel), [deformer.smoothed(0.3), boxcolor]) c.text(xmid, ht + vdist + 0.5 * htlabel, label, [text.halign.center, text.valign.middle, color.grey(1)]) c.insert(filesymbol(size, symbolcolor), [trafo.translate(xmid, 0.5 * ht)]) c.text(xmid, 0.2 * ht, status, [text.halign.center, symbolcolor]) for nr, operation in enumerate(('git add', 'git commit')): xmid = nr * (wd + hdist) + 0.5 * wd c.stroke( path.line(xmid + 0.5 * size + 0.1, 0.5 * ht, xmid + wd + hdist - 0.5 * size - 0.1, 0.5 * ht), [deco.earrow.large, style.linewidth.Thick]) cop = canvas.canvas() optext = text.text(0, 0, operation, [text.halign.center, text.valign.middle]) tblarge = optext.bbox().enlarged(0.1) cop.fill(tblarge.path(), [deco.stroked([color.grey(0)]), color.grey(0.9)]) cop.insert(optext) c.insert( cop,
def rect(i0, j0, di=1, dj=1, txt=None): extra = [green, style.linewidth.Thick, style.linestyle.dashed, trafo.translate(x, y)] c.stroke(path.rect((i0-0.5)*dx, (j0-0.5)*dy, di*dx, dj*dy), extra) if txt: c.text((i0+di-0.5)*dx, (j0+dj-0.5)*dy-pip, txt, [trafo.translate(x, y), text.halign.boxright, text.valign.top])
c = canvas.canvas() r = 1 c.insert(server(r)) c.text(0, 0.5 * r + 0.3, 'central server', [text.halign.center]) h = 1.7 l = 2 for phi in (-30, 0, 30): c.stroke(path.line(0, -h, 0, -h - l), [ arrowcolor, style.linewidth.THICK, deco.barrow.LArge, deco.earrow.LArge, trafo.rotate(phi) ]) for dx, dy in ((-2, -3.7), (0, -4.2), (2, -3.7)): c.insert(client(), [trafo.translate(dx, dy)]) c.text(0, -5.5, 'clients', [text.halign.center]) dy = 0.8 dx = 1.5 versionoff = 1.5 cf = canvas.canvas() hueoff = 0.17 nr_revisions = 0 for nr, (name, versions) in enumerate( (('file 1', (0, 2, 4, 5)), ('file 2', (0, 1, 2, 3, 5)), ('file 3', (1, 4, 5)))): nr_revisions = max(nr_revisions, max(versions)) hue = hueoff + nr / 3 cf.text(0, -nr * dy, name, [color.hsb(hue, 1, 0.5), text.valign.middle]) for nver, (v1, v2) in enumerate(zip(versions[:-1], versions[1:])):