Seurat V5 Subscript Out of Bounds Error
0
0
Entering edit mode
4 months ago
KokiBio • 0

Hello,

I am trying to perform scRNA analysis with Seurat v5. I was originally having issues identifying the percentage of mitochondrial counts because my gene names were in ENSEMBL format. I decided to convert the ENSEMBL genes to gene symbols to identify mitochondrial counts.

seurat <- CreateSeuratObject(counts = counts, project = "e9.5", 
                             min.cells = 3, min.features = 250)

genes = read_tsv("E-MTAB.tsv", col_names = FALSE)
genes <- genes[,1]

mouse.ensembl <- useEnsembl(biomart = "genes", dataset = "mmusculus_gene_ensembl")

query_attributes = c("ensembl_gene_id", "external_gene_name")
query_filters = "ensembl_gene_id"

gene.symbol <- getBM(attributes = query_attributes, 
      filters = query_filters, 
      values = genes[,1],
      mart = mouse.ensembl,
      )

seurat.row.names <- rownames(seurat)
map <- setNames(gene.symbol$external_gene_name, gene.symbol$ensembl_gene_id)
new.row.names <- map[seurat.row.names]
new.row.names[is.na(new.row.names)] = seurat.row.names[is.na(new.row.names)]

seurat.subset <- seurat
rownames(seurat.subset[["RNA"]]) <- new.row.names

seurat.subset[["percent.mt"]] <- PercentageFeatureSet(seurat.subset, pattern = "^mt-")

The matching was not 1:1, but I replaced any NA values with the original ENSEMBL gene name. However, subsetting the seurat object later resulted in the following error.

seurat.subset <- subset(seurat.subset, percent.mt < 6)
Error in as.matrix(x = x)[i, , drop = drop] : subscript out of bounds

Please help me figure out why I am unable to subset after converting gene symbols, or if there are better ways to go about this. I am also new to R, so any advice on coding practices would be appreciated. Thank you!

Seurat scRNA • 550 views
ADD COMMENT
0
Entering edit mode

Renaming rownames of a Seurat object is not possible: you cannot change Ensembl ID to Gene Symbol or vice-versa. However, you can store the corresponding gene symbols in the meta.features of the Seurat object. For instance, you can check the rownames of your seurat.subset and you ll still see all your Ensembl ids. That's why the error might have come to your above script. Instead, you can supply a list of mitochondrial genes as follows:

seurat.subset[["percent.mt"]] <- PercentageFeatureSet(seurat.subset, features = c("ENSMUSG00000064336", "ENSMUSG00000064337", "ENSMUSG00000064338", "ENSMUSG00000064339", "ENSMUSG00000064340"...))
ADD REPLY

Login before adding your answer.

Traffic: 1880 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6