scverse / squidpy

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

neighborhood enrichment z scores #501

Closed vicmuliadi closed 2 years ago

vicmuliadi commented 2 years ago

Hello,

Thank you for developing this nice tool! I've been using it to run some neighborhood enrichment analysis, and I noticed that the enrichment z score between pairs of the same cluster types is not always the maximum score. Is this possible? And what would be the best way to interpret these results?

Thank you!

MxMstrmn commented 2 years ago

Hey @vicmuliadi,

cool that you find squidpy useful! Do you mind providing a minimal code example that shows what you are doing specifically?

vicmuliadi commented 2 years ago

Thanks for answering @MxMstrmn! Here's a bit of the code I'm using (I'm trying to calculate the neighborhood enrichment scores between different genes in an in situ sequencing dataset):

sq.gr.spatial_neighbors(adata, coord_type = "generic", n_neighs = 10, delaunay = False) sq.gr.nhood_enrichment(adata, cluster_key="gene_names") sq.pl.nhood_enrichment(adata, cluster_key="gene_names")

and here is how the resulting graph looks like: bc8 nhood enrichment

From my own understanding one would expect the enrichment scores between pairs of the same genes (i.e. the diagonal line through the matrix) to be the maximum possible score, but this is not always the case here. Could it be due to the input data itself (e.g. differences in signal density of the genes)?

MxMstrmn commented 2 years ago

Hi @vicmuliadi, thanks for providing this example, that already helped a lot understanding your problem. Please have a look at this part of the squidpy tutorials. The enrichment scores tell you something about the spatial co-occurence of clusters and therefore clusters of the same type do not have to occur together, but can be distributed across the whole tissue.

vicmuliadi commented 2 years ago

Ah that makes sense, I understand now. Thank you!