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.11% 78.59% +1.47%
==========================================
Files 63 63
Lines 9418 9459 +41
Branches 1585 1585
==========================================
+ Hits 7263 7434 +171
+ Misses 1554 1425 -129
+ Partials 601 600 -1
🚀 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:
|
|
I will clean up the docstrings to have a dropdown per flavour so we get rid of this mess and will add the AutoK function in a separate PR. But still wanted to ask for a review from you @Intron7 |
|
@shashkat , thanks a lot for the PR I hope you don't mind my commits directly without asking but wdyt? also you mentioned spatial_neighbours didn't do something as it should like reusing the |
|
Hi @selmanozleyen , your welcome! Yeah no problem at all. I went through your changes and they look good to me. Just one point: Thanks a lot for reviewing the code! |

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