def plot_dataset_ranges(data, width, label): methods = data.keys() binsizes = numpy.unique(data[methods[0]]['binsize']) ho = 0.4 ho2 = 0.4 vo = 0.6 spacer = 0.25 plot_width = (width - ho * 2 - (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) 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(width, plot_height * 0.5 + vo, label, [ 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 draw(self): """draw the text!!""" for layer in self.sectors: radius = self.sectors[layer]['radius'] letter_radius = radius + 0.25 * self.sector_width prev_radian = 0 for radian in self.sectors[layer]['letters']: end = False letter = self.sectors[layer]['letters'][radian][0] if len(letter) > 1: end = True freq = self.sectors[layer]['letters'][radian][1] offset = False cur_radian = radian if (radian - prev_radian) * letter_radius < 0.22: cur_radian = prev_radian + 0.22 / letter_radius prev_radian = cur_radian offset = True centroid_x = radius * cos(radian) + self.xo centroid_y = radius * sin(radian) + self.yo if end: letter_x = radius * cos(cur_radian) + self.xo letter_y = radius * sin(cur_radian) + self.yo else: letter_x = letter_radius * cos(cur_radian) + self.xo letter_y = letter_radius * sin(cur_radian) + self.yo # rotate the text accordingly transform = trafo.rotate(radian * 180 / pi) if cur_radian > pi / 2 and cur_radian < (3 * pi / 2): transform = trafo.rotate(180 + radian * 180 / pi) # if this condition is true then the letter is actually the # whole word, it is an end sector, so display the frequency if len(letter) > 1: letter += ' ' letter += str(freq) # the random floats are me tuning the color just right lol text_color = color.rgb(0, 0.0784 * 1.4, 0.156 * 1.4) self.canvas.text( letter_x, letter_y, r"\texttt{" + letter + '}', [ text.halign.center, text.valign.middle, transform, text.size.scriptsize, text_color ]) if offset: self.canvas.stroke( path.line(centroid_x, centroid_y, letter_x, letter_y), [style.linewidth(0.0035), text_color]) self.canvas.fill(path.circle(centroid_x, centroid_y, 0.0065), [text_color]) prev_radian = cur_radian
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(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 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 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.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.stroke(breakline1, self.defaultbreaklinesattrs + self.breaklinesattrs) canvas.stroke(breakline2, self.defaultbreaklinesattrs + self.breaklinesattrs) _title.paint(self, canvas, data, axis, axispos)
def signature(self, deg_max=6, padded=False, has_border=False): """ For a visualization of glyphs, lay out in a 2D grid PNG file. """ self.scale() sig = canvas.canvas([trafo.rotate(90), trafo.mirror(0)]) scale = 1.5 if padded or has_border: sig_margin = 0.2 x = (deg_max + 1) * scale + (1.5 * sig_margin) border_path = path.path(path.moveto(0, 0), path.lineto(0, x), path.lineto(x, x), path.lineto(x, 0), path.closepath()) if padded: border_color = color.cmyk.White if has_border: border_color = color.cmyk.Gray sig.stroke(border_path, [ border_color, trafo.translate(-sig_margin * 2, -sig_margin * 2), style.linewidth(.025) ]) for index in self.glist: if len(index) > 2: c = degree_glyph(index[0], index[1], index[2], (self.mincount, self.maxcount)) else: c = degree_glyph(index[0], index[1], 1, (self.mincount, self.maxcount)) sig.insert(c, [trafo.translate(index[0] * scale, (index[1]) * scale) ]) # text writing requires full latex return sig
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 plate_circle_layer(plate, information, message, plate_radius=32.6): outerclip = 39.6 box_xoffset = 1. box_xsize = 4. box_ysize = 16. text_ybuffer = 0.5 text_xbuffer = 0.3 clippath = path.circle(0., 0., outerclip) plate_clipobject = canvas.clip(clippath) plate_circle = canvas.canvas([plate_clipobject]) plate_circle.stroke(path.circle(0., 0., plate_radius), [style.linewidth.THICk]) plate_circle.stroke( path.line(-plate_radius + box_xoffset, -box_ysize * 0.5, -plate_radius + box_xoffset - box_xsize, -box_ysize * 0.5), [style.linewidth.THICk]) plate_circle.stroke( path.line(-plate_radius + box_xoffset - box_xsize, -box_ysize * 0.5, -plate_radius + box_xoffset - box_xsize, box_ysize * 0.5), [style.linewidth.THICk]) plate_circle.stroke( path.line(-plate_radius + box_xoffset, box_ysize * 0.5, -plate_radius + box_xoffset - box_xsize, box_ysize * 0.5), [style.linewidth.THICk]) tab_path = path.line(-plate_radius - text_xbuffer, -box_ysize * 0.5 + text_ybuffer, -plate_radius - text_xbuffer, box_ysize * 0.5 - text_ybuffer) tab_text = r"\font\myfont=cmr10 at 100pt {\myfont " + str(plate) + "}" plate_circle.draw(tab_path, [deco.curvedtext(tab_text)]) information_path = (path.circle(0., 0., plate_radius).transformed( trafo.rotate(90.))) plate_circle.draw(information_path, [ deco.curvedtext(information, textattrs=[text.valign.top, text.vshift.topzero]) ]) message_path = (path.circle(0., 0., plate_radius).transformed(trafo.rotate(-90.))) plate_circle.draw(message_path, [ deco.curvedtext(message, textattrs=[text.valign.top, text.vshift.topzero]) ]) return plate_circle
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 trafo(self, dx, dy): direction = self.direction + math.atan2(dy, dx) * 180 / math.pi while (direction > 180 + self.epsilon): direction -= 360 while (direction < -180 - self.epsilon): direction += 360 while (direction > 90 + self.epsilon): direction -= 180 while (direction < -90 - self.epsilon): direction += 180 return trafomodule.rotate(direction)
def plot_dataset_ranges(data, width, label): methods = data.keys() binsizes = numpy.unique(data[methods[0]]['binsize']) ho = 0.4 ho2 = 0.4 vo = 0.6 spacer = 0.25 plot_width = (width - ho * 2 - (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) 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(width, plot_height * 0.5 + vo, label, [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 tetra(x, y, count=None, subcount=None, rev=1, back=True, front=True, reflect=False): if back: circle(x, y, r, shade) rr = 1.0*r if subcount is not None: ps = [] for i in range(3): theta1 = rev*2*(i+subcount)*pi/3 if i==0: # start of curve x1, y1 = x+rr*sin(theta1), y+rr*cos(theta1) ps.append((x1, y1)) if i==1: x1, y1 = x+0.7*r*sin(theta1), y+0.7*r*cos(theta1) ps.append((x1, y1)) else: x1, y1 = x+0.4*r*sin(theta1), y+0.4*r*cos(theta1) ps.append((x1, y1)) if i==2: # end of curve x1, y1 = x+1.0*rr*sin(theta1), y+1.0*rr*cos(theta1) ps.append((x1, y1)) c.stroke(path.path( path.moveto(*ps[0]), path.lineto(*ps[1]), path.lineto(*ps[2]), path.lineto(*ps[3]), path.lineto(*ps[4])), st_curve+[deformer.smoothed(0.6)]) if front: for theta1 in [0., 2*pi/3, 4*pi/3]: x1, y1 = x+0.5*r*sin(theta1), y+0.5*r*cos(theta1) circle(x1, y1, r0, white) if count is not None: assert 0<=count<=2 s = 0.86*r r1 = 2.4*r0 extra = [] #c.text(x, y, count) if reflect: #count = [0, 1, 2][count] extra.append(trafo.scale(x=x, y=y, sx=-1, sy=1)) extra += [trafo.rotate(-count*120, x=x, y=y)] t = Turtle(x1, y1-r1, -pi/2).right(pi, r1).fwd(s).right(pi, r1).fwd(s) t.stroke(extra) t.stroke(extra+[deco.earrow()])
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 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 RectMid(canv, pt, w, h, fi=0, linewidth=LINE_DEF_WIDTH, linecolor=LINE_DEF_COLOR, fillcolor=None, mstyle=[]): rect = path.rect(pt.x, pt.y - h / 2, w, h) rto = trafo.rotate(fi, pt.x, pt.y) if fillcolor is not None: canv.fill(rect, [fillcolor, rto]) canv.stroke(rect, [style.linewidth(linewidth), linecolor, rto] + mstyle)
def jog(cls, paths, length=0.5, deg=10): if not isinstance(paths, list): paths = [paths] x, y = [ coord / unit.length(1) for coord in paths[-1].tangent(paths[-1].end()).atend() ] d = degrees(atan2(y, x)) begin = P(*paths[-1].tangent(paths[-1].end()).atbegin()) end = P(*paths[-1].tangent(paths[-1].end()).atend()) tan = end - begin d = degrees(atan2(*[coord / unit.length(1) for coord in tan][::-1])) dp = trafo.rotate(d - deg if d <= -90 else d + deg).apply(-length, 0) paths[-1].append(path.rlineto(*dp)) return paths
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(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 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 winding(n, radius, angle=60, windingnumber=False, endpointcolor=color.rgb(0.6, 0.2, 0), pathcolor=color.rgb(0.4, 0.3, 0.8)): c = canvas.canvas() ticklen = 0.1 c.stroke(path.circle(0, 0, radius), [style.linewidth.Thin]) tick = path.line((1 - ticklen) * radius, 0, (1 + ticklen) * radius, 0) c.stroke(tick, [endpointcolor, style.linewidth.Thick]) c.stroke(tick, [trafo.rotate(angle), endpointcolor, style.linewidth.Thick]) tick_outer = (1 + ticklen) * radius for _angle, label in ((0, r'$\phi_\text{i}$'), (radians(angle), 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
c.stroke(path.line(x+1.4*r, y, x+2.6*r, y), [deco.earrow()]) c.text(x+2.0*r, y+0.4*r, "$f$", center) x += 4*r surface(x, y, r, shade, mark=True) t = Turtle(x, y-r, -0.45*pi) dr = 0.15 r0 = 0.90 dtheta = 0.53*pi dtheta = 0.45*pi st_cw = [trafo.rotate(-90, x=x, y=y)] t.right(0.45*pi, 0.90) #c.stroke(path.circle(t.x, t.y, 0.1), st_cw) t.right(0.45*pi, 0.75) #c.stroke(path.circle(t.x, t.y, 0.1), st_cw) t.right(0.70*pi, 0.55) #c.stroke(path.circle(t.x, t.y, 0.1), st_cw) t.right(0.45*pi, 0.44) t.stroke(st_curve + st_cw) t.stroke(st_curve + [trafo.rotate(90, x=x, y=y), deco.earrow()], reverse=True) surface(x, y, r1, white, mark=True) c.text(x-r, y+r, "$\widehat{a}$", northwest)
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)]) c.stroke(path.line(0, -dist, xcells, -dist), [deco.earrow, myblue]) c.text(0.5 * xcells, -2 * dist, 'axis 2', [text.halign.center, text.valign.top, myblue]) c.writePDFfile()
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)) c.text(0.8, 0.2, 'Gitlab / Github server', [color.hsb(0.5, 0.8, 0.5), text.size.small]) c.writePDFfile()
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([canvas.clip(p)]) c2 = canvas.canvas() textcolor = color.hsb(0.6, 0.3, 1) t = """\Huge $2x^4+10x^3$ p1 = \{4: 2, 3: 10\} $5x^2-x+32$ p2 = \{2: 5, 1: -1, 0: 32\} multiply(p1, p2) """ c2.text(0, 0, t, [text.parbox(2*w), textcolor]) c1.insert(c2, [trafo.rotate(20).translated(-0.2*w, 0.9*h)]) c.insert(c1) t = r'\Large $(2x^4+10x^3)(5x^2-x+32)$' c.text(w/2, h/2, t, [text.halign.center, text.valign.middle, color.hsb(0.05, 0.9, 0.6)]) c.writeGSfile(device="png16m", resolution=300)
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
anyon(0., r) anyon(0., 0.) anyon(0., -r) anyon(w, r) anyon(w, 0.) anyon(w, -r) if count==0: pop() else: pop([trafo.translate(0., 8*r)]) pop([trafo.rotate(-90)]) x = -3.0*r y = 0.0*r c.text(x, y, r"$\sigma_1^{2}\ket{\psi}$", center) y -= 4.0*r c.text(x, y, r"$\ket{\psi}$", center) c.stroke(path.line(x, y+r, x, -r), [deco.earrow(size=0.2)]) c.stroke(path.line(x-0.1, y+r, x+0.1, y+r)) x = +5.0*r y = 0.0*r
def text_pyx(g, x_coord, y_coord, text_input, text_size = -2, color = None, rotation = 0.): """ Function that draws text in a given plot INPUTS: g (Object) A graph-type object to which you want to add the text x_coord (Double) x-coordinate (in plot units) at which you want to place the text y_coord (Double) y-coordinate (in plot units) at which you want to place the text text_input (String) Text that you want to add. text_size (int, optional) Text size of the text added to the plot. Default is -2. color (instance) Color instance that defines the color that you want the text to have. Default is black. """ # First define the text attributes: textattrs = [pyx_text.size(text_size),pyx_text.halign.center, pyx_text.vshift.middlezero, trafo.rotate(rotation)] # Now convert plot positions to pyx's: x0,y0 = g.pos(x_coord, y_coord) # If no color is given, draw black text. If color is given, draw text with the input color: if color is None: g.text(x0,y0,text_input,textattrs) else: # First, check which was the input color palette: color_dict = color.color if len(color_dict.keys()) == 4: color_string = str(color_dict['c'])+','+str(color_dict['m'])+','+str(color_dict['y'])+','+str(color_dict['k']) color_palette = 'cmyk' else: color_string = str(color_dict['r'])+','+str(color_dict['g'])+','+str(color_dict['b']) color_palette = 'rgb' # Now draw the text: g.text(x0, y0, r"\textcolor["+color_palette+"]{"+color_string+"}{"+text_input+"}",textattrs)
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
def apogee_layer(holes, numbers=False, renumber=False): offset_amount = -0.03 hole_radius = 0.4 # Read in APOGEE blocks information blocks = apogee_south_blocks() # Set up colors pyxcolor = dict() pyxcolor['red'] = color.cmyk.Red pyxcolor['black'] = color.cmyk.Black pyxcolor['blue'] = color.cmyk.CornflowerBlue # Get science fiber information isci = np.nonzero(np.array(holes['holetype']) == b'APOGEE_SOUTH')[0] xfocal = np.array(holes['xfocal'])[isci] yfocal = np.array(holes['yfocal'])[isci] fiberid = np.array(holes['fiberid'])[isci] block = np.array(holes['block'])[isci] if (renumber): fiberid = np.array(blocks.fibers['fiberid'])[fiberid - 1] block = np.array(blocks.fibers['blockid'])[fiberid - 1] # Create Voronoi tessellation xy = np.array([xfocal, yfocal]).transpose() vor = Voronoi(xy) nridges = vor.ridge_points.shape[0] # Set up object to print clippath = path.circle(0., 0., interior_radius) clipobject = canvas.clip(clippath) interior = canvas.canvas([clipobject]) # Print lines separating blocks for indx in range(nridges): iv0 = vor.ridge_vertices[indx][0] iv1 = vor.ridge_vertices[indx][1] ip0 = vor.ridge_points[indx][0] ip1 = vor.ridge_points[indx][1] point0 = vor.points[ip0, :] / 10. point1 = vor.points[ip1, :] / 10. ib0 = block[ip0] ib1 = block[ip1] if (iv0 > 0 and iv1 > 0 and ib0 != ib1): if (ib0 <= 25): side0 = 'Red' else: side0 = 'Blue' if (ib1 <= 25): side1 = 'Red' else: side1 = 'Blue' if (side0 == side1): if (side0 == 'Red'): color0 = color.cmyk.Red color1 = color.cmyk.Red else: color0 = color.cmyk.Blue color1 = color.cmyk.Blue else: color0 = color.cmyk.Black color1 = color.cmyk.Black vertex_start = vor.vertices[iv0, :] / 10. vertex_end = vor.vertices[iv1, :] / 10. (start0, end0) = offset_line(offset_amount, vertex_start, vertex_end, point0) interior.stroke(path.line(start0[1], start0[0], end0[1], end0[0]), [style.linewidth.THick, color0]) (start1, end1) = offset_line(offset_amount, vertex_start, vertex_end, point1) interior.stroke(path.line(start1[1], start1[0], end1[1], end1[0]), [style.linewidth.THick, color1]) # Print circles around holes for indx in range(len(xfocal)): hole_color = pyxcolor[blocks.fcolor(fiberid[indx])] interior.stroke( path.circle(yfocal[indx] / 10., xfocal[indx] / 10., hole_radius), [style.linewidth.THick, hole_color]) if (numbers is True): # Print numbers near holes for indx in range(len(xfocal)): if (indx <= 150): props = [text.halign.boxleft, text.valign.middle] else: props = [ text.halign.boxright, text.valign.middle, trafo.rotate(180.) ] interior.text( (yfocal[indx] / 10.) + hole_radius * 1.2, (xfocal[indx] / 10.), r"\font\myfont=cmr10 at 20pt {\myfont " + str(fiberid[indx]) + "}", props) return interior
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 draw_continent_circle(con, name="", draw_upper_landscape=True, draw_lower_landscape=False, draw_upper_green=True, draw_lower_purple=False, draw_train_tracks=False, draw_foliation=True, foliation_style_old=False, foliation_style_split=False, foliation_style_cusp_leaves=True, foliation_style_boundary_leaves=True, shade_triangles=False, draw_fund_domain=False, fund_dom_tets=None, draw_fund_domain_edges=False, draw_tetrahedron_rectangles=[]): global_scale_up = 10.0 edge_thickness = 0.02 track_thickness = 0.02 leaf_thickness = 0.03 edge_colours = { True: color.rgb(0.9, 0.3, 0), False: color.rgb(0, 0.3, 0.9) } green = color.rgb(0.0, 0.5, 0.0) purple = color.rgb(0.5, 0.0, 0.5) scl = trafo.trafo(matrix=((global_scale_up, 0), (0, global_scale_up)), vector=(0, 0)) canv = canvas.canvas() canv.stroke(path.circle(0, 0, global_scale_up), [style.linewidth(0.02)]) n = len(con.coast) for v in con.coast: i = v.coastal_index t = 2 * pi * float(i) / float(n) v.circle_pos = complex(cos(t), sin(t)) vert_pos = v.circle_pos * 1.01 * global_scale_up canv.text(vert_pos.real, vert_pos.imag, "$" + str(con.vertices.index(v)) + "$", textattrs=[ text.size(-4), text.halign.left, text.valign.middle, trafo.rotate( (180 / pi) * atan2(vert_pos.imag, vert_pos.real)) ]) # vert_pos2 = v.circle_pos * 1.2 * global_scale_up # p = path.path(path.moveto(vert_pos.real, vert_pos.imag), path.lineto(vert_pos2.real, vert_pos2.imag)) # canv.stroke(p, [deco.curvedtext("$"+str(con.vertices.index(v))+"$")]) ### highlight vertices of tetrahedra in a fundamental domain if draw_fund_domain: if fund_dom_tets == None: fund_dom_tets = get_fund_domain_tetrahedra(con) for con_tet in fund_dom_tets: if type( con_tet ) == continent_tetrahedron: ### could be an integer if we didnt find this tet if draw_fund_domain_edges: for e in con_tet.edges(): col = edge_colours[e.is_red] u, v = e.vertices p = make_arc(u.circle_pos, v.circle_pos) p = p.transformed(scl) canv.stroke(p, [ style.linewidth(edge_thickness), style.linecap.round, col ]) update_fund_dom_tet_nums(con, fund_dom_tets) for v in [v for v in con.coast if v.fund_dom_tet_nums != []]: vert_pos = v.circle_pos * 1.03 * global_scale_up canv.text(vert_pos.real, vert_pos.imag, "$" + str(v.fund_dom_tet_nums) + "$", textattrs=[ text.size(-4), text.halign.left, text.valign.middle, trafo.rotate( (180 / pi) * atan2(vert_pos.imag, vert_pos.real)) ]) # lower_colours = {True: color.rgb(0.5,0.3,0), False: color.rgb(0,0.3,0.5)} # upper_colours = {True: color.rgb(0.9,0.3,0), False: color.rgb(0,0.3,0.9)} landscape_edges = [con.lower_landscape_edges, con.upper_landscape_edges] # colours = [lower_colours, upper_colours] upper_tris = con.upper_landscape_triangles lower_tris = con.lower_landscape_triangles boundary_tris = [lower_tris, upper_tris] if shade_triangles: u, v, w = con.triangle_path[0].vertices p = make_arc(u.circle_pos, v.circle_pos) q = make_arc(v.circle_pos, w.circle_pos) r = make_arc(w.circle_pos, u.circle_pos) p.append(q[1]) p.append(r[1]) ### remove extraneous moveto commands p = p.transformed(scl) canv.stroke( p, [deco.filled([color.transparency(0.8)]), style.linewidth(0)]) u, v, w = con.triangle_path[-1].vertices p = make_arc(u.circle_pos, v.circle_pos) q = make_arc(v.circle_pos, w.circle_pos) r = make_arc(w.circle_pos, u.circle_pos) p.append(q[1]) p.append(r[1]) ### remove extraneous moveto commands p = p.transformed(scl) canv.stroke( p, [deco.filled([color.transparency(0.8)]), style.linewidth(0)]) # for triangle in con.triangle_path: # u,v,w = triangle.vertices # p = make_arc(u.circle_pos, v.circle_pos) # q = make_arc(v.circle_pos, w.circle_pos) # r = make_arc(w.circle_pos, u.circle_pos) # p.append(q[1]) # p.append(r[1]) ### remove extraneous moveto commands # p = p.transformed(scl) # canv.stroke(p, [deco.filled([color.transparency(0.8)]), style.linewidth(0)]) to_do = [] if draw_lower_landscape: to_do.append(0) if draw_upper_landscape: to_do.append(1) for i in to_do: for e in landscape_edges[i]: col = edge_colours[e.is_red] transp = [] if i == 0: transp = [color.transparency(0.75)] u, v = e.vertices p = make_arc(u.circle_pos, v.circle_pos) p = p.transformed(scl) canv.stroke( p, [style.linewidth(edge_thickness), style.linecap.round, col] + transp) for tri in boundary_tris[i]: center = incenter(tri.vertices[0].circle_pos, tri.vertices[1].circle_pos, tri.vertices[2].circle_pos) # canv.fill(path.circle(global_scale_up*center[0], global_scale_up*center[1], 0.1)) canv.text(global_scale_up * center[0], global_scale_up * center[1], "$" + str(tri.index) + "$", textattrs=[ text.size(-2), text.halign.center, text.valign.middle ] + transp) ### train tracks... purple_train_routes = [ ] ### pairs of coastal edges corresponding to a train route green_train_routes = [] if draw_lower_purple: if draw_train_tracks: for tri in lower_tris: midpts = [] is_reds = [] for e in tri.edges: is_reds.append(e.is_red) u, v = e.vertices p, midpt = make_arc(u.circle_pos, v.circle_pos, return_midpt=True) midpts.append(midpt) for i in range(3): if (is_reds[i] == is_reds[(i + 1) % 3]) or ( not is_reds[i] and is_reds[(i + 1) % 3]): p = make_arc(midpts[i], midpts[(i + 1) % 3]) p = p.transformed(scl) canv.stroke(p, [ style.linewidth(track_thickness), style.linecap.round, purple ]) if draw_foliation: for edge in con.lower_landscape_edges: leaf_end_edges = [] if edge.is_coastal(): if not edge.is_coastal_sink(upper=False): leaf_end_edges.append(edge) for tri in edge.boundary_triangles: if not tri.is_upper: last_tri = con.flow(tri)[0] last_edge = last_tri.edges[ last_tri.downriver_index()] leaf_end_edges.append(last_edge) else: if edge.is_watershed(): for tri in edge.boundary_triangles: last_tri = con.flow(tri)[0] last_edge = last_tri.edges[ last_tri.downriver_index()] leaf_end_edges.append(last_edge) if len(leaf_end_edges) == 2: purple_train_routes.append(leaf_end_edges) if foliation_style_old: leaf_ends = [] for e in leaf_end_edges: endpts = e.vertices _, midpt = make_arc(endpts[0].circle_pos, endpts[1].circle_pos, return_midpt=True) leaf_ends.append(midpt) p = make_arc(leaf_ends[0], leaf_ends[1]) p = p.transformed(scl) canv.stroke(p, [ style.linewidth(leaf_thickness), style.linecap.round, purple ]) if draw_upper_green: if draw_train_tracks: for tri in upper_tris: midpts = [] is_reds = [] for e in tri.edges: is_reds.append(e.is_red) u, v = e.vertices p, midpt = make_arc(u.circle_pos, v.circle_pos, return_midpt=True) midpts.append(midpt) for i in range(3): if (is_reds[i] == is_reds[(i + 1) % 3]) or ( is_reds[i] and not is_reds[(i + 1) % 3]): p = make_arc(midpts[i], midpts[(i + 1) % 3]) p = p.transformed(scl) canv.stroke(p, [ style.linewidth(track_thickness), style.linecap.round, green ]) if draw_foliation: for edge in con.upper_landscape_edges: leaf_end_edges = [] if edge.is_coastal(): if not edge.is_coastal_sink(upper=True): leaf_end_edges.append(edge) for tri in edge.boundary_triangles: if tri.is_upper: last_tri = con.flow(tri)[0] last_edge = last_tri.edges[ last_tri.downriver_index()] leaf_end_edges.append(last_edge) else: if edge.is_watershed(): for tri in edge.boundary_triangles: last_tri = con.flow(tri)[0] last_edge = last_tri.edges[ last_tri.downriver_index()] leaf_end_edges.append(last_edge) if len(leaf_end_edges) == 2: green_train_routes.append(leaf_end_edges) if foliation_style_old: leaf_ends = [] for e in leaf_end_edges: endpts = e.vertices _, midpt = make_arc(endpts[0].circle_pos, endpts[1].circle_pos, return_midpt=True) leaf_ends.append(midpt) p = make_arc(leaf_ends[0], leaf_ends[1]) p = p.transformed(scl) canv.stroke(p, [ style.linewidth(leaf_thickness), style.linecap.round, green ]) if draw_foliation and (foliation_style_split or foliation_style_cusp_leaves or foliation_style_boundary_leaves): for e in con.coastal_edges: e.purple_ends = [] e.green_ends = [] for e1, e2 in purple_train_routes: e1.purple_ends.append(e2) e2.purple_ends.append(e1) for e1, e2 in green_train_routes: e1.green_ends.append(e2) e2.green_ends.append(e1) for i, e in enumerate(con.coastal_edges): rotated_coastal_edges = con.coastal_edges[ i:] + con.coastal_edges[:i] e.purple_ends.sort( key=lambda e_other: rotated_coastal_edges.index(e_other), reverse=True) e.green_ends.sort( key=lambda e_other: rotated_coastal_edges.index(e_other), reverse=True) if e.is_red: e.ends = e.green_ends + e.purple_ends else: e.ends = e.purple_ends + e.green_ends if foliation_style_split: for e1, e2 in purple_train_routes: p1 = end_pos(e2, e1) p2 = end_pos(e1, e2) p = make_arc(p1, p2) p = p.transformed(scl) canv.stroke(p, [ style.linewidth(leaf_thickness), style.linecap.round, purple ]) for e1, e2 in green_train_routes: p1 = end_pos(e2, e1) p2 = end_pos(e1, e2) p = make_arc(p1, p2) p = p.transformed(scl) canv.stroke(p, [ style.linewidth(leaf_thickness), style.linecap.round, green ]) if foliation_style_cusp_leaves or foliation_style_boundary_leaves: for i, c in enumerate(con.coast): c.purple_thorn_end_positions = [] ### complex numbers c.purple_thorn_ends = [ ] ### [coastal arc, position along that arc] e = con.coastal_edges[i] e1 = e.purple_ends[0] while True: index = e1.purple_ends.index(e) if index == len(e1.purple_ends) - 1: break else: c.purple_thorn_end_positions.append( end_pos(e, e1, offset=0.5)) c.purple_thorn_ends.append((e1, e1.ends.index(e))) e, e1 = e1, e1.purple_ends[index + 1] if foliation_style_boundary_leaves: e_before = con.coastal_edges[(i - 1) % len(con.coast)] e_after = con.coastal_edges[i] first_pos = end_pos(e_after.purple_ends[0], e_after, offset=-0.25) last_pos = end_pos(e_before.purple_ends[-1], e_before, offset=0.25) c.purple_thorn_end_positions = [ first_pos ] + c.purple_thorn_end_positions + [last_pos] arcs = [] for i in range(len(c.purple_thorn_end_positions) - 1): arcs.append( make_arc(c.purple_thorn_end_positions[i], c.purple_thorn_end_positions[i + 1])) for p in arcs: p = p.transformed(scl) canv.stroke(p, [ style.linewidth(leaf_thickness), style.linecap.round, purple ]) if foliation_style_cusp_leaves: for thorn_end in c.purple_thorn_ends: thorn_end_pos = end_pos2(thorn_end) p = make_arc(c.circle_pos, thorn_end_pos) p = p.transformed(scl) canv.stroke(p, [ style.linewidth(leaf_thickness), style.linecap.round, purple ]) for i, c in enumerate(con.coast): c.green_thorn_end_positions = [] ### complex numbers c.green_thorn_ends = [ ] ### [coastal arc, position along that arc] e = con.coastal_edges[i] e1 = e.green_ends[0] while True: index = e1.green_ends.index(e) if index == len(e1.green_ends) - 1: break else: c.green_thorn_end_positions.append( end_pos(e, e1, offset=0.5)) c.green_thorn_ends.append((e1, e1.ends.index(e))) e, e1 = e1, e1.green_ends[index + 1] if foliation_style_boundary_leaves: e_before = con.coastal_edges[(i - 1) % len(con.coast)] e_after = con.coastal_edges[i] first_pos = end_pos(e_after.green_ends[0], e_after, offset=-0.25) last_pos = end_pos(e_before.green_ends[-1], e_before, offset=0.25) c.green_thorn_end_positions = [ first_pos ] + green_thorn_end_positions + [last_pos] arcs = [] for i in range(len(c.green_thorn_end_positions) - 1): arcs.append( make_arc(c.green_thorn_end_positions[i], c.green_thorn_end_positions[i + 1])) for p in arcs: p = p.transformed(scl) canv.stroke(p, [ style.linewidth(leaf_thickness), style.linecap.round, green ]) if foliation_style_cusp_leaves: for thorn_end in c.green_thorn_ends: thorn_end_pos = end_pos2(thorn_end) p = make_arc(c.circle_pos, thorn_end_pos) p = p.transformed(scl) canv.stroke(p, [ style.linewidth(leaf_thickness), style.linecap.round, green ]) for tet in draw_tetrahedron_rectangles: purple_sides = tet_purple_rectangle_sides( tet, actually_do_green=False) green_sides = tet_purple_rectangle_sides( tet, actually_do_green=True) for side in purple_sides: for cusp_leaf in side: if cusp_leaf != None: v, thorn_end = cusp_leaf thorn_end_pos = end_pos2(thorn_end) p = make_arc(v.circle_pos, thorn_end_pos) p = p.transformed(scl) canv.stroke(p, [ style.linewidth(2 * leaf_thickness), style.linecap.round, purple ]) for side in green_sides: for cusp_leaf in side: if cusp_leaf != None: v, thorn_end = cusp_leaf thorn_end_pos = end_pos2(thorn_end) p = make_arc(v.circle_pos, thorn_end_pos) p = p.transformed(scl) canv.stroke(p, [ style.linewidth(2 * leaf_thickness), style.linecap.round, green ]) output_filename = 'Images/CircleContinent/' + name + '.pdf' canv.writePDFfile(output_filename)
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
c.stroke(path.rect(x0, y0, w, h), dashed) c.stroke(path.rect(x0+w+m, y0, w, h), dotted) grarrow = [green, style.linewidth.THick, deco.earrow(size=0.2)] y = y0+0.3*h c.stroke(path.line(x0+0.5*w, y, x0+1.5*w+m, y), grarrow) anyon(x0+0.8*w, y) anyon(x0+m+1.2*w, y) y = y0+0.7*h c.stroke(path.line(x0+1.5*w+m, y, x0+0.5*w, y), grarrow) anyon(x0+0.8*w, y) anyon(x0+m+1.2*w, y) pop([trafo.rotate(-90), trafo.translate(0.7, 2.5*h)]) c.text(0., 0.5*h, "(a)") # -------------------------------------------------------------------- #x0, y0 = 0.6, 0. #c.text(x0-0.8, y0, "(b)") push() c.stroke(path.rect(x0, y0, w, h), dashed) c.stroke(path.rect(x0+w+m, y0, w, h), dotted) p = path.path( path.moveto(x0+0.5*w, y0-0.3*h),
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
g = pyx.graph.graphxy(width=figwidth, height=figheight, x=pyx.graph.axis.linear(min=nmin, max=nmax, title=r'$\log n_\mathrm{gas}$'), y=pyx.graph.axis.linear(min=tmin, max=tmax, title=r'$\log T$'), ) from pyx.style import linestyle, linewidth from pyx.color import transparency from pyx.graph.style import line from pyx.graph import data from pyx.trafo import rotate, scale line.defaultlineattrs += [linewidth.thick, transparency(0.2)] # Free-fall time < 1.e5 years g.plot(data.function("x(y) = 5.31"), [line([linestyle.dashed])]) xx, yy = g.pos(5.6, 3.8) g.text(xx, yy, r"\(t_\mathrm{ff} = 10^5\,\mathrm{yr}\)", [scale(0.7), rotate(90)]) # Plot contours of Jeans instability for MJeans in (0.0, 1.0): g.plot(data.function("y(x) = 0.491 + 0.6667*MJeans + 0.333*(x-3.0)", context=locals()), [line([linestyle.solid, linewidth.Thick])]) ang = N.arctan2(0.3333*(nmax-nmin), (tmax-tmin))*180.0/N.pi x, y = g.pos(1.6, 0.8) g.text(x, y, r"\(M_J = 10~M_\odot\)", [scale(0.7), rotate(ang)]) x, y = g.pos(3.6, 0.8) g.text(x, y, r"\(M_J = 1~M_\odot\)", [scale(0.7), rotate(ang)]) # Plot contours of equilibrium T execdir = os.path.dirname(sys.argv[0]) for Av, D in [ [0.0, 0.3],
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)]) c.stroke(path.line(0, -dist, xcells, -dist), [deco.earrow, myblue]) c.text(0.5*xcells, -2*dist, 'axis 2', [text.halign.center, text.valign.top, myblue]) c.writePDFfile()
box = c.bbox() pd = 0.1 xoff = box.left() - pd pdx = 0.2 pdy = 0.5 c.stroke( path.curve(xoff, box.top() + pd, xoff - pdx, box.top() - pdy, xoff - pdx, box.bottom() + pdy, xoff, box.bottom() - pd)) xoff = box.right() + pd c.stroke( path.curve(xoff, box.top() + pd, xoff + pdx, box.top() - pdy, xoff + pdx, box.bottom() + pdy, xoff, box.bottom() - pd)) x = box.left() - pdx - 0.4 c.stroke(path.line(x, box.top(), x, box.bottom()), [deco.earrow, color0]) c.text( x - 0.1, 0.5 * (box.top() + box.bottom()), 'axis 0', [text.halign.center, color0, trafo.rotate(90)]) y = box.top() + 0.4 c.stroke(path.line(box.left(), y, box.right(), y), [deco.earrow, color1]) c.text(0.5 * (box.left() + box.right()), y + 0.1, 'axis 1', [text.halign.center, color1]) c.writePDFfile() c.writeGSfile(device="png16m", resolution=600)
dx = 2 dy = 0.8 c = canvas.canvas() for nx in range(3): for ny in range(3): c.text(nx*dx, -ny*dy, r'a[\textcolor{axis0}{%s}, \textcolor{axis1}{%s}]' % (ny, nx), [text.halign.center]) box = c.bbox() pd = 0.1 xoff = box.left()-pd pdx = 0.2 pdy = 0.5 c.stroke(path.curve(xoff, box.top()+pd, xoff-pdx, box.top()-pdy, xoff-pdx, box.bottom()+pdy, xoff, box.bottom()-pd)) xoff = box.right()+pd c.stroke(path.curve(xoff, box.top()+pd, xoff+pdx, box.top()-pdy, xoff+pdx, box.bottom()+pdy, xoff, box.bottom()-pd)) x = box.left()-pdx-0.4 c.stroke(path.line(x, box.top(), x, box.bottom()), [deco.earrow, color0]) c.text(x-0.1, 0.5*(box.top()+box.bottom()), 'axis 0', [text.halign.center, color0, trafo.rotate(90)]) y = box.top()+0.4 c.stroke(path.line(box.left(), y, box.right(), y), [deco.earrow, color1]) c.text(0.5*(box.left()+box.right()), y+0.1, 'axis 1', [text.halign.center, color1]) c.writePDFfile()
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)
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