Exemplo n.º 1
0
def venn_diagram_5prime(labels_a, labels_b, labels_c, figure_options=None):
    # type: (Labels, Labels, Labels, FigureOptions) -> None

    # first, reduce each set to common genes
    list_labels_common_3prime = reduce_labels_to_genes_in_all(
        [labels_a, labels_b, labels_c])
    label_value_pair = numbers_for_3d_venn(*list_labels_common_3prime)

    fig, ax = plt.subplots()

    # venn3([set(get_set_gene_keys(labels)) for labels in list_labels_common_3prime],
    #       set_labels=[labels.name for labels in list_labels_common_3prime])

    # create equal sized circles
    v = venn3([1, 1, 1, 1, 1, 1, 1],
              set_labels=[labels.name for labels in list_labels_common_3prime])

    for key, value in label_value_pair.items():
        v.get_label_by_id(key).set_text(value)

    # Add title and annotation
    FigureOptions.set_properties_for_axis(ax, figure_options)

    if figure_options is not None and figure_options.save_fig is not None:
        plt.savefig(figure_options.save_fig, bbox_inches='tight')

    # Show it
    plt.show()
Exemplo n.º 2
0
def catplot(df, x, y, hue=None, kind="box", figure_options=None, **kwargs):
    # type: (pd.DataFrame, str, str, str, Union[str, None], FigureOptions, Dict[str, Any]) -> None
    sns_kwargs = get_value(kwargs, "sns_kwargs", dict())
    g = sns.catplot(x=x, y=y, data=df, kind=kind, hue=hue, legend=False, aspect=1.5, **sns_kwargs)

    if kind == "point":
        plt.setp(g.ax.lines, linewidth=1)  # set lw for all lines of g axes
        # plt.setp(g.ax.lines, markersize=0)  # set lw for all lines of g axes
    #
    # if fontsize:
    #     g.set_xlabels(x, fontsize=fontsize)
    #     g.set_ylabels(x, fontsize=fontsize)

    FigureOptions.set_properties_for_axis(g.axes[0][0], figure_options)
    legend = get_value(kwargs, "legend", "full")
    legend_loc = get_value(kwargs, "legend_loc", None)




    if hue is not None and legend:
        title = get_value(kwargs, "legend_title", None)
        if not legend_loc:
            plt.legend(loc='center left', bbox_to_anchor=(1.05, 0.5), title=title)
        else:
            plt.legend(loc=legend_loc)

    # plt.savefig(next_name(pd_work))
    save_figure(figure_options)
    plt.show()
Exemplo n.º 3
0
def scatterplot(df, x, y, hue=None, figure_options=None, **kwargs):
    # type: (pd.DataFrame, str, str, Union[str, None], FigureOptions, Dict[str, Any]) -> None

    sns_kwargs = get_value(kwargs, "sns_kwargs", dict())
    ax = get_value(kwargs, "ax", None)

    identity = get_value(kwargs, "identity", False)

    if not ax:
        _, ax = plt.subplots()

    g = sns.scatterplot(x=x, y=y, hue=hue, data=df, linewidth=0, **sns_kwargs)

    if identity:
        add_identity(ax, color="r", ls="--")

    FigureOptions.set_properties_for_axis(ax, figure_options)
    legend = get_value(kwargs, "legend", "full")
    legend_loc = get_value(kwargs, "legend_loc", None)
    if hue is not None and legend:
        title = get_value(kwargs, "legend_title", None)
        if not legend_loc:
            plt.legend(loc='center left', bbox_to_anchor=(1.05, 0.5), title=title)
        else:
            plt.legend(loc=legend_loc)


    save_figure(figure_options)
    plt.show()
Exemplo n.º 4
0
def plot_catplot(df, column_x, column_y, figure_options=None):
    _, ax = plt.subplots()
    sns.catplot(x=column_x, y=column_y, kind="bar", data=df)

    FigureOptions.set_properties_for_axis(ax, figure_options)
    if figure_options is not None and figure_options.save_fig is not None:
        plt.savefig(figure_options.save_fig, bbox_index="tight")

    plt.show()
Exemplo n.º 5
0
def distplot(df, x, figure_options=None, **kwargs):
    _, ax = plt.subplots()

    sns_kwargs = get_value(kwargs, "sns_kwargs", dict())
    if "kde" not in sns_kwargs:
        sns_kwargs["kde"] = True

    g = sns.distplot(df[x], bins=50, **sns_kwargs)

    FigureOptions.set_properties_for_axis(g.axes, figure_options)
    save_figure(figure_options)
    plt.show()
