Repository navigation
fix: handle zero counts in Pearson residual normalization - #4404
Open
HamzaAhmed-bio wants to merge 2 commits into
Open
HamzaAhmed-bio wants to merge 2 commits into
HamzaAhmed-bio wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4404 +/- ##
==========================================
+ Coverage 83.78% 83.80% +0.02%
==========================================
Files 134 134
Lines 12691 12691
==========================================
+ Hits 10633 10636 +3
+ Misses 2058 2055 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pearson residual normalization currently produces
NaNvalues for zero-count genes or cells because their fitted mean and variance are zero. An entirely zero matrix also divides by zero when constructing the fitted means. These values can make downstream PCA fail after subsetting the gene matrix.This change assigns zero residuals by convention to zero-count cells/genes, including an all-zero input, while leaving positive-mean entries on the existing negative-binomial/Poisson formula.
np.divide(..., where=mu != 0)avoids the invalid division rather than replacing arbitrary NaNs afterward. The docstring describes the convention.invalid value encountered in dividewhen runningpp.normalize_pearson_residuals#2496tests/test_normalization.py: 382 passed, 2 skipped on Windows with Python 3.13.16, NumPy 2.5.3, and AnnData 0.13.4.AI assistance: implementation, tests, and this description were prepared with OpenAI Codex. No independent human review is claimed.