I'm trying to subset a Seurat object (called dNSC_cells) based on counts of genes of interest. Specifically, I have a list of genes and I plan on looping through them to subset my data and do some Wilcox tests. What I have so far looks like this:
pro_genes_list <- c("Bcl2", "Bid")
for (p in pro_genes_list) {
median_prog <- median(GetAssayData(dNSC_cells, slot = 'counts')[p,])
with_p <- colnames(subset(dNSC_cells, subset = as.name(p) > median_prog))
However, it blocks at the last line, with this Error:
Error in FetchData(object = object, vars = unique(x = expr.char[vars.use]), :
None of the requested variables were found:
I also tried using
subset = p > median_prog
but it gave the same Error. Would be super grateful for any pointers!
the subset
function does not support gene symbol in variable, you need to extract a dataframe first.
for (p in pro_genes_list) {
median_prog <- median(GetAssayData(dNSC_cells, slot = 'counts')[p,])
expr <- FetchData(object = dNSC_cells, vars = p)
with_p <- colnames(dNSC_cells[, which(expr > median_prog)])
}
Hi, thanks for the update! That seems to do something but it doesn't seem to give me the counts for the expr. I'd like to use raw counts there. I tried p_expr <- table(GetAssayData(dNSC_cells, slot = 'counts')[p,]) but that somehow omits most of the data. Thoughts?
Me again, your suggestion, with a little workaround, solved it!
p_expr <- as.data.frame(GetAssayData(dNSC_cells, slot = 'counts')[p,]) p_expr <- p_expr %>% rename(ex =
GetAssayData(dNSC_cells, slot = "counts")[p, ]) ## cells that have at least 1 count of Bcl2 with_p <- colnames(dNSC_cells[, which(p_expr$ex > median_prog)])
thank you!!