This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to remove rows with empty gene symbols from a seurat object?

Hi Biostars,

I convert Ensembl gene to gene symbol of a seurat object, so 144 rows have "" instead of gene symbols among 26,407 rows. When I subset the seurat object with Ensembl, no error but seurat object with gene symbol has error. I guess because of the "" rows.

subset_seurat <- subset(combined_seurat, subset = sample %in% group_1)
Error in .subscript.2ary(x, i, j, drop = drop) : subscript out of bounds
In addition: Warning message:
In subset.Assay(x = x[[assay]], cells = cells, features = assay.features) :
  NAs passed in the features vector, removing NAs

combined_seurat <- combined_seurat[rownames(combined_seurat) != "", ]
Error in .subscript.2ary(x, i, j, drop = drop) : subscript out of bounds
In addition: Warning message:
In subset.Assay(x = x[[assay]], cells = cells, features = assay.features) :
  NAs passed in the features vector, removing NAs

I checked all elements in group_1 is included in combined_seurat object, so the error message in this case is not relevant. Would you please have a suggestion in this case? When I subset using Ensembl ID and convert to gene symbol later, no error. Thank you so much!

seurat

1 answer

I cannot recommend the approach of renaming your features in the Seurat object to gene symbols yourself. So, don't do it. You have no guarantee that gene symbols are unique or complete or that the Seurat functions can deal with it. Indeed, renaming features is not supported. Run your analysis on the gene names that come with the Seurat object and don't change them. After you identified genes of interest from the analysis, map the gene ids to gene symbols and go from there. If you need to change gene names, change the names in the count matrix before creating the Seurat Object. Make sure all rows have non-empty names and that all names are unique.

See also here: https://github.com/satijalab/seurat/discussions/8999 and https://github.com/satijalab/seurat/issues/2617

I use cellchat and it will have error with Ensembl ID but no error with gene symbol.

Then I recommend going with gene symbols from the start by renaming the count matrix.

Log in to answer this question.