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

Bug fix for scanpy.tl.score_genes #3167

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 4 additions & 2 deletions src/scanpy/tools/_score_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ def _score_genes_bins(
# Sometimes (and I don’t know how) missing data may be there, with NaNs for missing entries
obs_avg = obs_avg[np.isfinite(obs_avg)]

n_items = int(np.round(len(obs_avg) / (n_bins - 1)))
obs_cut = obs_avg.rank(method="min") // n_items
obs_avg.sort_values(ascending=True, inplace=True)
n_items = int(np.ceil(len(obs_avg) / (n_bins)))
rank = np.repeat(np.arange(n_bins), n_items)[: len(obs_avg)]
obs_cut = pd.Series(rank, index=obs_avg.index)
keep_ctrl_in_obs_cut = False if ctrl_as_ref else obs_cut.index.isin(gene_list)

# now pick `ctrl_size` genes from every cut
Expand Down
Loading