Hi. I am totally new to R and Seurat so please forgive me if this is a stupid question.
I have four samples (two mouse strains, treated and control). I created four individual Seuratobjects using the standard pipeline Read10X CreateSeuratObject Done QC (mito content ++)-->then filtered the cells
Then I run this on each object
SCTransform
RunPCA(npcs = 30, verbose = FALSE) %>%
RunUMAP(reduction = "pca", dims = 1:30, verbose = FALSE) %>%
FindNeighbors(reduction = "pca", dims = 1:30, verbose = FALSE) %>%
FindClusters(resolution = 0.7, verbose = FALSE)
before merging, and then again running:
merge.sct<-merge(x = object1, y = c(object2, object3, object4), add.cell.ids = c("object1", "object2", "object3", "object4"), merge.data = TRUE)
VariableFeatures(merge.sct[["SCT"]]) <- rownames(merge.sct[["SCT"]]@scale.data)
merge.sct <- PrepSCTFindMarkers((merge.sct), assay = "SCT", verbose = TRUE)
all.genes <- rownames(merge.sct)
merge.sct <- RunPCA(merge.sct, features = VariableFeatures(object = merge.sct))
merge.sct <- FindNeighbors(merge.sct, dims = 1:40)
merge.sct <- FindClusters(merge.sct, resolution = 0.5)
merge.sct <- RunUMAP(merge.sct, dims = 1:40)
In the merged object, the STRAINcontrol/STRAINtreated is stored in the orig.ident slot. I have also created individual slots called Strain and Treatment.
So to my question: All this worked nicely, I got nice clusters, and was able to use FindAllMarkers to determine cell types. However, when I wanted to look at single clusters and compare DEGs between conditions, something goes wrong.
I wanted to find DEGs in a given cluster in treated vs control:
`merged_markers<-FindMarkers(merge.sct, ident.1 = "3", group.by = "Treatment", test.use = "wilcox")`
then I get the error that it can't find the ident.1. I have tried typing "3", 3
, just 3, I have tried renaming the clusters with cell type, nothing works..
Here's the error:
Error in WhichCells.Seurat(object = object, idents = ident.1) : Cannot find the following identities in the object: 3
I have trouble with accessing the active.ident slot in the merged object as well..or I have no trouble changing it using
`Idents(object=merge.sct) <- "orig.ident"`
or back to clusters
Idents(object=merge.sct) <- "seurat_clusters"
When I do this I can see that it changes in the object (view(merge.sct)) but when I type
merge.sct$active.ident
I get this error.
Error: Cannot find 'active.ident' in this Seurat object
I get the same error when I try to visualize the active.ident in the four initial seurat objects that I used to create the merged.sct, so my concern is that something has gone wrong when creating these initial objects.
Additional info: I have Seurat version 4.3.0. I have tried to restart R, re-install Seurat several times.
Let me know if I need to provide more information Thank you so much! E
To loop through multiple clusters, one option would be:
this will produce a list,
cluster_markers
with theFindMarkers
results for each cluster as a separate "entry"/key-value pair in the list