Exemplo n.º 6
0
def barplot(df, x, y, hue, figure_options=None, **kwargs):
    sns_kwargs = get_value(kwargs, "sns_kwargs", dict())
    ax = get_value(kwargs, "ax", None)

    g = sns.barplot(x=x, y=y, data=df, hue=hue,  ax=ax, **sns_kwargs)

    if hue is not None:
        plt.legend(loc='center left', bbox_to_anchor=(1.05, 0.5))

    FigureOptions.set_properties_for_axis(g, figure_options)
    plt.tight_layout()
    save_figure(figure_options)
    # plt.tight_layout(rect=[-0.3,0,1,1.2])
    plt.show()
Exemplo n.º 7
0
def kdeplot(df, x, y, hue=None, figure_options=None, **kwargs):
    # type: (pd.DataFrame, str, str, Union[str, None], FigureOptions, Dict[str, Any]) -> None
    sns_kwargs = get_value(kwargs, "sns_kwargs", dict())

    _, ax = plt.subplots()
    y_df = None if y is None else df[y]

    g = sns.kdeplot(df[x], y_df, legend=False, **sns_kwargs)

    if hue is not None:
        plt.legend(loc='center left', bbox_to_anchor=(1.05, 0.5))

    FigureOptions.set_properties_for_axis(ax, figure_options)
    save_figure(figure_options)
    plt.show()
Exemplo n.º 8
0
def scatter(df, column_x, column_y, figure_options=None, **kwargs):
    # type: (pd.DataFrame, str, str, FigureOptions, Dict[str, Any]) -> None

    column_z = get_value(kwargs, "column_z", None)
    identity = get_value(kwargs, "identity", False)
    hue = df[column_z] if column_z is not None else None

    _, ax = plt.subplots()


    sns.jointplot(df[column_x], df[column_y], kind="scatter", alpha=0.3, s=10, linewidth=0)
    #sns.scatterplot(df[column_x], df[column_y], hue=hue, alpha=0.3, s=10, linewidth=0)
    if identity:
        add_identity(ax, color="r", ls="--")

    FigureOptions.set_properties_for_axis(ax, figure_options)
    if figure_options is not None and figure_options.save_fig is not None:
        plt.savefig(figure_options.save_fig, bbox_index="tight")

    plt.show()
Exemplo n.º 9
0
def plot_hist_by_group(df_data,
                       column_x,
                       column_group=None,
                       figure_options=None,
                       **kwargs):
    # type: (pd.DataFrame, str, Union[str, None], FigureOptions, Dict[str, Any]) -> None

    bins = get_value(kwargs, "bins", 10)

    _, ax = plt.subplots()

    cumulative = get_value(kwargs, "cumulative", False)
    shade = False if cumulative else True
    cut = [min(df_data[column_x]), max(df_data[column_x])]
    if column_group is not None:
        for name, df_group in df_data.groupby(column_group):
            sns.distplot(df_group[column_x],
                         hist=False,
                         kde_kws={
                             "shade": shade,
                             "cumulative": cumulative
                         },
                         label=name)
    else:
        # sns.distplot(df_data[column_x], hist=True, kde_kws={"shade": shade, "cumulative": cumulative, "clip": cut})
        sns.distplot(df_data[column_x],
                     bins=bins,
                     hist=True,
                     kde=False,
                     hist_kws={"edgecolor": "black"})

    FigureOptions.set_properties_for_axis(ax, figure_options)

    # plt.xlim([min(df_data[column_x]), max(df_data[column_x])])
    if figure_options is not None and figure_options.save_fig is not None:
        plt.savefig(figure_options.save_fig, bbox_index="tight")

    plt.show()
