Ejemplo n.º 1
0
    def plot_sssh(
        self,
        feature_name: str,
        feature_data: pandas.DataFrame,
        top_feature_values: list,
        stability_points: tuple = None,
        ax: plt.axes = None,
        color: str = 'YlGnBu',
        stable_point: bool = False,
        break_point: bool = False,
    ) -> None:

        feature_data = feature_data.loc[
            feature_data['feature_value'].isin(top_feature_values), :
        ]

        feature_data = feature_data.assign(
            feature_value=feature_data['feature_value'].astype(str)
        )

        feature_values = feature_data.feature_value.unique()
        palette = sns.color_palette(
            color, n_colors=self.top_feature_values
        )[:len(feature_values)]

        p2 = sns.lineplot(
            data=feature_data, x='read', y='sssh', hue='feature_value',
            ax=ax, ci=None, estimator=None, palette=palette,
            hue_order=[str(v) for v in top_feature_values]
        )
        if stability_points is not None and stable_point:
            ax.axvline(
                x=stability_points[0], linewidth=1, linestyle='--', color='black'
            )
        if stability_points is not None and break_point:
            if stability_points[1] is not None:
                ax.axvline(
                    x=stability_points[1], linewidth=1, linestyle='-', color='black'
                )

        legend = ax.legend()
        legend.texts[0].set_text(feature_name)

        # Legend and labels
        p2.tick_params(labelsize=6)
        p2.set_xlabel('\nReads', fontsize=9)
        p2.set_ylabel('Sum of ranked sum of shared hashes\n', fontsize=9)
Ejemplo n.º 2
0
def dist_attr(ax: plt.axes = None,
              ds: loompy.LoomConnection = None,
              out_file: str = None,
              attr: str = None,
              plot_title: str = None,
              line: float = None):

    if ax is None:
        fig, ax = plt.subplots(figsize=(6, 4))
    if attr in ds.ca:
        ax.hist(ds.ca[attr], bins=100)
        ax.set_xlim(np.amin(ds.ca[attr]), np.amax(ds.ca[attr]))
        if line is not None:
            ax.axvline(x=line, c='r')
        if plot_title is not None:
            ax.set_title(plot_title)
        if out_file is not None:
            fig.savefig(out_file, dpi=144)
        return (ax)
Ejemplo n.º 3
0
def fake_doublets_dist(ax: plt.axes = None,
                       doublet_score_A: np.array = None,
                       logprob: np.array = None,
                       xx: np.array = None,
                       score1: float = 1,
                       score2: float = 1,
                       score: float = 1,
                       out_file: str = None) -> None:
    # fig, ax = plt.subplots(figsize=(12, 12))
    if ax is None:
        ax = plt.gca()
    ax.fill_between(xx.T[0], np.exp(logprob), alpha=0.5)
    ax.plot(doublet_score_A,
            np.full_like(doublet_score_A, -0.01),
            '|k',
            markeredgewidth=1)
    ax.set_ylim(-0.02, 5)

    ax.set_title(f'Fake Doublets distribution (Selected TH: {score})')
    if score1 != 1:
        ax.axvline(x=score1, c='r')
    if score2 != 1:
        ax.axvline(x=score2, linestyle='--', c='r')
    if score != 1:
        ax.axvline(x=score, linestyle=':', c='r')
    ax.set_ylabel('# cells')
    ax.set_xlabel('DoubletFinder score')
    hd = ax.hist(doublet_score_A, bins=30, density=True)
    if out_file is not None:
        plt.savefig(out_file, dpi=144)
    return (hd)
Ejemplo n.º 4
0
def plot_date_randomisation(ax: plt.axes,
                            replicates: np.array or list,
                            rate: float,
                            log10: bool = True) -> plt.axes:
    """ Plot distribution of substitution rates for date randomisation test

    :param ax: axes object to plot the date randomisation
    :param replicates: list of replicate substitution rate estimates
    :param rate: true rate estimate vertical line for evaluation
    :param log10: plot log10 of substitution rates on horizontal axis

    :returns axes object

    """

    if log10:
        replicates = np.log10(replicates)

    with plt.style.context('seaborn-colorblind'):
        ax.hist(x=replicates, color='gray')
        ax.axvline(x=rate, color='r')

    return ax