Exemplo n.º 1
0
def prettyplot():
    reds = mpl.cm.Reds
    reds.set_bad("white")
    reds.set_under("white")

    blues_r = mpl.cm.Blues_r
    blues_r.set_bad("white")
    blues_r.set_under("white")

    # Need to 'reverse' red to blue so that blue=cold=small numbers,
    # and red=hot=large numbers with '_r' suffix
    blue_red = get_map("RdBu", "diverging", 11, reverse=True).mpl_colormap
    green_purple = get_map("PRGn", "diverging", 11).mpl_colormap
    red_purple = get_map("RdPu", "sequential", 9).mpl_colormap

    return blues_r, reds, blue_red, green_purple, red_purple
Exemplo n.º 2
0
def main():
    SIZE = 20
    PLOIDY = 2
    MUTATIONS = 2

    indices = range(SIZE)
    # Build fake data
    seqA = list("0" * SIZE)
    allseqs = [seqA[:] for x in range(PLOIDY)]  # Hexaploid
    for s in allseqs:
        for i in [choice(indices) for x in range(MUTATIONS)]:
            s[i] = "1"

    allseqs = [make_sequence(s, name=name) for (s, name) in \
                zip(allseqs, [str(x) for x in range(PLOIDY)])]

    # Build graph structure
    G = Graph("Assembly graph", filename="graph")
    G.attr(rankdir="LR", fontname="Arial", splines="true")
    G.attr(ranksep=".2", nodesep="0.02")
    G.attr('node', shape='point')
    G.attr('edge', dir='none', penwidth='4')

    colorset = get_map('Set2', 'qualitative', 8).mpl_colors
    colorset = [to_hex(x) for x in colorset]
    colors = sample(colorset, PLOIDY)
    for s, color in zip(allseqs, colors):
        sequence_to_graph(G, s, color=color)
    zip_sequences(G, allseqs)

    # Output graph
    G.view()
Exemplo n.º 3
0
def main():
    SIZE = 20
    PLOIDY = 2
    MUTATIONS = 2

    indices = range(SIZE)
    # Build fake data
    seqA = list("0" * SIZE)
    allseqs = [seqA[:] for x in range(PLOIDY)]  # Hexaploid
    for s in allseqs:
        for i in [choice(indices) for x in range(MUTATIONS)]:
            s[i] = "1"

    allseqs = [make_sequence(s, name=name) for (s, name) in \
                zip(allseqs, [str(x) for x in range(PLOIDY)])]

    # Build graph structure
    G = Graph("Assembly graph", filename="graph")
    G.attr(rankdir="LR", fontname="Helvetica", splines="true")
    G.attr(ranksep=".2", nodesep="0.02")
    G.attr('node', shape='point')
    G.attr('edge', dir='none', penwidth='4')

    colorset = get_map('Set2', 'qualitative', 8).mpl_colors
    colorset = [to_hex(x) for x in colorset]
    colors = sample(colorset, PLOIDY)
    for s, color in zip(allseqs, colors):
        sequence_to_graph(G, s, color=color)
    zip_sequences(G, allseqs)

    # Output graph
    G.view()
Exemplo n.º 4
0
Arquivo: cnv.py Projeto: xuanblo/jcvi
    def plot(self, samplekey, chrs=allsomes, color=None, dx=None, ymax=8,
             ms=2, alpha=.7):

        import matplotlib.pyplot as plt
        from jcvi.utils.brewer2mpl import get_map

        props = dict(boxstyle='round', facecolor='wheat', alpha=0.2)

        if isinstance(chrs, str):
            chrs = [chrs]
        f, axs = plt.subplots(1, len(chrs), sharey=True)
        if not isinstance(axs, np.ndarray):
            axs = np.array([axs])
        plt.tight_layout()
        if color is None:
            color = choice(get_map('Set2', 'qualitative', 8).mpl_colors)

        for region, ax in zip(chrs, axs):
            chr, start, end = parse_region(region)
            X, Z, clen, events = self.run_one(samplekey, chr)
            ax.plot(X, ".", label="observations",
                    ms=ms, mfc=color, alpha=alpha)
            ax.plot(Z, "k.", label="hidden", ms=6)

            if start is None and end is None:
                ax.set_xlim(0, clen)
            else:
                ax.set_xlim(start / 1000, end / 1000)

            ax.set_ylim(0, ymax)
            ax.set_xlabel("1Kb bins")
            title = "{} {}".format(samplekey.split("_")[1], chr)
            if dx:
                title += " ({})".format(dx)
            ax.set_title(title)

            # The final calls
            yy = .9
            abnormal = [x for x in events if x[-1]]
            if len(abnormal) > 5:
                yinterval = .02
                size = 10
            else:
                yinterval = .05
                size = 12
            for mean_cn, rr, event in events:
                if mean_cn > ymax:
                    continue
                ax.text(np.mean(rr), mean_cn + .2, mean_cn,
                        ha="center", bbox=props)
                if event is None:
                    continue
                ax.text(.5, yy, str(event).rsplit(" ", 1)[0],
                        color='r', ha="center",
                        transform=ax.transAxes, size=size)
                yy -= yinterval

        axs[0].set_ylabel("Copy number")