Exemplo n.º 10
0
def lmplot(df, x, y, hue=None, figure_options=None, **kwargs):
    # type: (pd.DataFrame, str, str, Union[str, None], FigureOptions, Dict[str, Any]) -> None

    sns_kwargs = get_value(kwargs, "sns_kwargs", dict())
    if "aspect" not in sns_kwargs:
        sns_kwargs["aspect"] = 2

    g = sns.lmplot(x=x, y=y, hue=hue, data=df, legend=False, **sns_kwargs)

    FigureOptions.set_properties_for_axis(g.axes[0][0], figure_options)
    legend = get_value(kwargs, "legend", "full")
    legend_loc = get_value(kwargs, "legend_loc", None)
    if hue is not None and legend:
        title = get_value(kwargs, "legend_title", None)
        if not legend_loc:
            g.axes[0][0].legend(loc='center left', bbox_to_anchor=(1.05, 0.5), title=title)
        else:
            g.axes[0][0].legend(loc=legend_loc)

    save_figure(figure_options, fig=g.fig)
    plt.subplots_adjust(right=1)
    plt.show()
    return g
Exemplo n.º 11
0
def lineplot(df, x, y, hue=None, figure_options=None, **kwargs):
    # type: (pd.DataFrame, str, str, Union[str, None], FigureOptions, Dict[str, Any]) -> None

    sns_kwargs = get_value(kwargs, "sns_kwargs", dict())
    ax = get_value(kwargs, "ax", None)
    show = get_value(kwargs, "show", ax is None)
    legend = get_value(kwargs, "legend", "full")
    legend_loc = get_value(kwargs, "legend_loc", None)
    legend_ncol = get_value(kwargs, "legend_ncol", 1)

    identity = get_value(kwargs, "identity", False)

    if not ax:
        fig, ax = plt.subplots()
    else:
        fig = ax.get_figure()

    g = sns.lineplot(x=x, y=y, hue=hue, data=df, ax=ax, legend=legend, **sns_kwargs)

    if identity:
        add_identity(ax, color="r", ls="--")

    FigureOptions.set_properties_for_axis(ax, figure_options)
    if hue is not None and legend:
        title = get_value(kwargs, "legend_title", None)
        if not legend_loc:
            plt.legend(loc='center left', bbox_to_anchor=(1.05, 0.5), title=title, ncol=legend_ncol)
        else:
            plt.legend(loc=legend_loc, ncol=legend_ncol, title=title)
        if title is not None and len(title)  == 0:
            handles, labels = ax.get_legend_handles_labels()
            ax.legend(handles=handles[1:], labels=labels[1:], ncol=legend_ncol)

    if show:
        save_figure(figure_options, fig)
        plt.show()
def main(env, args):
    # type: (Environment, argparse.Namespace) -> None
    df = pd.read_csv(args.pf_data)
    df["chunk-size"] /= 1000

    import matplotlib.pyplot as plt

    fig, ax = plt.subplots()



    sns.lineplot(df[df["Tool"] == "SBSP"], "chunk-size", "percentage-common-3prime-and-5prime-from-common-3prime",
                 hue="Genome",
                 sns_kwargs={"palette": CM.get_map("verified"), "linestyle": "dashed"},
                 ax=ax,
                 legend=False,
                 figure_options=FigureOptions(
                     xlabel="Chunk size (mb)",
                     ylabel="Accuracy",
                     ylim=[74, 101],
                     save_fig=next_name(env["pd-work"])
                 ))

    for l in ax.lines:
        l.set_linestyle("--")

    sns.lineplot(df[df["Tool"] == "GMS2"], "chunk-size", "percentage-common-3prime-and-5prime-from-common-3prime",
                 hue="Genome",
                 sns_kwargs={"palette": CM.get_map("verified")},
                 legend_loc="best",
                 legend_ncol=2,
                 ax=ax)




    if args.with_mgm:
        y_max = ax.get_ylim()[1]
        ax.axvline(50, 0, y_max, color="grey", linestyle="dashed")
        ax.axhline(74, 5, 49, color="grey", linestyle="dashed")
        ax.annotate("MGM", (5, 72))

    if "MGM" in set(df["Tool"]):
        sns.lineplot(df[df["Tool"] == "MGM"], "chunk-size", "percentage-common-3prime-and-5prime-from-common-3prime",
                     hue="Genome",
                     sns_kwargs={"palette": CM.get_map("verified"), "linestyle": "-."},
                     ax=ax,
                     legend=False)

    for l in ax.lines[len(ax.lines)-5:]:
        l.set_linestyle(":")

    fo = FigureOptions(
                     xlabel="Chunk size (mb)",
                     ylabel="Accuracy",
                     ylim=[74,101],
                     save_fig=next_name(env["pd-work"])
                 )
    FigureOptions.set_properties_for_axis(ax, fo)
    plt.savefig(fo.save_fig)
    plt.show()