Exemplo n.º 1
0
def framebox(nx,
             ny,
             framecolor,
             nw=1,
             nh=1,
             boxsize=1,
             framefactor=0.1,
             reducedsize=False):
    '''draw color frame in one or across several boxes

       The drawing is done on the global canvas called c.

       nx, ny:      coordinates of lower left corner in number of boxes
       framecolor:  color
       nw, nh:      width and height of frame in boxes
       framefactor: framewidth as fraction of boxsize
       boxsize:     side length of fox
       reducedsize: if True, the size of the frame is reduced by the framewidth

    '''
    x = nx * boxsize
    y = ny * boxsize
    w = nw * boxsize
    h = nh * boxsize
    if reducedsize:
        outer_offset = framefactor * boxsize
        inner_offset = 2 * outer_offset
    else:
        outer_offset = 0
        inner_offset = framefactor * boxsize
    p = (path.rect(x + outer_offset, y + outer_offset, w - 2 * outer_offset,
                   h - 2 * outer_offset) +
         path.rect(x + inner_offset, y + inner_offset, w - 2 * inner_offset,
                   h - 2 * inner_offset).reversed())
    c.fill(p, [framecolor])
def framebox(nx, ny, framecolor, nw=1, nh=1, boxsize=1, framefactor=0.1,
             reducedsize=False):
    '''draw color frame in one or across several boxes

       The drawing is done on the global canvas called c.

       nx, ny:      coordinates of lower left corner in number of boxes
       framecolor:  color
       nw, nh:      width and height of frame in boxes
       framefactor: framewidth as fraction of boxsize
       boxsize:     side length of fox
       reducedsize: if True, the size of the frame is reduced by the framewidth

    '''
    x = nx*boxsize
    y = ny*boxsize
    w = nw*boxsize
    h = nh*boxsize
    if reducedsize:
        outer_offset = framefactor*boxsize
        inner_offset = 2*outer_offset
    else:
        outer_offset = 0
        inner_offset = framefactor*boxsize
    p = (path.rect(x+outer_offset, y+outer_offset,
                   w-2*outer_offset, h-2*outer_offset)
         + path.rect(x+inner_offset, y+inner_offset,
                     w-2*inner_offset, h-2*inner_offset).reversed()
         )
    c.fill(p, [framecolor])
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def make_picture_for_two_vertices():
    c = canvas.canvas()
    c.stroke(path.rect(0, 0, 12, 1))
    c.stroke(path.rect(1, 0, 1, 1), [style.linewidth.THICK])
    c.stroke(path.rect(5, 0, 1, 1), [style.linewidth.THICK])
    c.stroke(path.rect(7, 0, 1, 1), [style.linewidth.THICK])
    c.stroke(path.rect(10, 0, 1, 1), [style.linewidth.THICK])
    c.stroke(path.line(-0.5, 0.5, -0.5, 6), [deco.earrow(size=0.2)])
    c.stroke(path.line(1.5, 0.5, 1.5, 5), [deco.earrow(size=0.2)])
    c.stroke(path.line(5.5, 0.5, 5.5, 4), [deco.earrow(size=0.2)])
    c.stroke(path.line(7.5, 0.5, 7.5, 3), [deco.earrow(size=0.2)])
    c.stroke(path.line(10.5, 0.5, 10.5, 2), [deco.earrow(size=0.2)])
    c.stroke(path.line(12.5, 0.5, 12.5, 1), [deco.earrow(size=0.2)])
    c.stroke(path.line(5.5, 4, 8, 4), [style.linewidth.THIN])
    c.stroke(path.line(7, 3, 8, 3), [style.linewidth.THIN])
    c.text(7.5, 3.5, r"$\delta_i = l_i - l_{i + 1}$", [text.halign.boxcenter, text.valign.middle])
    c.stroke(path.line(6, 0, 6, -1), [style.linewidth.THIN])
    c.stroke(path.line(7, 0, 7, -1), [style.linewidth.THIN])
    c.text(6.5, -0.4, r"$d_i$", [text.halign.boxcenter, text.valign.middle])
    c.text(-0.5, 3, r"$l_0 = 1.0$", [text.halign.boxleft])
    c.text(5.5, 2.5, r"$l_i$", [text.halign.boxright])
    c.text(7.5, 2, r"$l_{i+1}$", [text.halign.boxleft])
    c.text(12.5, 1.1, r"$l_{E+1} = 0.0$", [text.halign.boxcenter])

    c.writePDFfile("test_picture.pdf")
def markbox(x, y, boxcolor, linewidthfactor=0.1, boxsize=1):
    '''mark box by a colored line

       the drawing is done on the global canvas called c
    '''
    linewidth = linewidthfactor*boxsize
    p = (path.rect(x, y, boxsize, boxsize)
         + path.rect(x+linewidth, y+linewidth,
                     boxsize-2*linewidth, boxsize-2*linewidth).reversed()
         )
    c.fill(p, [boxcolor])
Exemplo n.º 6
0
def draw(dx=0., dy=0., use_arrows=True):

    r = 4.*m
    syndrome1 = syndrome.copy()
    lines = []
    for tree in trees:
      for p0 in tree.sites:
        x0, y0 = coord(*p0)
        c.fill(path.circle(x0+dx, y0+dy, r), [grey])
        p1 = tree.parent[p0]
        #print p0, p1
        if p1 is None:
            continue # root
        lines.append((p0, p1))

        x1, y1 = coord(*p1)
        #syndrome1[p0] = 0
        #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
        #    [style.linewidth.Thick, deco.earrow(size=0.3)])

        if x0==x1:
            c.fill(path.rect(x0-r+dx, y0+dy, 2*r, y1-y0), [grey])
        else:
            c.fill(path.rect(x0+dx, y0-r+dy, x1-x0, 2*r), [grey])
        c.fill(path.circle(x0+dx, y0+dy, r), [grey])
        c.fill(path.circle(x1+dx, y1+dy, r), [grey])
        #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
        #    [style.linewidth.THICK, style.linecap.round, grey])

    if use_arrows:
      t = 0.1
      s = 1.-t
      for (p0, p1) in lines:
        x0, y0 = coord(*p0)
        x1, y1 = coord(*p1)
        #x0, x1 = s*x0+t*x1, s*x1+t*x0
        #y0, y1 = s*y0+t*y1, s*y1+t*y0
        if syndrome[p1]:
            x1 = s*x1+t*x0
            y1 = s*y1+t*y0
        syndrome1[p0] = 0
        c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
            [style.linewidth.Thick, style.linecap.round, deco.earrow(size=0.2)])

    for i, j in sites:
        c.stroke(path.rect(j*w+dx, i*h+dy, w-2*m, h-2*m))
        if syndrome[i,j]:
            x, y = coord(i, j)
            anyon(x+dx, y+dy, 0.1*w)

    syndrome[:] = syndrome1
