Warm tip: This article is reproduced from serverfault.com, please click

subset data based on read counts for Seurat object (Error in FetchData)

发布于 2021-09-08 15:53:11

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!

Questioner
Cora_olpe
Viewed
0
Horizon 2021-09-10 06:07:32

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