Exemplo n.º 5
0
    def plot(self, samplekey, chrs=allsomes, color=None, dx=None, ymax=8,
             ms=2, alpha=.7):

        import matplotlib.pyplot as plt
        from jcvi.utils.brewer2mpl import get_map

        props = dict(boxstyle='round', facecolor='wheat', alpha=0.2)

        if isinstance(chrs, str):
            chrs = [chrs]
        f, axs = plt.subplots(1, len(chrs), sharey=True)
        if not isinstance(axs, np.ndarray):
            axs = np.array([axs])
        plt.tight_layout()
        if color is None:
            color = choice(get_map('Set2', 'qualitative', 8).mpl_colors)

        for region, ax in zip(chrs, axs):
            chr, start, end = parse_region(region)
            X, Z, clen, events = self.run_one(samplekey, chr)
            ax.plot(X, ".", label="observations",
                    ms=ms, mfc=color, alpha=alpha)
            ax.plot(Z, "k.", label="hidden", ms=6)

            if start is None and end is None:
                ax.set_xlim(0, clen)
            else:
                ax.set_xlim(start / 1000, end / 1000)

            ax.set_ylim(0, ymax)
            ax.set_xlabel("1Kb bins")
            title = "{} {}".format(samplekey.split("_")[1], chr)
            if dx:
                title += " ({})".format(dx)
            ax.set_title(title)

            # The final calls
            yy = .9
            abnormal = [x for x in events if x[-1]]
            if len(abnormal) > 5:
                yinterval = .02
                size = 10
            else:
                yinterval = .05
                size = 12
            for mean_cn, rr, event in events:
                if mean_cn > ymax:
                    continue
                ax.text(np.mean(rr), mean_cn + .2, mean_cn,
                        ha="center", bbox=props)
                if event is None:
                    continue
                ax.text(.5, yy, str(event).rsplit(" ", 1)[0],
                        color='r', ha="center",
                        transform=ax.transAxes, size=size)
                yy -= yinterval

        axs[0].set_ylabel("Copy number")
Exemplo n.º 6
0
def prettyplot():
    # Get Set2 from ColorBrewer, a set of colors deemed colorblind-safe and
    # pleasant to look at by Drs. Cynthia Brewer and Mark Harrower of Pennsylvania
    # State University. These colors look lovely together, and are less
    # saturated than those colors in Set1. For more on ColorBrewer, see:
    set2 = get_map('Set2', 'qualitative', 8).mpl_colors
    set1 = get_map('Set1', 'qualitative', 9).mpl_colors

    reds = mpl.cm.Reds
    reds.set_bad('white')
    reds.set_under('white')

    blues_r = mpl.cm.Blues_r
    blues_r.set_bad('white')
    blues_r.set_under('white')

    # Need to 'reverse' red to blue so that blue=cold=small numbers,
    # and red=hot=large numbers with '_r' suffix
    blue_red = get_map('RdBu', 'diverging', 11, reverse=True).mpl_colormap
    green_purple = get_map('PRGn', 'diverging', 11).mpl_colormap
    red_purple = get_map('RdPu', 'sequential', 9).mpl_colormap

    return blues_r, reds, blue_red, set1, set2, green_purple, red_purple
Exemplo n.º 7
0
Arquivo: base.py Projeto: yangjl/jcvi
def prettyplot():
    # Get Set2 from ColorBrewer, a set of colors deemed colorblind-safe and
    # pleasant to look at by Drs. Cynthia Brewer and Mark Harrower of Pennsylvania
    # State University. These colors look lovely together, and are less
    # saturated than those colors in Set1. For more on ColorBrewer, see:
    set2 = get_map('Set2', 'qualitative', 8).mpl_colors
    set1 = get_map('Set1', 'qualitative', 9).mpl_colors

    reds = mpl.cm.Reds
    reds.set_bad('white')
    reds.set_under('white')

    blues_r = mpl.cm.Blues_r
    blues_r.set_bad('white')
    blues_r.set_under('white')

    # Need to 'reverse' red to blue so that blue=cold=small numbers,
    # and red=hot=large numbers with '_r' suffix
    blue_red = get_map('RdBu', 'Diverging', 11,
                                  reverse=True).mpl_colormap
    green_purple = get_map('PRGn', 'diverging', 11).mpl_colormap
    red_purple = get_map('RdPu', 'Sequential', 9).mpl_colormap

    return blues_r, reds, blue_red, set1, set2, green_purple, red_purple
Exemplo n.º 8
0
Arquivo: base.py Projeto: yangjl/jcvi
 def assign_colors(self):
     colorset = get_map('Set2', 'qualitative', len(self)).mpl_colors
     self.assign_array("color", colorset)
Exemplo n.º 9
0
Arquivo: base.py Projeto: yangjl/jcvi
 def diverge(self):
     colors = get_map(self.opts.diverge, 'diverging', 5).mpl_colors
     return colors[0], colors[-1]
Exemplo n.º 10
0
 def diverge(self):
     colors = get_map(self.opts.diverge, "diverging", 5).mpl_colors
     return colors[0], colors[-1]
Exemplo n.º 11
0
def set3_n(number=12):
    return get_map("Set3", "qualitative", number).hex_colors
Exemplo n.º 12
0
def set2_n(number=8):
    # Get Set2 from ColorBrewer, a set of colors deemed colorblind-safe and
    # pleasant to look at by Drs. Cynthia Brewer and Mark Harrower of Pennsylvania
    # State University. These colors look lovely together, and are less
    # saturated than those colors in Set1. For more on ColorBrewer, see:
    return get_map("Set2", "qualitative", number).hex_colors
Exemplo n.º 13
0
def set1_n(number=9):
    return get_map("Set1", "qualitative", number).hex_colors
Exemplo n.º 14
0
 def assign_colors(self):
     colorset = get_map('Set2', 'qualitative', 8).mpl_colors
     colorset = sample_N(colorset, len(self))
     self.assign_array("color", colorset)
Exemplo n.º 15
0
 def assign_colors(self):
     colorset = get_map('Set2', 'qualitative', len(self)).mpl_colors
     self.assign_array("color", colorset)
Exemplo n.º 16
0
 def assign_colors(self):
     colorset = get_map('Set2', 'qualitative', 8).mpl_colors
     colorset = sample_N(colorset, len(self))
     self.assign_array("color", colorset)