bnprks / BPCells

Scaling Single Cell Analysis to Millions of Cells
https://bnprks.github.io/BPCells
Other
166 stars 17 forks source link

Problem running with Visium HD spatial Data #145

Open salasd opened 4 weeks ago

salasd commented 4 weeks ago

Trying to use BPCells to help with smoother analysis of Visium HD data but keep getting errors.

localdir <- "/projects/visium-hd-invasion/HD_Mousebrain"

visium_data <- Load10X_Spatial(data.dir = localdir, bin.size = c(8,16))

Convert to BPCells format

expr_matrix <- GetAssayData(visium_data, layer = "counts") expr_matrix_int <- convert_matrix_type(expr_matrix, type = "double")

write_matrix_dir(mat = expr_matrix, dir = "/projects/visium-hd-invasion/HD_Mousebrain/matrix") 19059 x 393543 IterableMatrix object with class MatrixDir

Row names: Xkr4, Rp1 ... Vamp7 Col names: s_008um_00301_00321-1, s_008um_00602_00290-1 ... s_008um_00595_00611-1

Data type: double Storage order: column major

Queued Operations:

  1. Load compressed matrix from directory /projects/visium-hd-invasion/HD_Mousebrain/matrix

    bp_matrix <- open_matrix_dir(dir = "/projects/visium-hd-invasion/HD_Mousebrain/matrix")

    Create Seurat object with BPCells matrix

    seurat_big <- CreateSeuratObject(counts = bp_matrix) seurat_big@meta.data <- visium_data@meta.data seurat_big@images <- visium_data@images

    Proceed with your workflow

    DefaultAssay(seurat_big) <- "Spatial.008um" Error in match.arg(arg = value, choices = Assays(object = object)) : 'arg' should be “RNA” vln.plot <- VlnPlot(seurat_big, features = "nCount_Spatial.008um", pt.size = 0) + theme(axis.text = element_text(size = 4)) + NoLegend() Warning: Default search for "data" layer in "RNA" assay yielded no results; utilizing "counts" layer instead. Rasterizing points since number of points exceeds 100,000. To disable this behavior set raster=FALSE count.plot <- SpatialFeaturePlot(seurat_big, features = "nCount_Spatial.008um") + theme(legend.position = "right") vln.plot | count.plot

    Normalize data

    seurat_big <- NormalizeData(seurat_big) Normalizing layer: counts Error in validObject(object = x) : invalid class “Seurat” object: 'active.idents' must be as long as the number of cells present

immanuelazn commented 3 weeks ago

Hi salasd,

Good to see that you're trying to incorporate BPCells into your workflow! From what I see, this is an issue with Seurat rather than BPCells. It would be really good to evaluate whether this issue is happening with your workflow in Seurat, if you weren't using BPCells.

Nonetheless from what I see, there is a length mismatch between your active.idents and the number of cells in your dataset. Idents are batch information for your project. You can set it using Idents(object = seurat_big) <- "metadata_column", however Seurat probably should have set it with a default value first.

Best,

Immanuel