Example #1
0
 def draw(self, ax, height=.6):
     if self.broken is None:
         GeneGlyph(ax,
                   self.x1,
                   self.x2,
                   self.y,
                   height,
                   tip=2,
                   color=self.color,
                   gradient=True)
     else:
         a, lcolor, rcolor = self.broken
         if self.sign < 0:
             lcolor, rcolor = rcolor, lcolor
         GeneGlyph(ax,
                   self.x1,
                   a,
                   self.y,
                   height,
                   tip=0,
                   color=lcolor,
                   gradient=True)
         GeneGlyph(ax,
                   a,
                   self.x2,
                   self.y,
                   height,
                   tip=2,
                   color=rcolor,
                   gradient=True)
Example #2
0
def plot_diagram(ax, x, y, label="S", title="syntenic", gradient=True):
    """
    Part of the diagrams that are re-used. (x, y) marks the center of the
    diagram. Label determines the modification to the "S" graph.
    """
    trackgap = 0.06
    tracklen = 0.12
    xa, xb = x - tracklen, x + tracklen
    ya, yb = y + trackgap, y - trackgap
    hsps = (((60, 150), (50, 130)), ((190, 225), (200, 240)), ((330, 280), (360, 310)))

    for yy in (ya, yb):
        ax.plot((xa, xb), (yy, yy), "-", color="gray", lw=2, zorder=1)

    ytip = 0.015
    mrange = 400
    m = lambda t: xa + t * 1.0 / mrange * tracklen * 2

    for i, ((a, b), (c, d)) in enumerate(hsps):
        fb = False
        if label == "FB" and i == 1:
            c, d = 270, 280
            fb = True
        if label == "G" and i == 0:
            c, d = 120, 65

        a, b, c, d = [m(t) for t in (a, b, c, d)]
        color = "g" if i == 1 else "r"
        GeneGlyph(ax, a, b, ya, 2 * ytip, fc=color, gradient=gradient, zorder=10)

        if i == 1 and label in ("F", "G", "FN"):
            pass
        else:
            if fb:
                GeneGlyph(
                    ax, c, d, yb, 2 * ytip, fc="w", tip=0, gradient=gradient, zorder=10
                )
            else:
                GeneGlyph(ax, c, d, yb, 2 * ytip, fc="r", gradient=gradient, zorder=10)

        r = Polygon(
            ((a, ya - ytip), (c, yb + ytip), (d, yb + ytip), (b, ya - ytip)),
            fc="r",
            alpha=0.2,
        )

        if i == 1 and label not in ("S", "FB"):
            pass
        elif i == 0 and label == "G":
            pass
        else:
            ax.add_patch(r)

    if label == "FN":
        ax.text(x + 0.005, yb, "NNNNN", ha="center", size=7)

    title = "{0}: {1}".format(label, title)
    ax.text(x, ya + 5 * ytip, title, size=8, ha="center")