Initial framework of the niche refactor - #1245
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.68% +1.44%
==========================================
Files 63 63
Lines 9378 9491 +113
Branches 1579 1589 +10
==========================================
+ Hits 7244 7468 +224
+ Misses 1532 1415 -117
- 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
|
This is ready for review @selmanozleyen @grst Some important points:
|
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