Exemplo n.º 7
0
def array(shape):
    baseshape = (3, 4)
    bgcolor = color.grey(0.5)
    c = canvas.canvas()
    c.text(baseshape[1] / 2, baseshape[0] + 0.3, 'shape=%s' % repr(shape),
           [text.halign.center])
    if len(shape) == 1:
        shape = (1, shape[0])
    assert len(shape) == 2
    c.stroke(path.rect(0, 0, baseshape[1], baseshape[0]), [bgcolor])
    for nx in range(1, baseshape[1]):
        c.stroke(path.line(nx, 0, nx, baseshape[0]), [bgcolor])
    for ny in range(1, baseshape[0]):
        c.stroke(path.line(0, ny, baseshape[1], ny), [bgcolor])
    if not (shape == baseshape):
        c.fill(path.rect(0, baseshape[0], shape[1], -shape[0]),
               [color.rgb(1, 0.8, 0.4)])
        if shape[0] in (1, baseshape[0]) and shape[1] in (1, baseshape[1]):
            for nx in range(baseshape[1]):
                for ny in range(baseshape[0]):
                    c.text(
                        nx + 0.5, baseshape[0] - ny - 0.5,
                        str(baseshape[1] * min(ny, shape[0] - 1) +
                            min(nx, shape[1] - 1) + 1),
                        [text.halign.center, text.valign.middle, bgcolor])
        else:
            alertcolor = color.rgb(0.6, 0, 0)
            c.stroke(path.line(0, 0, baseshape[1], baseshape[0]),
                     [alertcolor, style.linewidth.Thick])
            c.stroke(path.line(0, baseshape[0], baseshape[1], 0),
                     [alertcolor, style.linewidth.Thick])
    else:
        for nx in range(baseshape[1]):
            for ny in range(baseshape[0]):
                c.text(nx + 0.5, baseshape[0] - ny - 0.5,
                       str(baseshape[1] * ny + nx + 1),
                       [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
def arraygraphics(a,
                  idxstr,
                  title=True,
                  xscale=1.0,
                  fgcolor=color.grey(1),
                  bgcolor=color.hsb(0.9, 1, 0.5)):
    """create a graphical representation of a two-dimensional array
    
    a         array containing the data to be shown
    slicestr  string defining the slice to be highlighted
    xscale    PyX scaling for text
    fgcolor   color of highlighted data
    bgcolor   color of highlighted cells

    """
    assert a.ndim == 2
    n0, n1 = a.shape
    highlighted = np.zeros_like(a, dtype=bool)
    exec("highlighted{} = True".format(idxstr))
    unit.set(xscale=xscale)
    text.set(text.LatexRunner)
    text.preamble(
        r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}'
    )
    c = canvas.canvas()
    for ny, nx in zip(*np.nonzero(highlighted)):
        c.fill(path.rect(nx, n0 - ny, 1, -1), [bgcolor])
    c.stroke(path.rect(0, 0, n1, n0))
    for nx in range(1, n1):
        c.stroke(path.line(nx, 0, nx, n0))
    for ny in range(1, n0):
        c.stroke(path.line(0, ny, n1, ny))
    textcentered = [text.halign.center, text.valign.middle]
    textcentered_highlighted = textcentered + [fgcolor]
    for nx in range(n1):
        for ny in range(n0):
            if highlighted[ny, nx]:
                textattrs = textcentered_highlighted
            else:
                textattrs = textcentered
            c.text(nx + 0.5, n0 - ny - 0.5, a[ny, nx], textattrs)
    if title:
        textcolor = bgcolor
    else:
        textcolor = color.grey(1)
    titlestr = r"\Large a" + idxstr.replace('%', '\%')
    c.text(0.5 * n1, n0 + 0.4, titlestr, [text.halign.center, textcolor])
    return c
Exemplo n.º 9
0
def rectangular_band(g, x_coord_init, y_coord_init, x_coord_final,
                     y_coord_final, band_color):
    """
        Function that draws a rectangular band around the given coordinates

        INPUTS:

                g               (Object) A graph-type object to which you want to add the text

                x_coord_init    (Double) x-coordinate (in plot units) at which you want the band
                                to start.

                y_coord_init    (Double) y-coordinate (in plot units) at which you want the band
                                to start.

                x_coord_final   (Double) x-coordinate (in plot units) at which you want the band
                                to end.

                y_coord_final   (Double) y-coordinate (in plot units) at which you want the band
                                to end.

                band_color      (instance) Instance color that defines the color of the band.

        """
    x0, y0 = g.pos(x_coord_init, y_coord_init)
    xf, yf = g.pos(x_coord_final, y_coord_final)

    x = x0
    y = y0
    w = np.abs(x0 - xf)
    h = np.abs(y0 - yf)

    g.fill(pyx_path.rect(x, y, w, h), [band_color])
def array34(arange, hlshape=None):
    c = canvas.canvas()
    if hlshape is None:
        c.text(2, 3.3, 'shape=(3, 4)', [text.halign.center])
    else:
        c.text(2, 3.3, 'shape=%s' % repr(hlshape), [text.halign.center])
    if hlshape is not None:
        if len(hlshape) == 1:
            hlshape = (1, hlshape[0])
    if arange:
        gridcolor = color.grey(0)
    else:
        gridcolor = color.grey(0.5)
    if hlshape is None:
        arange = True
    elif (hlshape[0] in (1, 3)) and (hlshape[1] in (1, 4)):
        arange = False
    else:
        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
Exemplo n.º 11
0
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])
Exemplo n.º 12
0
def draw_config(name):
    c = canvas.canvas()
    config = configs[name]
    ysize = len(config)
    xsize = len(config[0])
    for nx in range(xsize):
        for ny in range(ysize):
            if config[ny][nx]:
                c.fill(path.rect(nx, ysize-ny, 1, -1))
    strokecolor = color.grey(0.6)
    c.stroke(path.rect(0, 0, xsize, ysize), [strokecolor])
    for nx in range(1, xsize):
        c.stroke(path.line(nx, 0, nx, ysize), [strokecolor])
    for ny in range(1, ysize):
        c.stroke(path.line(0, ny, xsize, ny), [strokecolor])
    return c
