scverse / squidpy

Spatial Single Cell Analysis in Python
https://squidpy.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
434 stars 79 forks source link

Counting by edges inflating z-scores for high number of n_rings. #87

Closed ilibarra closed 3 years ago

ilibarra commented 4 years ago

The function permtest_leiden_pairs works well for nodes so far. However, it reports inflated number of observed edges between leiden pairs when n_rings is 2 or higher. This can be visually inspected in visium cases where the top selected leiden pairs actually separated by many nodes.

spatial_connectivity(adata, n_rings=2)
permtest_leiden_pairs(adata, count_option='edges',
                              print_log_each=25, n_permutations=n_permutations)

I can attach images for this issue. It needs to be however tackled to allow the mode edges to be accepted.

giovp commented 4 years ago

right, this is the notebook we should look at yes https://github.com/theislab/spatial-tools/blob/master/notebooks/permutation_test.ipynb ? what is node dev again?

giovp commented 4 years ago

@ilibarra do you mind explaining again whats' node dev? I don't remember it sorry

ilibarra commented 4 years ago

@giovp there are currently three implementations, nodes, edges, and nodes-dev

The goal is to keep debugging nodes-dev and eventually rename it nodes.

giovp commented 4 years ago

ok great, thank you for the explanation! Let me know if I can help with debugging etc.

ilibarra commented 4 years ago

I was wondering whether I can convert the adata, conn graph and visium viz to a down-scaled version of those? For example: this one here is ~2700x2700. If I can down-scale it somehow to 50,50 and 100,100 I could troubleshoot issue I am getting faster (same pattern, much less edges). image

Thank you,

giovp commented 4 years ago

Would something like this works for your purpose?

adata_subset = adata[adata.obsm["spatial"][:, 1] < adata.obsm["spatial"][:, 1].mean()]
sc.pl.spatial(adata_subset, img_key="hires", color=["leiden"])

image

adata is the same as in your case, so standard preprocessing and then leiden

ilibarra commented 3 years ago

Hey,

I have tested in the big versus small example for the same case, but unfortunately the pattern is not maintained i.e. the z-score for edges returns to negative values when doing this (bottom case).

I think I should maintain the big example to reproduce this case (top case with high, unexpected z-score). Still wondering how to visualize this. Is there a visualization package suggestion for the connectivity graphs? e.g. a networkx.

image

giovp commented 3 years ago

closed with #140