Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bimodality index to doublet detection #307

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pegasus/tools/doublet_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ def _calc_expected_doublet_rate(ncells):
return expected_rate


def _calc_bc_sarle(scores):
""" Sarle's Biomodality Coefficient for finite samples: https://rdrr.io/github/microbiome/microbiome/man/bimodality_sarle.html
"""
from scipy.stats import skew, kurtosis
g = skew(scores)
k = kurtosis(scores)
n = scores.size
return (g ** 2 + 1.0) / (k + 3 * (n - 1) ** 2 / (n - 2) / (n - 3))


@timer(logger=logger)
def _run_scrublet(
data: Union[MultimodalData, UnimodalData],
Expand Down Expand Up @@ -429,7 +439,8 @@ def _run_scrublet(

neo_dbl_rate = data.obs['pred_dbl'].sum() / data.shape[0]
neo_sim_dbl_rate = (sim_scores > threshold).sum() / sim_scores.size
logger.info(f"Sample {name}: doublet threshold = {threshold:.4f}; total cells = {data.shape[0]}; neotypic doublet rate in simulation = {neo_sim_dbl_rate:.2%}; neotypic doublet rate = {neo_dbl_rate:.2%}.")

logger.info(f"Sample {name}: doublet threshold = {threshold:.4f}; total cells = {data.shape[0]}; neotypic doublet rate in simulation = {neo_sim_dbl_rate:.2%}; bimodality coefficient = {_calc_bc_sarle(sim_scores_log):.4f}; neotypic doublet rate = {neo_dbl_rate:.2%}.")

fig = None
if plot_hist:
Expand Down
Loading