satijalab / seurat

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

How can I visualize the celltype, rather than "orig.ident" #3393

Closed biostat0903 closed 4 years ago

biostat0903 commented 4 years ago

Hi Seurat team, Using the following code, I merge four 10x genomics scRNA-seq data.

sc_qc <- function(dat_str, project){

  require(Seurat)
  ## create object
  dat <- Read10X(data.dir = dat_str)
  seurat_obj <- CreateSeuratObject(counts = dat, 
                                   project = project, 
                                   min.cells = 3, 
                                   min.features = 300, 
                                   names.delim = "\\."
                                   )
  cat(paste0("The data includes ", dim(seurat_obj)[2], " cells.\n"))
  cat(paste0("The data includes ", dim(seurat_obj)[1], " features.\n"))
  ## return object 
  return(seurat_obj)

}
combined_list <- list()
### PG10
pg10_str <- "./PG10/raw_feature_bc_matrix"
pg10_project <- "PG10"
combined_list[[1]] <- sc_qc(pg10_str, pg10_project)
### PG22
pg22_str <- "./PG22/raw_feature_bc_matrix"
pg22_project <- "PG22"
combined_list[[2]] <- sc_qc(pg22_str, pg22_project)
### PG42
pg42_str <- "./PG42/raw_feature_bc_matrix"
pg42_project <- "PG42"
combined_list[[3]] <- sc_qc(pg42_str, pg42_project)
### PG56
pg56_str <- "./PG56/raw_feature_bc_matrix"
pg56_project <- "PG56"
combined_list[[4]] <- sc_qc(pg56_str, pg56_project)
### Rename cell 
combined_list[[1]] <- RenameCells(
  object = combined_list[[1]],
  new.names = paste0("pg10_", colnames(x = combined_list[[1]])) 
)
combined_list[[2]] <- RenameCells(
  object = combined_list[[2]],
  new.names = paste0("pg22_", colnames(x = combined_list[[2]])) 
)
combined_list[[3]] <- RenameCells(
  object = combined_list[[3]],
  new.names = paste0("pg42_", colnames(x = combined_list[[3]])) 
)
combined_list[[4]] <- RenameCells(
  object = combined_list[[4]],
  new.names = paste0("pg56_", colnames(x = combined_list[[4]])) 
)

Then I follows the code of SCTransform.

for (i in 1:length(combined_list)) {
        combined_list[[i]] <- SCTransform(combined_list[[i]], verbose = FALSE)
}
combined_features <- SelectIntegrationFeatures(object.list = combined_list, 
                                               nfeatures = 2000)
combined_list <- PrepSCTIntegration(object.list = combined_list, 
                                    anchor.features = combined_features, 
                                    verbose = FALSE)
combined_anchors <- FindIntegrationAnchors(object.list = combined_list, 
                                           normalization.method = "SCT", 
                                           anchor.features = combined_features, 
                                           verbose = FALSE)
combined_integrated <- IntegrateData(anchorset = combined_anchors, 
                                     normalization.method = "SCT", 
                                     verbose = FALSE)
combined_integrated <- RunPCA(combined_integrated, verbose = FALSE)

combined_integrated <- RunUMAP(combined_integrated, dims = 1:30)

Last, I fail to get the plot of UMAP. As I know, I should have celltype in the combined_integrated@meta.data. Could you tell me how I can get the celltype? The following is the str(combined_integrated@meta.data).

'data.frame':   93479 obs. of  5 variables:
 $ orig.ident  : chr  "PG10" "PG10" "PG10" "PG10" ...
 $ nCount_RNA  : num  1717 1407 26297 2590 5354 ...
 $ nFeature_RNA: int  857 552 5096 841 1839 5337 2717 415 5393 935 ...
 $ nCount_SCT  : num  2261 2334 2688 2611 3275 ...
 $ nFeature_SCT: int  859 569 1126 841 1668 1335 1047 512 1530 935 ...

Thanks!

Best, Sheng

timoast commented 4 years ago

Why should you have celltype in the metadata? You didn't add it in the code you posted...

biostat0903 commented 4 years ago

Hi, I hope to add celltype, because I would like to label the celltype on the UMAP plot. Could you tell me how to add the celltype in my code. Thanks

Best, Sheng

benjytan88 commented 4 years ago

Hi, then you need to cluster your data, check the markers and annotate them. I see in your code that you didn't do anything of the sort. Please refer to the sections downwards of Cluster the cells in this vignette. https://satijalab.org/seurat/v3.2/pbmc3k_tutorial.html