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

Skip labels before loop #394

Merged
merged 6 commits into from
Aug 7, 2024
Merged

Skip labels before loop #394

merged 6 commits into from
Aug 7, 2024

Conversation

johnarevalo
Copy link
Contributor

When there are many labels to be skipped, having this validation inside the for loop makes kbet computation significantly slow:

scib/scib/metrics/kbet.py

Lines 114 to 122 in ed3e284

# subset by label
adata_sub = adata_tmp[adata_tmp.obs[label_key] == clus, :].copy()
# check if neighborhood size too small or only one batch in subset
if np.logical_or(
adata_sub.n_obs < 10, len(adata_sub.obs[batch_key].cat.categories) == 1
):
print(f"{clus} consists of a single batch or is too small. Skip.")
score = np.nan

This PR extract such checks outside the for loop to do them in a single pass.

Copy link

codecov bot commented Aug 7, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 54.63%. Comparing base (9271d92) to head (7d9e357).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
scib/metrics/kbet.py 80.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #394      +/-   ##
==========================================
+ Coverage   54.60%   54.63%   +0.02%     
==========================================
  Files          22       22              
  Lines        1683     1684       +1     
==========================================
+ Hits          919      920       +1     
  Misses        764      764              
Flag Coverage Δ
unittests 54.63% <80.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
scib/metrics/kbet.py 72.22% <80.00%> (+0.25%) ⬆️

@mumichae mumichae merged commit 5547cd1 into theislab:main Aug 7, 2024
11 checks passed
@adamgayoso
Copy link
Contributor

@johnarevalo would you be willing to make a similar PR to our scib-metrics package here? https://github.com/YosefLab/scib-metrics

@johnarevalo
Copy link
Contributor Author

Sure! I'll port these changes to scib-metrics and tag you when the PR is ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants