I am trying to carry out a single-cell analysis in which I started with a .RDS file. I was developing the workflow but I have stopped in the Quality control, because I need to add de "percent.mt" column in the count matrix of the dataset. I was trying but I discovered that the genes was named by ENSEMBLE ID nomenclature, and I need it in genesymbol. While trying to add that column, I found an error in the last step of it. I will show my script in case somebody could help me!
Thank you in advance.
Upload .RDS file
bonemarrow \<- readRDS(file = "C:/Users/merce/Documents/Máster en Bioinformática/TFM/be8db92e-e52c-430c-b3d1-c27b506f8c2e.rds")
str(bonemarrow)
slotNames(bonemarrow)
View([email protected])
Extract the expression count array from the Seurat object.
In this code, pbmc.data1@assays$RNA@counts accesses the expression count matrix inside the Seurat object pbmc.data1. Then, this count array is passed as counts argument to CreateSeuratObject
counts_matrix <- bonemarrow@assays$RNA@counts
Create a new Seurat object using the extracted counts matrix:
bonecounts<- CreateSeuratObject(counts = counts_matrix, project = "seuratM")
bonecounts
Quality control (QCONTROL):
View([email protected])
#1. PERCENT-MT
# calculate the percentage of mt
# Calculate the percentage of mitochondrial gene expression and assign it to the Seurat object.
# You can get the Ensembl IDs of the rows of the counts matrix.
ensembl_ids \<- rownames(counts_matrix)
Load the genomic annotation database for Mus musculus
if (!requireNamespace("org.Mm.eg.db", quietly = TRUE)) {
install.packages("org.Mm.eg.db")
}
library(org.Mm.Mm.eg.db)
Get the gene symbols corresponding to the Ensembl IDs
gene_symbols \<- select(org.Mm.eg.db, keys=ensembl_ids, columns="SYMBOL", keytype="ENSEMBL")
Now, gene_symbols contains a mapping between Ensembl IDs and gene symbols.
You can add the gene symbols to your count matrix as row names
*rownames(counts_matrix) \<- gene_symbols$SYMBOL*
At this step, I found this error:
rownames(counts_matrix) <- gene_info$external_gene_name
Error in fixupDN.if.valid(value, x@Dim) :
length of Dimnames[[1]] (17982) is not equal to Dim[1] (17985)