satijalab / seurat

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

split integrated xenium objects #9024

Open yxue88 opened 2 weeks ago

yxue88 commented 2 weeks ago
# insert reproducible example here
I have 5 samples for xenium assay, and want to analyze them in r by integrating them together. after that, i want to split them by using split.obj <- SplitObject(naming.obj,split.by = 'Sample'). 
it returns: 
        Error in subset.Centroids(x = x[[i]], cells = cells) : 
          None of the requested cells found
the SplitObject works for my other integrated single cell sequencing(non-spatial) dataset, but do not work for my integrated xenium data.

I used seurat 4. Below is what I did in brief:
I created objects, all from my xenium data
path1 <- "C:/Xenium analysis-C drive/xenium data/output-XETG00089__0025040__Region_2__20240501__164432"
NE.obj <- LoadXenium(path1, fov = "fov")
# remove cells with 0 counts
NE.obj <- subset(NE.obj, subset = nCount_Xenium > 0)
Combined all the objects
merged_seurat <- merge(x=NE.obj,y=c(P7a.obj, P7b.obj, Yd1a.obj, Yd1b.obj),add.cell.id=c("NE.obj",'P7a.obj', 'P7b.obj', 'Yd1a.obj', 'Yd1b.obj'))
give the name “Sample”
metadata$Sample <- NA
metadata$Sample[which(str_detect(metadata$cells, "^NE.obj"))] <- "NE"
metadata$Sample[which(str_detect(metadata$cells, "^P7a.obj"))] <- "P7a"
metadata$Sample[which(str_detect(metadata$cells, "^P7b.obj"))] <- "P7b"
metadata$Sample[which(str_detect(metadata$cells, "^Yd1a.obj"))] <- "Yd1a"
metadata$Sample[which(str_detect(metadata$cells, "^Yd1b.obj"))] <- "Yd1b"

then do the dimension reduction and the cell clustering
merged_seurat <- SCTransform(merged_seurat, assay = "Xenium")
merged_seurat <- RunPCA(merged_seurat, npcs = 30, features = rownames(merged_seurat))
merged_seurat <- RunUMAP(merged_seurat, dims = 1:20)
merged_seurat <- FindNeighbors(merged_seurat, reduction = "pca", dims = 1:20)
merged_seurat <- FindClusters(merged_seurat, resolution = 0.3)
yxue88 commented 2 weeks ago

also, when I tried to calculate pathway scores for my integrated xenium object by using the below: seurat_scoring <- AddModuleScore( object = naming.obj, features = qlist, name = 'quiesence', search =TRUE) it do not work: Error in sample.int(length(x), size, replace, prob) : cannot take a sample larger than the population when 'replace = FALSE'

can anyone help with this? thanks a lot!

zskylarli commented 1 week ago

Hi - only in response to your initial issue as the follow-up has been duplicated as another issue; can you please show your sessionInfo() as we have recently resolved a similar issue with our latest versions of Seurat and SeuratObject?