pachterlab / SpatialFeatureExperiment

Extension of SpatialExperiment with sf
https://pachterlab.github.io/SpatialFeatureExperiment
Artistic License 2.0
43 stars 7 forks source link

`read10xVisiumSFE()` error when `data = "filtered"` for `style` arg #13

Closed alikhuseynov closed 1 year ago

alikhuseynov commented 1 year ago
sfe_visium <- 
    read10xVisiumSFE(dirs = "./outs/", 
                     sample_id = "test_1",
                     type = "sparse", 
                     data = "filtered",
                     unit = "micron",
                     load = FALSE)

Error in nb2listw(g, style = style, zero.policy = zero.policy): Empty neighbour sets found

./outs/ looks like this:

|-- analysis
|-- cloupe.cloupe
|-- filtered_feature_bc_matrix
|-- filtered_feature_bc_matrix.h5
|-- metrics_summary.csv
|-- molecule_info.h5
|-- possorted_genome_bam.bam
|-- possorted_genome_bam.bam.bai
|-- raw_feature_bc_matrix
|-- raw_feature_bc_matrix.h5
|-- spatial
|-- spatial_enrichment.csv
`-- web_summary.html

Any idea? It works when data = "raw". What does style arg exactly mean, like “W”, “B”, “C”, “U”, “minmax” and “S”? Thank you.

lambdamoses commented 1 year ago

If you get that error, it means that you have singletons, or spots that don't have neighbors. This behavior is the default in spdep. TBH I'm not entirely sure what to do with singletons. Sometimes Space Ranger output gives singletons because there are small bits of tissue with one spot. You can set zero.policy = TRUE to silently drop the singleton (their spatially lagged values are set to 0 and don't affect global spatial statistics). See spdep documentation on the meaning of style: https://r-spatial.github.io/spdep/reference/nb2listw.html Basically W means row normalize the spatial weights matrix, B means binary, "raw" means when distance based weights are used the weights are not changed in any way by normalization, C means normalize so all entries of the spatial weights matrix sum to n (number of spots), U means C divided by n.

alikhuseynov commented 1 year ago

zero.policy = TRUE works, thanks! 👍