squidpy icon indicating copy to clipboard operation
squidpy copied to clipboard

Calculate Moran's I statistic using `obsm` or `obs`

Open alam-shahul opened this issue 2 years ago • 3 comments

Description

Calculate Moran's I statistic using obsm or obs instead of just columns in var ...

I was wondering if it would be possible to add this functionality to sq.gr.spatial_autocorr()? I tried using sq.pl.extract(dataset, "X") to move dataset.obsm["X"] into dataset.obs, but it seems the genes parameter of sq.gr.spatial_autocorr() is only supposed to be used for columns in dataset.var. Would it be possible to expand this function for this use case?

alam-shahul avatar Mar 21 '22 16:03 alam-shahul

As a followup, I managed to accomplish what I wanted using:

from scanpy.metrics._morans_i import morans_i

morans_i(dataset.obsp["adjacency_matrix"], dataset.obsm["X"].T)

So I guess I was just wondering if there was a nice way this could be integrated into Squidpy.

alam-shahul avatar Mar 21 '22 16:03 alam-shahul

Are you looking for more functionality than you'd get from:

sc.metrics.morans_i(dataset, use_graph="adjacency_matrix", obsm="X")

ivirshup avatar Mar 23 '22 10:03 ivirshup

@alam-shahul I'd check out @ivirshup suggestion, calling scanpy directly. We provide a parallelized version but it'd be a bit of work to allow for non-genes to be handled. let us know if it works

giovp avatar Mar 23 '22 18:03 giovp

closing

giovp avatar Oct 18 '22 12:10 giovp