Initial framework of the niche refactor - #1245
Open
shashkat wants to merge 25 commits into
Open
Conversation
…late_niche() so that writing test case for sdata is possible
for more information, see https://pre-commit.ci
…ew implementation has differently named column
for more information, see https://pre-commit.ci
Tests in test_niche.py involving dummy_adata fail with scanpy<1.12.1 because of a change in handling of small edge weights by sc.pp.neighbors (scverse#4031). Updated the values in tests to match the expected values with scanpy>=1.12.1
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1245 +/- ##
==========================================
+ Coverage 77.24% 78.53% +1.29%
==========================================
Files 63 63
Lines 9378 9491 +113
Branches 1579 1589 +10
==========================================
+ Hits 7244 7454 +210
+ Misses 1532 1429 -103
- Partials 602 608 +6
🚀 New features to boost your workflow:
|
…late_niche_spatialleiden
…patialleiden with library_key not None
for more information, see https://pre-commit.ci
shashkat
marked this pull request as ready for review
July 27, 2026 05:24
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.
Description
Niche refactor improving the current implementation giving the user facing functions a more explicit API, more flexibility through embedder and clusterer classes and possibility of using combinations of them using
calculate_niche_custom. Postprocessor classes allow more organized and flexible postprocessing actions like masking and min_niche_size filtering of niches.The core idea is similar to the spatial_neighbors refactor in #1147 and builds on top of the relatively smaller fix in #1229.
The below graph demonstrates the code flow planned (read children of a node from left to right). This allows usage of different combinations of embeddings and clusterings to obtain niches, and also exposing easy to use and explicit user facing functions for the different flavors. Brown nodes are user-facing functions.

How has this been tested?
Keeping the API of function
calculate_nichesame, for i) backward compatibility and ii) being able to validate results being same before and after refactor for some test cases that I wrote for the purpose of this refactor, for the different flavors. Though later on, I thinkcalculate_nicheshould be deprecated as its not clear how arguments of it interact with different values offlavorargument.Closes
Closes #1192, where this was initially discussed