Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using WhichCells in a for loop #1839

Closed
ahoffrichter opened this issue Jul 17, 2019 · 2 comments
Closed

Error using WhichCells in a for loop #1839

ahoffrichter opened this issue Jul 17, 2019 · 2 comments

Comments

@ahoffrichter
Copy link

Hello,

I'm am having some troubles using the WhichCells() within a for loop.
My code looks like this:

genes <- c("KIF22", "RPGRIP1L")
v <- c(1:length(genes))
for (i in v){
  cells <- WhichCells(seurat_object, expression = genes[i] > 0)
  print(length(cells))
}

But when I run this I get the following error message:

Error in FetchData(object = object, vars = expr.char[vars.use], cells = cells, : None of the requested variables were found:

When I simply run

WhichCells(seurat_object, expression = KIF22 > 0)

it works fine.

In the end I would like to use this for loop to get some summary statistics for my genes of interest (e.g. min/max expression, mean expression, number of cells expressing the gene etc.).
So it would be great if I could find a way to make this work, or is there even a more simple/prebuilt way to do this?

@mojaveazure
Copy link
Member

Hi Anne,

Much like subset, the expression parameter for WhichCells is designed for interactive use only, not programmatic. In fact, subset.Seurat calls WhichCells under the hood. For using subset and WhichCells in a programmatic way, please see #1053 (comment)

@rahulnutron
Copy link

Thanks for this! this is what I did
Thanks,
Rahul

items <-c( 'AT1G06990', 'CHX14')
for (gene1 in items)
{
if (gene1 %in% rownames(gen.sobj))

{
expr <- FetchData(object = gen.sobj, vars = gene1)
gene_cells <- gen.sobj[, which(x = expr >= 0.5)]
write.csv(colnames(gene_cells),paste('E:/Rahul/',gene1,'.csv',sep = ''))

}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants