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)])
}