bugfix in _calculate_neighborhood_profile in gr/_niche.py#1229
Open
shashkat wants to merge 1 commit into
Open
Conversation
…te_neighborhood_profile
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1229 +/- ##
==========================================
+ Coverage 76.81% 76.84% +0.03%
==========================================
Files 63 63
Lines 9267 9273 +6
Branches 1565 1569 +4
==========================================
+ Hits 7118 7126 +8
+ Misses 1547 1543 -4
- Partials 602 604 +2
🚀 New features to boost your workflow:
|
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
I am currently working on refactoring the niche code and API to make more modular similar to how it was done for graph construction strategies in #1147 and discussed in #1192. However, before that, in a separate, smaller PR, I wanted to make aware of a bug in the niche code, and fix it. This is that PR.
The bug was in the function
_calculate_neighborhood_profile()in gr/_niche.py. This is called whencalculate_niche()is called withflavor = 'neighborhood', inside_get_nhood_profile_niches(). The goal of_calculate_neighborhood_profile()is to get a dataframe of shapenum_cells x num_categories(categories could be something like celltype), where each entry stores the number of neighbors of a cell of a particular category. However, it wasn't working correctly when different cells had different number of neighbors. I believe it was written to be meant for grid-based data only.Now, it handles correctly the case when cells have different number of neighbors.
How has this been tested?
I created a new dummy adata object (
dummy_adata2intests/conftest.py) with explicitly defined locations of the cells, not necessarily organized in a grid. Then, I determined how the neighborhood profile for this object would look like and wrote a test function accordingly intests/graph/test_niche.pycalledtest_calculate_neighborhood_profile(). It failed with the original version of_calculate_neighborhood_profile()due to incorrect values and passed with the new version.Other points