4
$\begingroup$

I know that I can do subsetting on just one gene in Seurat:

seurat_subset <- SubsetData(seurat_object, subset.name = neuron_ids[1], accept.low = 0.1)

However, I want to subset on multiple genes. Is there a way to do that? I just do not want to do manual subsetting on 10 genes, then manually getting @data matrix from each subset, and recreating seurat object afterwards.

$\endgroup$
6
$\begingroup$

I was able to achieve this in the following way:

require(data.table)
cell_names <- vector(mode="character")
for (i in 1:length(neuron_ids)) {
  seurat_subset <- SubsetData(seurat_object, subset.name = neuron_ids[i], accept.low = 0.1)
  genes <- colnames(seurat_subset@data)
  cell_names <- c(cell_names, genes[! genes %chin% cell_names])
}
seurat_subset <- SubsetData(seurat_object, cells.use = cell_names)

Would be interesting to know if Seurat provides such functionality out of the box.

$\endgroup$
1
  • $\begingroup$ In Seurat V3 you should use seurat_subset <- SubsetData(seurat_object, cells = cell_names) as cells.use is no longer supported. $\endgroup$
    – zdebruine
    Nov 15 '19 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.