Exemplo n.º 13
0
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])
Exemplo n.º 14
0
def draw_points_lines_crs(points: torch.Tensor,
                          lines: torch.Tensor,
                          crs: torch.Tensor,
                          filename,
                          size=1,
                          lw=1,
                          clw=1,
                          pcols=None,
                          lcols=None,
                          crscols=None,
                          canvas_clip=None,
                          svg=False):
    if canvas_clip is not None:
        c = canvas.canvas([canvas.clip(path.rect(*canvas_clip))])
    else:
        c = canvas.canvas()

    draw_points_to_canvas(c, points, size, pcols)
    draw_lines_to_canvas(c, lines, lw, lcols)
    draw_crs_to_canvas(c, crs, clw, crscols)

    if svg:
        c.writeSVGfile(file=filename)
    else:
        c.writePDFfile(file=filename)
Exemplo n.º 15
0
def guide_layer(holes):
    guide_size = 1.2

    # Get guide fiber information
    iguide = np.nonzero(np.array(holes['holetype']) == b'GUIDE')[0]
    guide_xfocal = np.array(holes['xfocal'])[iguide]
    guide_yfocal = np.array(holes['yfocal'])[iguide]
    guidenum = np.array(holes['iguide'])[iguide]

    # Set up object to print
    clippath = path.circle(0., 0., interior_radius)
    clipobject = canvas.clip(clippath)
    interior = canvas.canvas([clipobject])

    for indx in range(len(guide_xfocal)):
        interior.stroke(
            path.rect((guide_yfocal[indx] / 10.) - guide_size * 0.5,
                      (guide_xfocal[indx] / 10.) - guide_size * 0.5,
                      guide_size, guide_size),
            [style.linewidth.THick, color.cmyk.Black])
        interior.text(
            (guide_yfocal[indx] / 10.) + guide_size * 0.66,
            (guide_xfocal[indx] / 10.),
            r"\font\myfont=cmr10 at 35pt {\myfont " + str(guidenum[indx]) +
            "}", [text.halign.boxleft, text.valign.middle, text.size.Huge])

    return interior
Exemplo n.º 16
0
def state(x0, y0, r, c):
    x1 = x0 - r / sqrt(2)
    y1 = y0 + r / sqrt(2)
    x2 = x0 - 3 * r / 4 / sqrt(2)
    y2 = y1 + r / 8
    x3 = x0 - r / 4 / sqrt(2)
    y3 = y1 - r / 8
    x4 = x0 + r / 4 / sqrt(2)
    y4 = y1 + r / 8
    x5 = x0 + 3 * r / 4 / sqrt(2)
    y5 = y1 - r / 8
    x6 = x0 + r / sqrt(2)
    y6 = y1
    delta = r / 40

    c.fill(path.circle(x0, y0, r), [color.cmyk.RoyalBlue])
    c.fill(path.rect(x1 + delta, y0 + delta,
                     r * sqrt(2) - 2 * delta, r), [color.rgb.white])

    inside = path.curve(x1, y1, x2, y2, x3, y3, x0, y1) << \
             path.curve(x0, y1, x4, y4, x5, y5, x6, y6) << \
             path.line(x6, y6, x6, y0) << \
             path.line(x6, y0, x1, y0)
    inside.append(path.closepath())
    c.fill(inside, [color.cmyk.RoyalBlue])
    c.stroke(path.circle(x0, y0, r), [style.linewidth(r / 25)])
Exemplo n.º 17
0
def array34(arange, hlshape=None):
    c = canvas.canvas()
    if hlshape is None:
        c.text(2, 3.3, 'shape=(3, 4)', [text.halign.center])
    else:
        c.text(2, 3.3, 'shape=%s' % repr(hlshape), [text.halign.center])
    if hlshape is not None:
        if len(hlshape) == 1:
            hlshape = (1, hlshape[0])
    if arange:
        gridcolor = color.grey(0)
    else:
        gridcolor = color.grey(0.5)
    if hlshape is None:
        arange = True
    elif (hlshape[0] in (1, 3)) and (hlshape[1] in (1, 4)):
        arange = False
    else:
        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
def plot_key(width, height):
    c = canvas.canvas()
    step = height / float(len(method_colors))
    for i, meth in enumerate(['HiFive-Probability', 'HiFive-Express', 'HiFive-Binning']):
        c.fill(path.rect(0.2, height - step * (i + 0.5) - 0.1, 0.2, 0.2),
               [method_colors[meth]])
        c.text(0.5, height - step * (i + 0.5), meth, [text.halign.left, text.valign.middle, text.size(-2)])
    return c
def plot_key(width, height):
    c = canvas.canvas()
    w = height / 7.0
    for i, meth in enumerate(methods):
        c.fill(path.rect(1.0, (6 - i) * w - 0.1, 0.2, 0.2), [method_colors[meth]])
        c.text(1.3, (6 - i) * w, "%s" % meth_names[meth],
               [text.halign.left, text.valign.middle, text.size(-3)])
    return c
Exemplo n.º 20
0
def rect(x, y, dx, dy, intxt=None, bottxt=None):
    "x, y: lower left"
    c.stroke(path.rect(x, y, dx, dy), [style.linestyle.dashed, style.linewidth.thick, green])
    if intxt:
        c.text(x+dx/2., y+dy/2., intxt,
            [text.valign.middle, text.halign.boxcenter])
    if bottxt:
        c.text(x+dx-pip, y-pip, bottxt,
            [text.valign.top, text.halign.boxright])
def plot_key(width, height):
    c = canvas.canvas()
    w = height / 7.0
    for i, meth in enumerate(methods):
        c.fill(path.rect(1.0, (6 - i) * w - 0.1, 0.2, 0.2),
               [method_colors[meth]])
        c.text(1.3, (6 - i) * w, "%s" % meth_names[meth],
               [text.halign.left, text.valign.middle,
                text.size(-3)])
    return c
Exemplo n.º 22
0
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
Exemplo n.º 23
0
def draw(dx=0., dy=0.):

    r = 4.*m
    data1 = data.copy()
    lines = []
    for tree in trees:
      for p0 in tree.sites:
        x0, y0 = coord(*p0)
        c.fill(path.circle(x0+dx, y0+dy, r), [grey])
        p1 = tree.parent[p0]
        #print p0, p1
        if p1 is None:
            continue # root
        lines.append((p0, p1))

        x1, y1 = coord(*p1)
        #data1[p0] = 0
        #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
        #    [style.linewidth.Thick, deco.earrow(size=0.3)])

        if x0==x1:
            c.fill(path.rect(x0-r+dx, y0+dy, 2*r, y1-y0), [grey])
        else:
            c.fill(path.rect(x0+dx, y0-r+dy, x1-x0, 2*r), [grey])
        c.fill(path.circle(x0+dx, y0+dy, r), [grey])
        c.fill(path.circle(x1+dx, y1+dy, r), [grey])
        #c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
        #    [style.linewidth.THICK, style.linecap.round, grey])

    for (p0, p1) in lines:
        x0, y0 = coord(*p0)
        x1, y1 = coord(*p1)
        data1[p0] = 0
        c.stroke(path.line(x0+dx, y0+dy, x1+dx, y1+dy),
            [style.linewidth.Thick, deco.earrow(size=0.3)])

    for i, j in sites:
        c.stroke(path.rect(j*w+dx, i*h+dy, w-2*m, h-2*m))
        if data[i,j]:
            x, y = coord(i, j)
            anyon(x+dx, y+dy, 0.1*w)

    data[:] = data1
