-
Notifications
You must be signed in to change notification settings - Fork 699
feat: add distances parameter to sc.pp.neighbors
#3627
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
Conversation
… on how to integrate the two
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.
looks good except for the metrics changes being here instead of remaining in their own PR 😉
It also looks like some code is copied. Please check if you can introduce a helper function for everything after if method == "umap":, looks like most of that is identical to what’s in def neighbors. But if it’s too complicated or different, don’t do it!
Please also (after removing the metrics tests from this PR) add tests to check that passing distances results in the same stuff being added to adata as not doing it. Something like
adata_n = ...
adata_d = adata_n.copy()
sc.pp.neighbors(adata_n)
sc.pp.neighbors(adata_d, distances=adata_n.obsp["distances"])
# for all the parts that should be there:
np.testing.assert_almost_equal(...)
…
# for all the parts that can’t be derived from distances
assert "somekey" in adata_n.…
assert "somekey" not in adata_d.…
flying-sheep
left a comment
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.
looks good! please add a release note by running hatch run towncrier:create 3627.feature.md and editing that (don’t forget to add your name as in the other release note fragments)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3627 +/- ##
==========================================
+ Coverage 77.13% 78.16% +1.03%
==========================================
Files 117 117
Lines 12558 12586 +28
==========================================
+ Hits 9686 9838 +152
+ Misses 2872 2748 -124
Flags with carried forward coverage won't be shown. Click here to find out more.
|
distances parameter to sc.pp.neighbors
Adding a function,
neighbors_from_distance, that allows users to compute connectivities and distances directly from precomputed distance matrix. Might be useful where distances are generated externally, and we want to plug them into the standard scanpy graph-based pipeline without recomputing neighbors.This function should support the following: