satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.26k stars 905 forks source link

Subset cells in Seurat data based on reads and gene expression #9027

Closed zgb963 closed 3 months ago

zgb963 commented 3 months ago

Hi Seurat team,

I have a question about how I can find all cells that have at least one read mapped to any of these 8 activity-dependent genes: OSTN, BDNF, FOS, NPAS4, EGR1, LINC00473, ZNF331, PER1

I have a seurat object that I have subsetted out to include only clusters that have genes expressed in excitatory neurons.

seurat.obj_combined_filtered_excitatiory <- subset(seurat.obj_combined_filtered, idents = c(0, 1, 3, 4, 5, 6, 8, 11, 14, 15, 16, 19, 20))

The next thing I want to do is from seurat.obj_combined_filtered_excitatiory object I want to find all cells/cell barcodes that have at least one read or UMI that maps to any one of the 8 activity-dependent genes listed above. In other words I want to generate a list of cell barcodes that express the 8 genes above. I tried doing this but I'm getting an error

seurat.obj_combined_filtered_active <- subset(seurat.obj_combined_filtered_excitatiory, cells = nCount_RNA > 1 & features = c("OSTN", "BDNF", "FOS", "NPAS4", "EGR1", "LINC00473", "ZNF331", "PER1"))

Error: unexpected '=' in "seurat.obj_combined_filtered_active <- subset(seurat.obj_combined_filtered_excitatiory, cells = nCount_RNA > 1 & features ="

Is this the right way to approach this? Is there another way I can do this? Should I be using the feature barcode matrix in the seurat object instead? I would like to further subset `seurat.obj_combined_filtered_excitatiory' and then return a list of cell barcodes that meet this criteria.

Then after this I would like to use the findAllMarkers function to find DEG between seurat.obj_combined_filtered_active & seurat.obj_combined_filtered_excitatiory. Is this possible? Or can I only use the findAllMarkers() function with only one seurat object at a time?

Any help with this will be much appreciated!

zgb963 commented 3 months ago

Hi, I've now figured this out. You can just use the WhichCells Seurat function which returns a list of cell barcodes what match a certain criteria.

active_cells_excitatory_subset <- WhichCells(object = seurat.obj_combined_filtered_excitatiory, expression = OSTN > 0 | BDNF > 0 | FOS > 0 | NPAS4 > 0 | EGR1 > 0 | LINC00473 > 0 | ZNF331 > 0 | PER1 > 0, slot = 'counts')

I just need to figure out how to do the last step, which is to find DEG between these list of cell barcodes and the cell barcodes in the excitatory Seurat object. Again, any help would be appreciated!

zskylarli commented 3 months ago

Hi - once you have the cell names that you are looking for with active_cells_excitatory_subset, you can run code such as markers <- FindMarkers(seurat.obj_combined_filtered_excitatiory, cells.1 = active_cells_excitatory_subset, cells.2 = setdiff( Cells(seurat.obj_combined_filtered_excitatiory), active_cells_excitatory_subset) to obtain your DEGs.

We’ve also started asking users to direct questions like this to our Discussions board, where community members and developers can provide more targeted assistance. We’re going to close this issue for now but encourage you to utilize the other forum if you have further questions!

zgb963 commented 3 months ago

Hi @zskylarli thank you for your comment! The solution worked, I just had to change cells.1 & cells.2 to ident.1 & ident.2.