Exemplo n.º 24
0
def plot_key(width, height, data):
    methods = data.keys()
    methods.sort()
    c = canvas.canvas()
    step = height / float(len(method_colors))
    for i, meth in enumerate(methods):
        c.fill(path.rect(0.2, height - step * (i + 0.5) - 0.1, 0.2, 0.2),
               [method_colors[meth]])
        c.text(0.5, height - step * (i + 0.5), meth, [text.halign.left, text.valign.middle, text.size(-2)])
    return c
Exemplo n.º 25
0
def manifold(x, y, labels, count):

    if count in [0, 2]:
        c.stroke(path.line(x-r0, y, x+r1+r0, y), st_curve)
    else:
        extra = list(st_curve)
        #if count==3:
        #    extra.append(trafo.scale(x=x, y=y, sx=1, sy=-1))
        Turtle(x-0.85*r0, y, pi/2).\
            fwd(0.3).\
            right(0.25*pi, 0.4).left(0.50*pi, 0.73).left(0.88*pi, 0.15).\
            fwd(0.55).\
            right(0.88*pi, 0.15).right(0.50*pi, 0.73).\
            left(0.25*pi, 0.52).goto(x+r1+r0, y).\
            stroke(extra)

    if count==0:
        c.text(x+r1+r0, y-0.2, "$f$", northwest)
    else:
        c.text(x+r1+r0, y-0.2, "$R^{a_1a_2}_{b_1}f$", northwest)

    c.text(x+(r0+r1)/2, y+0.7, "$f'$", southwest)

    if count == 0:
        Turtle(x, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*r1).stroke(st_target+[trafo.scale(x=x, y=y, sx=1, sy=-1)])
    elif count == 3:
        Turtle(x-0.05, y, 0.90*pi).left(0.30*pi, 0.8).left(0.3*pi, 2.8).\
            stroke(st_target+[trafo.scale(x=x, y=y, sx=1, sy=-1)])
    else:
        Turtle(x+r0, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*(r1-r0)).stroke(st_target)

    for i in range(3):
        _x = [x, x+r0, x+r1][i]
        p = path.circle(_x, y, 0.08)
        c.fill(p, [white])
        c.stroke(p)
        ydelta = -0.25
        xdelta = 0.00
        if count==3  and labels[i]=="a_2":
            ydelta = -0.35
            xdelta = +0.1
        if count==3  and labels[i]=="a_1":
            xdelta = -0.1
            ydelta = +0.3
        c.text(_x+xdelta, y+ydelta, r"$\scriptstyle %s$"%labels[i], center)

    x1 = x+(r0+r1)/2.
    c.text(x1, y-0.2, "...", north)

    c.fill(path.rect(x1-0.4, y-0.1, 0.8, 0.2), [white])
    c.stroke(path.line(x1-0.4, y, x1+0.4, y), [green, style.linewidth.THick]+st_dotted)

    c.stroke(path.circle(x+r0/2, y, r0), [trafo.scale(x=x+r0/2, y=y, sx=1.0, sy=0.8)])

    c.text(x, y+0.3*h, "$b_1$", southeast)
def arraygraphics(a, idxstr, title=True, xscale=1.0,
               fgcolor=color.grey(1), bgcolor=color.hsb(0.9, 1, 0.5)):
    """create a graphical representation of a two-dimensional array
    
    a         array containing the data to be shown
    slicestr  string defining the slice to be highlighted
    xscale    PyX scaling for text
    fgcolor   color of highlighted data
    bgcolor   color of highlighted cells

    """
    assert a.ndim == 2
    n0, n1 = a.shape
    highlighted = np.zeros_like(a, dtype=bool)
    exec("highlighted{} = True".format(idxstr))
    unit.set(xscale=xscale)
    text.set(text.LatexRunner)
    text.preamble(r'\usepackage[sfdefault,scaled=.85,lining]{FiraSans}\usepackage{newtxsf}')
    c = canvas.canvas()
    for ny, nx in zip(*np.nonzero(highlighted)):
        c.fill(path.rect(nx, n0-ny, 1, -1), [bgcolor])
    c.stroke(path.rect(0, 0, n1, n0))
    for nx in range(1, n1):
        c.stroke(path.line(nx, 0, nx, n0))
    for ny in range(1, n0):
        c.stroke(path.line(0, ny, n1, ny))
    textcentered = [text.halign.center, text.valign.middle]
    textcentered_highlighted = textcentered+[fgcolor]
    for nx in range(n1):
        for ny in range(n0):
            if highlighted[ny, nx]:
                textattrs = textcentered_highlighted
            else:
                textattrs = textcentered
            c.text(nx+0.5, n0-ny-0.5, a[ny, nx], textattrs)
    if title:
        textcolor = bgcolor
    else:
        textcolor = color.grey(1)
    titlestr = r"\Large a"+idxstr.replace('%', '\%')
    c.text(0.5*n1, n0+0.4, titlestr, [text.halign.center, textcolor])
    return c
def plot_key(width, height):
    c = canvas.canvas()
    step = height / float(len(method_colors))
    for i, meth in enumerate(
        ['HiFive-Probability', 'HiFive-Express', 'HiFive-Binning']):
        c.fill(path.rect(0.2, height - step * (i + 0.5) - 0.1, 0.2, 0.2),
               [method_colors[meth]])
        c.text(0.5, height - step * (i + 0.5), meth,
               [text.halign.left, text.valign.middle,
                text.size(-2)])
    return c
Exemplo n.º 28
0
 def clear(self):
     """
     Erases the contents of this Window
     
     All Turtles and Pens are eliminated from the Window. Any attempt to use a 
     previously created :class:`Turtle` or :class:`Pen` will fail.
     """
     from pyx import canvas
     from pyx import path
     clippath = path.rect(self.x, self.y, self.width, self.height)
     self._canvas = canvas.canvas([canvas.clip(clippath)])
     self._turtles = []
     self._pencils = []
