Subset cells in Seurat data based on reads and gene expression
2
0
Entering edit mode
4 weeks ago
bgbs • 0

Hello,

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 using the Seurat R package.

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!

seurat • 554 views
ADD COMMENT
0
Entering edit mode
4 weeks ago
bk11 ★ 2.8k

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

#First check if your genes of interest are present in your Seurat object or not:
genes_of_interest <- c("OSTN", "BDNF", "FOS", "NPAS4", "EGR1", "LINC00473", "ZNF331", "PER1")
genes_in_data <- genes_of_interest[genes_of_interest %in% rownames(obj_combined_filtered_excitatiory)]
print(genes_in_data)

#You can then subset the Seurat object for your genes of interest
subset_data <- obj_combined_filtered_excitatiory[genes_in_data, ]

 #Then get cells or cell barcodes that expressed these genes:
cells_with_expression <- colnames(subset_data)[colSums(subset_data@assays$RNA@counts) > 0]
print(cells_with_expression)
ADD COMMENT
0
Entering edit mode

Hi, thanks for your response! I tried your solution, but I got errors unfortunately. Is there something I'm missing?

genes_of_interest <- c("OSTN", "BDNF", "FOS", "NPAS4", "EGR1", "LINC00473", "ZNF331", "PER1")
genes_in_data <- genes_of_interest[genes_of_interest %in% rownames(seurat.obj_combined_filtered_excitatiory)]
print(genes_in_data)
seurat.obj_combined_filtered_active <- seurat.obj_combined_filtered_excitatiory[genes_in_data, ]

I viewed subsetted seurat object of excitatory clusters

seurat.obj_combined_filtered_active

# An object of class Seurat 
# 8 features across 39702 samples within 1 assay 
# Active assay: RNA (8 features, 0 variable features)
#  3 layers present: counts, data, scale.data
#  2 dimensional reductions calculated: pca, umap

But it isn't subsetted? It has the same number of cells as seurat.obj_combined_filtered_excitatiory

I then ran these lines but got these errors

cells_with_expression <- colnames(seurat.obj_combined_filtered_active)[colSums(seurat.obj_combined_filtered_active@assays$RNA@counts) > 0]
print(cells_with_expression)

# Error in h(simpleError(msg, call)) : 
#   error in evaluating the argument 'x' in selecting a method for function 'colSums': no slot of name "counts" for this object of class "Assay5"
# 
# Error in print(cells_with_expression) : 
#   object 'cells_with_expression' not found
ADD REPLY
0
Entering edit mode

Could you check what layers are present in your Seurat object?

DefaultAssay(seurat.obj_combined_filtered_excitatiory) <- "RNA"
Layers(seurat.obj_combined_filtered_active)

If it is not counts, it may be data. And you may need to replace counts with data in the above function-

ADD REPLY
0
Entering edit mode

Hi, yes I did but I got the same error

 Error in h(simpleError(msg, call)) : 
 error in evaluating the argument 'x' in selecting a method for function 'colSums': no slot of name "data" for this object of class "Assay5"
ADD REPLY
0
Entering edit mode
4 weeks ago
bgbs • 0

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')
ADD COMMENT

Login before adding your answer.

Traffic: 2573 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6