Hello, I am working on scRNA-seq analysis using Seurat. For quality control, I am trying to calculate the proportion of reads mapped to mitochondrial transcripts. Since the sample is derived from drosophila, I got the information of mitocondrial transcripts in drosophila as below.
library(AnnotationHub)
library(ensembldb)
ah <- AnnotationHub()
ahDb <- query(ah, pattern = c("Drosophila melanogaster", "EnsDb"))
id <- ahDb %>% mcols() %>% rownames() %>% tail(n = 1)
edb <- ah[[id]]
annotations <- genes(edb, return.type = "data.frame")
annotations <- annotations %>% dplyr::select(gene_id, gene_name, gene_biotype, seq_name, description, entrezid)
View(annotations)
mt <- annotations %>% dplyr::filter(seq_name == "mitochondrion_genome") %>% dplyr::pull(gene_name)
The "mt" showed 38 mitochondrial transcripts. However, when I tried to use the following codes, there was an error message as "Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'colSums': object of type 'closure' is not subsettable".
metadata$mtUMI <- Matrix::colSums(counts[which(rownames(counts) %in% mt),], na.rm = T)
I would appreciate it if someone could inform me of how to fix it up.
You are trying to filter on a function called
counts()
. Thisobject of type 'closure' is not subsettable"
means that one is trying to do filtering and subsetting operation on a function while assuming it was a variable with (in your case) counts.Here is an example:
Meaning you probably think that
counts
was a matrix of counts, which it probably isn't. Check your code and make sure the count matrix is indeed assigned tocounts
.The problem was solved thanks to your advice. I appreciate your help!