Exemplo n.º 29
0
def file(c, size=1, xoff=0, yoff=0, attrs=[], title=''):
    w = 3
    h = 2.1
    fold = 0.6
    outline = path.path(path.moveto(0, 0), path.lineto(w, 0),
                        path.lineto(w, h - fold), path.lineto(w - fold, h),
                        path.lineto(0, h), path.closepath())
    foldpath = path.path(path.moveto(w - fold, h),
                         path.lineto(w - fold, h - fold),
                         path.lineto(w, h - fold))
    c1 = canvas.canvas()
    c1.stroke(outline, attrs)
    d = deformer.smoothed(0.2)
    c1.stroke(d.deform(foldpath), attrs)
    c1.stroke(path.rect(0.1 * w, 0.3 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.45 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.6 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.75 * h, 0.6 * w, 0.1 * h))
    c1.text(0.1, 0.1, r'\sffamily ' + title, [trafo.scale(0.7)])
    myattrs = [trafo.translate(xoff, yoff), trafo.scale(size)]
    myattrs.extend(attrs)
    c.insert(c1, myattrs)
def generate_tile(item):
    title = item['title']
    print(title)
    image = item['image']

    if item['quantity'] > 1:
        handle_multiple(item)
        return

    #72dpi is illustrator default
    drawing = svgfile.svgfile(0, 0, 'images%s' % image, parsed=True, resolution=72)
    setEtch(drawing.canvas)
    canvas_size = get_canvas_size(item)
    drawing_size = (drawing.bbox().width(), drawing.bbox().height())

    dir = 'tiles/%s' % item['type']
    if not os.path.exists(dir):
        os.makedirs(dir)
    c = canvas.canvas()

    center = ( (canvas_size[0] - drawing_size[0]) / 2, (canvas_size[1] - drawing_size[1]) / 2 )
    c.insert(drawing, [trafo.translate(center[0], center[1])])

    yMargin = (canvas_size[1] - drawing_size[1]) / 2
    yPos = yMargin - yMargin / 2
    baseline = text.parbox.middle
    textbox = '{\large %s}' % title
    if 'subtitle' in item:
        textbox += '\n\n'
        textbox += item['subtitle']

    if yPos < (unit.t_inch / 2):
        baseline = text.parbox.bottom

    c.text(canvas_size[0] / 2, yPos, textbox, [
            text.halign.boxcenter,
            text.halign.flushcenter,
            text.parbox(canvas_size[0] - .25 * unit.t_inch, baseline = baseline)
    ])

    #draw Cut line
    if CUT_LINE:
        c.stroke(
            path.rect(0, 0, canvas_size[0], canvas_size[1]),
            [ style.linewidth(0.001), color.rgb.red ]
        )

    p = document.page(c, bbox=bbox.bbox(0, 0, canvas_size[0], canvas_size[1]))
    d = document.document([p])
    d.writeSVGfile('%s/%s.svg' % (dir, slugify(title)))
Exemplo n.º 31
0
def drawgrid(c, nxcells, nycells, yoff, gridcolor=color.grey(0), arange=None):
    c.stroke(path.rect(0, yoff, nxcells, nycells), [gridcolor])
    for nx in range(nxcells-1):
        c.stroke(path.line(nx+1, yoff, nx+1, yoff+nycells), [gridcolor])
    for ny in range(nycells-1):
        c.stroke(path.line(0, yoff+ny+1, nxcells, yoff+ny+1), [gridcolor])
    entry = '1'
    if arange is not None:
        for nx in range(nxcells):
            for ny in range(nycells):
                if arange:
                    entry = str(4*ny+nx)
                c.text(nx+0.5, 2.5-ny, entry,
                       [text.halign.center, text.valign.middle, gridcolor])
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
Exemplo n.º 33
0
def test_pie(radius, start, end):
    c = canvas.canvas()
    container = path.rect(-(radius + 1), -(radius + 1), 2 * (radius + 1),
                          2 * (radius + 1))

    c.stroke(container, [style.linewidth(0.001), color.rgb.red])

    pie = path.path(path.moveto(0, 0), path.arc(0, 0, radius, start, end),
                    path.closepath())

    c.stroke(pie, [
        style.linewidth(0.1),
        pyx.color.rgb(1, 1, 1),
        deco.filled([color.rgb.red])
    ])
    c.writeSVGfile("figure")
Exemplo n.º 34
0
def plot_key(width, height):
    c = canvas.canvas()
    wstep = width / 2.0
    hstep = height / 3
    for i in range(5):
        x = wstep * (i / 3)
        y = height - (i % 3 + 0.5) * hstep
        c.fill(path.rect(x + 0.1, y - 0.15, 0.3, 0.3), [step_colors[i]])
        temp = step_names[str(i)].split(' ')
        if len(temp) > 2:
            c.text(x + 0.5, y + 0.13, ' '.join(temp[:2]),
                   [text.halign.left, text.valign.middle, text.size(-2)])
            c.text(x + 0.5, y - 0.13, temp[-1],
                   [text.halign.left, text.valign.middle, text.size(-2)])
        else:
            c.text(x + 0.5, y, step_names[str(i)],
                   [text.halign.left, text.valign.middle, text.size(-2)])
    return c
Exemplo n.º 35
0
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)
Exemplo n.º 36
0
    def plot(self, canvas, shape="s"):
        """Plot this direction on a pyx canvas.

        The direction will be transformed onto a Lambert equal-area 
        projection and plotted as a square, circle, or triangle
        (shape parameter: s, c, or t).
        """
        (x, y) = self.project()
        if shape == "s":
            canvas.stroke(path.rect(x - 0.1, y - 0.1, 0.2, 0.2))
        elif shape == "t":
            s = 0.15
            canvas.stroke(path.path(path.moveto(x, y + s),
                                    path.rlineto(-0.866 * s, -1.5 * s),
                                    path.rlineto(2 * .866 * s, 0),
                                    path.closepath()))
        elif shape == "c":
            canvas.stroke(path.circle(x, y, 0.1))
Exemplo n.º 37
0
def generate_diagrams(data, shape_canvas, text_canvas, settings, source_path):
    diagrams = {}
    # draw bounding box so the file is the right size and shape
    x = settings['output']['x']
    y = settings['output']['y']

    # draw the bounding box
    shape_canvas.stroke(
        path.rect(-0.25 * x, -0.5 * y, x, y),
        [color.rgb.white, style.linewidth(0.001)])
    for entry in data:
        name = entry[0]
        origin = entry[1]
        data_source = entry[2]
        diagrams[name] = Sunburst(shape_canvas, text_canvas, settings,
                                  source_path, name, origin, data_source)
        diagrams[name].draw()
        stop_trace()
    return diagrams
