-
Notifications
You must be signed in to change notification settings - Fork 774
feat(preprocessing): add optimal shifted CLR (PFlog) normalization #4160
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
Open
rwbaber
wants to merge
25
commits into
scverse:main
Choose a base branch
from
rwbaber:feature/normalize_clr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6c253cb
feat(preprocessing): add optimal shifted CLR (PFlog1pPF) normalization
rwbaber eec2659
docs: update release notes fragment with PR number
rwbaber 32fb68b
test: register normalize_clr in copy_sigs signature conventions
rwbaber 6bd44b0
refactor(pp): unify normalize_clr math variables and clean up bibliog…
rwbaber dd9aca0
docs: polish normalize_clr docstring wording
rwbaber f652a7e
refactor(pp): finalize normalize_clr API per review
rwbaber 6eee954
feat(pp): support dask arrays in normalize_clr
rwbaber b284927
test(pp): cover alpha="auto" zero-mean overdispersion error
rwbaber f344a8e
Merge branch 'main' into feature/normalize_clr
ilan-gold 7cf8a5b
Merge branch 'main' into feature/normalize_clr
Intron7 4212ccf
Merge remote-tracking branch 'upstream/main' into feature/normalize_clr
rwbaber 3549f19
Add sparse PFlog normalization and PCA support
rwbaber 1438bf9
Merge branch 'main' into feature/normalize_clr
ilan-gold 4b3321f
Merge branch 'main' into feature/normalize_clr
rwbaber 2cac9ef
Merge remote-tracking branch 'origin/feature/normalize_clr' into feat…
rwbaber 30a7f4f
Refine PFlog metadata and Dask target handling
rwbaber 3fd7086
Fix stale AnnData concatenation tutorial link
rwbaber a1f1acb
Merge branch 'main' into feature/normalize_clr
rwbaber d3c6b73
Merge branch 'main' into feature/normalize_clr
rwbaber dff3612
Merge branch 'main' into feature/normalize_clr
rwbaber 4538e36
Merge branch 'main' into feature/normalize_clr
rwbaber 96c4a8b
Merge upstream/main into feature/normalize_clr
rwbaber 5110b39
refactor(preprocessing): simplify normalize_clr to dense PFlog
rwbaber 2abb963
fix(preprocessing): relax CLR doctest tolerance
rwbaber e7e0560
Merge branch 'main' into feature/normalize_clr
rwbaber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add {func}`scanpy.pp.normalize_clr` for PFlog shifted centered log-ratio normalization, a variance-stabilizing, depth-invariant and rank-preserving count transform {cite:p}`Booeshaghi2022`. By default, it estimates negative-binomial overdispersion and uses the Anscombe pseudocount. The complete centered result is stored in `X` or the selected layer. Because CLR centering generally maps zeros to non-zero values, the output is dense. {smaller}`R Baber` |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to compute this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the subsequent conditional (
if denominator == 0.0) and type cast (alpha = float(numerator / denominator)) need concrete scalar values at that point, not lazy Dask scalar objects.I ran a quick test, and it looks like Dask can actually evaluate scalar truthiness and float conversion implicitly without throwing an error, but it does so sequentially for each line. This triggers separate computations and duplicates the upstream work.
Calling
dask.compute(numerator, denominator)explicitly together merges both reductions into a single optimized pass. And this doesn't materialize the count matrix, it only executes the reduction graph down to the two final scalar sums.