Open Lem-P opened 5 months ago
can you check whether you have nan in adata.obsm["spatial"]
Maybe a noob question, but how? I have tried with
df = pd.DataFrame(adata.obsm["spatial"])
nan_count = df.isna().sum()
print(nan_count)
and got 0 1 1 1 dtype: int64
But not sure it is the right method
if np.isnan(adata.obsm["spatial"]).sum()
return > 1 then you have nan and it's something in your data and possibly not related to squidpy
np.isnan(adata.obsm["spatial"]).sum()
gives me 2 as output.
How can I found out where it's coming from? (the data comes from spaceranger-2.0.1)
How can I correct the dataset?
unfortunately I don't know, an option is also to just filter out cells that are like that, and also check in original raw data where that issue might arise.
After some testing, it is the sq.read.visium()
function that create the issue.
If I create my AnnData with sc.read_visium()
function, there are no NaN value in adata.obsm["spatial"]
and I can go on with the rest of the analysis.
So there is indeed a bug with Squidpy, the workaround is to use Scanpy to import the Visium data
This can be because of this line: https://github.com/scverse/squidpy/blob/main/src/squidpy/read/_read.py#L94
@Lem-P do both of the same adata
objects (from sq.read.visium()
and sc.read_visium()
have the same number of cells? The SquidPy function will keep all the cells in the adata
and put NaNs for the coords if they are missing.
No, I have the same number of observations/cells and variables/genes in both objects.
But I found the problematic row.
In the object made with Scanpy : array([ 7335, 12140])
In the object made with Squidpy : array([nan, nan])
Would the space before the first value create the issue? Where is it coming from? Why would spaceranger suddenly add a space before a value?
ok, it seems the issue is then due to the visium reader, also reported in #746 , it has to do with space ranger versions I'm afraid. I won't have time to look at it soon but @Lem-P I would take a look at @scverse/spatialdata-io for a visium reader that should support all spaceranger versions
I also met this error, even if I use the latest squidpy (1.5.0) and I finally find the reason. header=1
should be changed to header=0
. Perhaps It's a typo of squidpy. https://github.com/scverse/squidpy/issues/746
yes this I think it's due to the different specifications. Unfortuantely we only maintain readers in spatialdata-io so I would suggest to take a look at that. https://spatialdata.scverse.org/projects/io/en/latest/index.html
Hi, I am trying to import a dataset from 10X Visium H&E
I am importing the dataset with:
Then pre-processing:
Then to calculate the image_features, I create my ImageContainer (not clear to me if I can do it before filtering or not).
No problem until that point (except a lot of warnings about deprecated parameter in pandas)
I then do:
but get this error:
Traceback
If trying to do neighborhood enrichment with sq.gr.spatial_neighbors(adata)
I got this ValueError: Input X contains NaN.
Version
squidpy==1.4.1