Exemplo n.º 38
0
def make_moon_key(canv, chart) :
    large_moon_rad = 0.16
    small_moon_rad = 0.12
    x = 0.0
    y = -1.8
    canv.fill(path.rect(x, y, chart.width, 1.0), 
            [color.rgb(0.0, 0.0, 0.0)])
    for i in range(8) :
        X = 1.0-(i+1.0)/9.0
        canv.fill(waning_moon(X, small_moon_rad, x+(i+4.0)/4.0, -1.3),
                    [style.linejoin.bevel,mooncolorlight])
    canv.text(x+1.8, -1.1,
              r'{\footnotesize\sffamily Küçülen Ay}',
              [text.halign.center,text.valign.baseline,mooncolorlight])
    canv.text(x+1.8, -1.7,
              r"{\scriptsize\sffamily (Ay'ın doğuş zamanları)}",
              [text.halign.center,text.valign.baseline,mooncolorlight])
    for i in range(8) :
        X = (i+1.0)/9.0
        canv.fill(waxing_moon(X, small_moon_rad, x+(i+4.0)/4.0+3.0, -1.3),
                    [style.linejoin.bevel,mooncolordark])
    canv.text(x+1.8+3.0, -1.1,
              r'{\footnotesize\sffamily Büyüyen Ay}',
              [text.halign.center,text.valign.baseline,mooncolordark])
    canv.text(x+1.8+3.0, -1.7,
              r"{\scriptsize\sffamily (Ay'ın batış zamanları)}",
              [text.halign.center,text.valign.baseline,mooncolordark])
    # new moon, first quarter
    # full moon,  last quarter
    canv.stroke(path.circle(x+8.5,-1.1,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolordark])])
    canv.text(x+8.25, -1.2, r'{\footnotesize\sffamily Yeni ay}',
            [text.halign.right,text.valign.baseline, mooncolordark])
    canv.stroke(first_quarter_moon(large_moon_rad, x+8.9,-1.1),[mooncolordark,pyx.deco.filled([mooncolordark])])
    canv.text(x+9.25, -1.2, r'{\footnotesize\sffamily İlk dördün}',
            [text.halign.left,text.valign.baseline, mooncolordark])
    canv.stroke(path.circle(x+8.5,-1.5,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
    canv.text(x+8.25, -1.6, r'{\footnotesize\sffamily Dolunay}',
            [text.halign.right,text.valign.baseline, mooncolorlight])
    canv.stroke(last_quarter_moon(large_moon_rad, x+8.9,-1.5),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
    canv.text(x+9.25, -1.6, r'{\footnotesize\sffamily Son dördün}',
            [text.halign.left,text.valign.baseline, mooncolorlight])
Exemplo n.º 39
0
def whiteout_layer(holes):
    whiteout = canvas.canvas()
    for indx in range(len(holes['xfocal'])):
        radius = 0.25
        if (holes['holetype'][indx] == b'GUIDE'):
            radius = 0.54
        if (holes['holetype'][indx] == b'ALIGNMENT'):
            radius = 0.1
        if (holes['holetype'][indx] == b'MANGA'):
            radius = 0.4
        if (holes['holetype'][indx] == b'MANGA_SINGLE'):
            radius = 0.4
        if (holes['holetype'][indx] == b'MANGA_ALIGNMENT'):
            radius = 0.2
        if (holes['holetype'][indx] == b'CENTER'):
            radius = 0.36
        if (holes['holetype'][indx] == b'TRAP'):
            radius = 0.45
        if (holes['holetype'][indx] == b'ACQUISITION_CENTER'):
            radius = 2.9
        whiteout.fill(
            path.circle(holes['yfocal'][indx] / 10.,
                        holes['xfocal'][indx] / 10., radius),
            [color.rgb.white])

    ioffaxis = np.nonzero(
        np.array(holes['holetype']) == b'ACQUISITION_OFFAXIS')[0]
    if (len(ioffaxis) == 0):
        return whiteout
    if (len(ioffaxis) > 1):
        print("Expect just one off-axis acquisition camera.")
        sys.exit()
    offaxis_xfocal = np.array(holes['xfocal'])[ioffaxis[0]]
    offaxis_yfocal = np.array(holes['yfocal'])[ioffaxis[0]]
    whiteout.fill(
        path.rect((offaxis_yfocal / 10.) - offaxis_ysize * 0.49,
                  (offaxis_xfocal / 10.) - offaxis_xsize * 0.49,
                  0.98 * offaxis_ysize, 0.98 * offaxis_xsize),
        [color.rgb.white])

    return whiteout
Exemplo n.º 40
0
def plot_key(width, height):
    c = canvas.canvas()
    wstep = width / 2.0
    hstep = height / 3
    for i in range(5):
        x = wstep * (i / 3)
        y = height - (i % 3 + 0.5) * hstep
        c.fill(path.rect(x + 0.1, y - 0.15, 0.3, 0.3), [step_colors[i]])
        temp = step_names[str(i)].split(' ')
        if len(temp) > 2:
            c.text(x + 0.5, y + 0.13, ' '.join(temp[:2]),
                   [text.halign.left, text.valign.middle,
                    text.size(-2)])
            c.text(x + 0.5, y - 0.13, temp[-1],
                   [text.halign.left, text.valign.middle,
                    text.size(-2)])
        else:
            c.text(x + 0.5, y, step_names[str(i)],
                   [text.halign.left, text.valign.middle,
                    text.size(-2)])
    return c
Exemplo n.º 41
0
    def flush(self):
        """
        Writes out all of the pens and turtles attached to the window.
        """
        # Draw a bounding box
        from pyx import path
        from pyx import text
        r = path.rect(0, 0, self.width, self.height)
        self._canvas.stroke(r)

        for t in self._turtles:
            t.flush()

        for p in self._pencils:
            p.flush()

        # Write the title, if we have one
        if not self.title is None:
            self._canvas.text(
                0, self.height / 2.0 - 30, "{\\Huge %s}" % self.title,
                [text.halign.boxcenter, self._offset()])
Exemplo n.º 42
0
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_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
Exemplo n.º 44
0
    def pyx_plotter(self):
        from pyx import canvas, path, color

        st = Stats(self.points)

        if self.plot_range == AUTO:
            xmax, xmin, ymax, ymin = st.bbox_auto(self.points)
        else:
            xmax, xmin, ymax, ymin = st.bbox()
        wd, ht = xmax - xmin, ymax - ymin

        sx = self.default_width / wd
        sy = self.aspect_ratio * self.default_width / ht
        #print 'WD:', wd, 'HT:', ht, sx, sy

        clip = canvas.clip(path.rect(sx * xmin, sy * ymin, sx * wd, sy * ht))

        c = canvas.canvas([clip])
        #c.stroke(path.rect(sx*xmin, sy*ymin, sx*wd, sy*ht))

        pth = path.path()
        first_point = True

        for p in self.points:
            if first_point:
                pth.append(path.moveto(sx * p.x, sy * p.y))
                first_point = False
            else:
                pth.append(path.lineto(sx * p.x, sy * p.y))

        c.stroke(pth)

        for p in self.points:
            if st.is_extreme_outlier(p):
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03), [color.rgb.red])
            else:
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03))
        return c
