error for Findmarkers function from seurat package

I have a count matrix named "metadata_marker", it is a sparse matrix. I want to make a Seurat object of it.
then Find marker genes for two different cell type like "CM" and "FB".
here is my code:

install.packages(c("Seurat", "Matrix"))
filtered_final_data_marker <- final_data_marker
filtered_final_data_marker <- as((as.matrix(filtered_final_data_marker)), "sparseMatrix")
seurat_obj <- CreateSeuratObject(counts = filtered_final_data_marker, assay = "RNA", names.field = 1, names.delim	= "_", = metadata_marker)
markers <- FindMarkers(seurat_obj, ident.1 = "CM",  ident.2 = "FB" , assay = "RNA", test.use = "wilcox", logfc.threshold = 0.1)

When I run the last line it shows this error:
Warning: No layers found matching search pattern provided
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'rowSums': subscript out of bounds
In addition: Warning messages:
1: Layer ‘data’ is empty
2: Layer ‘data’ is empty

for more information,
celltype donor condition
1 CM H5 Healthy
2 CM H5 Healthy
3 CM H5 Healthy
4 CM H5 Healthy
5 CM H5 Healthy
6 CM H5 Healthy
it has 615 rows
CM_H5_hca_Healthy_1 CM_H5_hca_Healthy_2 CM_H5_hca_Healthy_3
MIR1302-2HG 0 0 0
FAM138A 0 0 0
OR4F5 0 0 0
dim of it is 33555*615
Is there anyone who knows how to fix it?
thanks in advance.

First, in the code you share, you don't define the Idents(), so FindMarkers() should have failed with a cannot find identity "CM" message. I imagine you have more code that you didn't share.

Then, for your error message, it's because within the assay RNA, you can have several slots, typically counts and data.

Here, because you are just creating the object from a count matrix, it gets added in the counts slot. You could force FindMarkers() to use that slot:

Idents(seurat_obj) <- "celltype"

markers <- FindMarkers(seurat_obj,
                       ident.1 = "CM",  ident.2 = "FB" , 
                       assay = "RNA", slot = "counts",
                       test.use = "wilcox", logfc.threshold = 0.1)

By default, FindMarkers() will look for the slot data, it would be created if you perform the usual normalizations, either with normalizeData() or with SCTransform(). For example:

seurat_obj <- NormalizeData(seurat_obj, normalization.method = "LogNormalize", scale.factor = 10000)

markers <- FindMarkers(seurat_obj,
                       ident.1 = "CM",  ident.2 = "FB" , 
                       assay = "RNA",
                       test.use = "wilcox", logfc.threshold = 0.1)

In general, I would recommend using the normalized data for the tests, to account for the fact that the individual single cells have been sequenced at different depths. In principle (according to the paper), SCTransform is even better than the basic normalizeData().

1 Like

Thanks, @AlexisW, your code worked, you are right I didn't have the "data" slot in the Seurat object. Before you answered I had tried something else and it worked too.
I used assay version 3 because assay version 5 doesn't have the "data" slot.

options(Seurat.object.assay.version = "v3")

Now it is fixed.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.