Exemplo n.º 45
0
def acquisition_layer(holes):

    # Get camera info
    icenter = np.nonzero(
        np.array(holes['holetype']) == b'ACQUISITION_CENTER')[0]
    if (len(icenter) == 0):
        return None
    if (len(icenter) > 1):
        print("Expect just one central acquisition camera.")
    center_xfocal = np.array(holes['xfocal'])[icenter[0]]
    center_yfocal = np.array(holes['yfocal'])[icenter[0]]

    ioffaxis = np.nonzero(
        np.array(holes['holetype']) == b'ACQUISITION_OFFAXIS')[0]
    if (len(ioffaxis) == 0):
        print("If there is a center acquisition camera we expect an off-axis.")
        sys.exit()
    if (len(ioffaxis) > 1):
        print("Expect just one off-axis acquisition camera.")
        sys.exit()
    offaxis_xfocal = np.array(holes['xfocal'])[ioffaxis[0]]
    offaxis_yfocal = np.array(holes['yfocal'])[ioffaxis[0]]

    # Set up object to print
    clippath = path.circle(0., 0., interior_radius)
    clipobject = canvas.clip(clippath)
    interior = canvas.canvas([clipobject])

    interior.stroke(
        path.circle(center_yfocal / 10., center_xfocal / 10., center_radius),
        [style.linewidth.THick, color.cmyk.Black])

    interior.stroke(
        path.rect((offaxis_yfocal / 10.) - offaxis_ysize * 0.5,
                  (offaxis_xfocal / 10.) - offaxis_xsize * 0.5, offaxis_ysize,
                  offaxis_xsize), [style.linewidth.THick, color.cmyk.Black])

    return interior
Exemplo n.º 46
0
    def pyx_plotter(self):
        from pyx import canvas, path, color

        st = Stats(self.points)

        if self.plot_range == AUTO:
            xmax, xmin, ymax, ymin = st.bbox_auto(self.points)
        else:
            xmax, xmin, ymax, ymin = st.bbox()
        wd, ht = xmax - xmin, ymax - ymin

        sx = self.default_width / wd
        sy = self.aspect_ratio * self.default_width / ht
        #print 'WD:', wd, 'HT:', ht, sx, sy

        clip = canvas.clip(path.rect(sx * xmin, sy * ymin, sx * wd, sy * ht))

        c = canvas.canvas([clip])
        #c.stroke(path.rect(sx*xmin, sy*ymin, sx*wd, sy*ht))

        pth = path.path()
        first_point = True

        for p in self.points:
            if first_point:
                pth.append(path.moveto(sx * p.x, sy * p.y))
                first_point = False
            else:
                pth.append(path.lineto(sx * p.x, sy * p.y))

        c.stroke(pth)

        for p in self.points:
            if st.is_extreme_outlier(p):
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03), [color.rgb.red])
            else:
                c.fill(path.circle(sx * p.x, sy * p.y, 0.03))
        return c
Exemplo n.º 47
0
def make_moon_key2_eng(canv, chart, y) :
    x = 0.0
    canv.fill(path.rect(x, y, chart.width, 1.0), 
            [color.rgb(0.0, 0.0, 0.0)])
    for i in range(8) :
        X = 1.0-(i+1.0)/9.0
        canv.fill(waning_moon(X, 0.08, x+(i+4.0)/4.0, y+0.5),
                    [style.linejoin.bevel,mooncolorlight])
    canv.text(x+1.8, y+0.7,
              r'{\footnotesize\sffamily Waning Moon}',
              [text.halign.center,text.valign.baseline,mooncolorlight])
    canv.text(x+1.8, y+0.2,
              r"{\scriptsize\sffamily (Moon rising)}",
              [text.halign.center,text.valign.baseline,mooncolorlight])
    for i in range(8) :
        X = (i+1.0)/9.0
        canv.fill(waxing_moon(X, 0.08, x+(i+4.0)/4.0+3.0, y+0.5),
                    [style.linejoin.bevel,mooncolordark])
    canv.text(x+1.8+3.0, y+0.7,
              r'{\footnotesize\sffamily Waxing Moon}',
              [text.halign.center,text.valign.baseline,mooncolordark])
    canv.text(x+1.8+3.0, y+0.2,
              r"{\scriptsize\sffamily (Moon setting)}",
              [text.halign.center,text.valign.baseline,mooncolordark])
    # new moon, first quarter
    # full moon,  last quarter
    canv.stroke(path.circle(x+8.5,y+0.75,.12),[mooncolorlight,pyx.deco.filled([mooncolordark])])
    canv.text(x+8.25, y+0.65, r'{\footnotesize\sffamily New Moon}',
            [text.halign.right,text.valign.baseline, mooncolordark])
    canv.stroke(first_quarter_moon(0.12, x+8.9,y+0.75),[mooncolordark,pyx.deco.filled([mooncolordark])])
    canv.text(x+9.25, y+0.65, r'{\footnotesize\sffamily First Quarter}',
            [text.halign.left,text.valign.baseline, mooncolordark])
    canv.stroke(path.circle(x+8.5,y+0.35,.12),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
    canv.text(x+8.25, y+0.25, r'{\footnotesize\sffamily Full Moon}',
            [text.halign.right,text.valign.baseline, mooncolorlight])
    canv.stroke(last_quarter_moon(0.12, x+8.9,y+0.35),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
    canv.text(x+9.25, y+0.25, r'{\footnotesize\sffamily Last Quarter}',
            [text.halign.left,text.valign.baseline, mooncolorlight])
Exemplo n.º 48
0
def make_moon_key2(canv, chart, y) :
    x = 0.0
    canv.fill(path.rect(x, y, chart.width-1.0, 1.0), 
            [color.rgb(0.0, 0.0, 0.0)])
    for i in range(8) :
        X = 1.0-(i+1.0)/9.0
        canv.fill(waning_moon(X, 0.08, x+(i+4.0)/4.0, y+0.5),
                    [style.linejoin.bevel,mooncolorlight])
    canv.text(x+1.8, y+0.7,
              r'{\footnotesize\sffamily Küçülen Ay}',
              [text.halign.center,text.valign.baseline,mooncolorlight])
    canv.text(x+1.8, y+0.2,
              r"{\scriptsize\sffamily (Ay'ın doğuş zamanları)}",
              [text.halign.center,text.valign.baseline,mooncolorlight])
    for i in range(8) :
        X = (i+1.0)/9.0
        canv.fill(waxing_moon(X, 0.08, x+(i+4.0)/4.0+3.0, y+0.5),
                    [style.linejoin.bevel,mooncolordark])
    canv.text(x+1.8+3.0, y+0.7,
              r'{\footnotesize\sffamily Büyüyen Ay}',
              [text.halign.center,text.valign.baseline,mooncolordark])
    canv.text(x+1.8+3.0, y+0.2,
              r"{\scriptsize\sffamily (Ay'ın batış zamanları)}",
              [text.halign.center,text.valign.baseline,mooncolordark])
    # new moon, first quarter
    # full moon,  last quarter
    canv.stroke(path.circle(x+8.5,y+0.7,.12),[mooncolorlight,pyx.deco.filled([mooncolordark])])
    canv.text(x+8.25, y+0.6, r'{\footnotesize\sffamily Yeni Ay}',
            [text.halign.right,text.valign.baseline, mooncolordark])
    canv.stroke(first_quarter_moon(0.12, x+8.9,y+0.7),[mooncolordark,pyx.deco.filled([mooncolordark])])
    canv.text(x+9.25, y+0.6, r'{\footnotesize\sffamily İlk Dördün}',
            [text.halign.left,text.valign.baseline, mooncolordark])
    canv.stroke(path.circle(x+8.5,y+0.3,.12),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
    canv.text(x+8.25, y+0.2, r'{\footnotesize\sffamily Dolunay}',
            [text.halign.right,text.valign.baseline, mooncolorlight])
    canv.stroke(last_quarter_moon(0.12, x+8.9,y+0.3),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
    canv.text(x+9.25, y+0.2, r'{\footnotesize\sffamily Son Dördün}',
            [text.halign.left,text.valign.baseline, mooncolorlight])
Exemplo n.º 49
0
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
Exemplo n.º 50
0
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])
Exemplo n.º 51
0
highlight = rgb(0.6, 0.6, 0.6)
#highlight = white
#highlight = rgb(1,1,0)

HH = 0.6*H
X0 = -10.
X1 = 0.

for X in [X0, X1]:

    tr = trafo.translate(X, 0.)
    
    for i in range(-3, 2):
        extra = [highlight] if (i%2) else [shade]
        c.fill(path.rect(2*i*r+r, 0, 2*r, HH), extra+[tr])
        extra = [shade] if (i%2) else [highlight]
        c.fill(path.rect(2*i*r+r, -HH, 2*r, HH), extra+[tr])
    c.stroke(path.rect(-5*r, -HH, 10*r, 2*HH), [tr])
    
    radius = 0.1
    for x in [-3*r, -r, r, 3*r]:
        c.fill(path.circle(x, 0., radius), [tr]) # focus


c.stroke(path.line(-8*r, 0, -6*r, 0), [deco.earrow()])
c.stroke(path.line(-8*r, -0.1, -8*r, +0.1))
c.text(-7*r, +0.2, r"$\sigma_i$", south)

c.text(X0-3*r, -0.4, "$...$", center)
c.text(X0-r, -0.4, "$i$", center)
Exemplo n.º 52
0
y -= 3*dr

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)]
Exemplo n.º 53
0
def draw_square(x, y, kante):
    c.fill(path.rect(x, y, kante, kante), [color.grey(1)])
    c.stroke(path.line(x, y, x + kante, y + kante),
             [style.linewidth.thick, color.grey(0.5)])
    c.stroke(path.rect(x, y, kante, kante), [style.linewidth.thick])
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)
Exemplo n.º 55
0
from pyx import canvas, color, deco, path, text, trafo

text.set(text.LatexRunner)
c = canvas.canvas()

codepoint = 0x00E9
bits = 16

codepointbinary = [(codepoint & 2**n)/2**n for n in range(bits)]
codepointbinary.reverse()

size = 0.4
x0 = 0
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),
Exemplo n.º 56
0
x, y = 0., 0.

frame()

for i in range(3):
    a = 0.1*i+0.3
    c.stroke(path.line(x, y+a*h, x+w, y+(a+0.0)*h), st_tau)


dx = 0.2*w
for i in range(3, 6):
    a = 0.1*i+0.3
    c.stroke(path.line(x+0.18*w+dx, y+a*h, x+0.20*w+dx, y+(a+0.00)*h), st_tau)

c.fill(path.rect(x+0.2*w+dx, y, x+0.25*w+dx, y+h), [white])

c.text(x+0.2*w+dx, y+0.55*h, r"$\Big\} k$", west)


x += 1.1*w

c.text(x, y+0.5*h, r"$= f_{k-1}$", west)

x += 0.8*w
frame()

c.stroke(path.line(x, y+0.5*h, x+w, y+0.5*h), st_vac)

x += 1.1*w
c.text(x, y+0.5*h, r"$+ f_k$", west)
Exemplo n.º 57
0
    c = old_c
    old_c = None


# --------------------------------------------------------------------

w, h = 1.0, 1.0
m = 0.1

#x0, y0 = 0.6, h + 10*m
x0, y0 = 0., 0.

push()
#c.text(x0-0.8, y0, "(a)")

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)])
text.set(text.LatexRunner)
text.preamble(r'''\usepackage[T1]{fontenc}
                  \usepackage{bera}
                  \renewcommand*\familydefault{\ttdefault}
                  \usepackage{color}
                  \definecolor{ex1}{rgb}{0, 0, 0.7}
                  \definecolor{ex2}{rgb}{0, 0.6, 0}
                  \definecolor{ex3}{rgb}{0.7, 0, 0}''')
unit.set(xscale=1.2)

c = canvas.canvas()

ex1color = color.rgb(0, 0, 0.7)
linewidth = 0.1*boxsize
for n in (0, 2, 5):
    c.fill(path.rect(n*boxsize+linewidth, linewidth,
                     boxsize-2*linewidth, 3*boxsize-2*linewidth),
           [ex1color])
    c.fill(path.rect(n*boxsize+2*linewidth, 2*linewidth,
                     boxsize-4*linewidth, 3*boxsize-4*linewidth),
           [color.grey(1)])

ex2color = color.rgb(0, 0.6, 0)
linewidth = 0.1
for n in range(5):
    markbox((n+1)*boxsize, (ncols-n-1)*boxsize, ex2color)

ex3color = color.rgb(0.7, 0, 0)
linewidth = 0.1
for n in (0, 2, 5):
    markbox(2*boxsize, (ncols-n-1)*boxsize, ex3color)