dviraran / SingleR

SingleR: Single-cell RNA-seq cell types Recognition (legacy version)
GNU General Public License v3.0
260 stars 95 forks source link

Assigning cell types problem #163

Closed esoaress closed 1 month ago

esoaress commented 1 month ago

Hello,

I am facing problems when assigning cell types using celldex::ImmGenData()

Console

pred <- SingleR(test = as.SingleCellExperiment(alldata), ref = ref, labels = ref$label.main)

Error in GetAssayData(): ! GetAssayData doesn't work for multiple layers in v5 assay. Run rlang::last_trace() to see where the error occurred.

rlang::last_trace() <error/ You can run 'object <- JoinLayers(object = object, layers = layer)'.> Error in GetAssayData(): ! GetAssayData doesn't work for multiple layers in v5 assay.

Backtrace: ▆

  1. ├─SingleR::SingleR(...)
  2. │ └─SingleR:::.to_clean_matrix(...)
  3. │ └─base::rownames(x)
  4. ├─Seurat::as.SingleCellExperiment(alldata)
  5. └─Seurat:::as.SingleCellExperiment.Seurat(alldata)
  6. ├─SeuratObject::GetAssayData(object = x, assay = assayn, slot = "counts")
  7. └─SeuratObject:::GetAssayData.Seurat(...)
  8. ├─SeuratObject::GetAssayData(object = object[[assay]], layer = layer)
  9. └─SeuratObject:::GetAssayData.StdAssay(object = object[[assay]], layer = layer) Run rlang::last_trace(drop = FALSE) to see 1 hidden frame.

This were the commands

library(dplyr) library(Seurat) library(patchwork) library(SingleR) library(celldex)

directory <- getwd() dir(directory)

p1d0 <- Read10X("P1-d0") # Replace 'path_to_dataset1' with the path to your first dataset p2d0 <- Read10X("P2_d0") # Replace 'path_to_dataset1' with the path to your first dataset

celldex p1d0 <- CreateSeuratObject(p1d0, project = "p1d0") p2d0 <- CreateSeuratObject(p2d0, project = "p2d0")

add metadata

p1d0$type = "p1d0" p2d0$type = "p2d0"

The [[ operator can add columns to object metadata. This is a great place to stash QC stats

p1d0[["percent.mt"]] <- PercentageFeatureSet(p1d0, pattern = "^MT-") p2d0[["percent.mt"]] <- PercentageFeatureSet(p2d0, pattern = "^MT-")

Visualize QC metrics as a violin plot

VlnPlot(p1d0, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)

VlnPlot(p2d0, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)

p1d0 <- subset(p1d0, subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5) p2d0 <- subset(p2d0, subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5)

Merge datasets into one single seurat object

alldata <- merge(p1d0, c(p2d0), add.cell.ids = c("p1d0", "p2d0")) alldata <- NormalizeData(alldata) alldata <- FindVariableFeatures(alldata) alldata <- ScaleData(alldata) alldata <- RunPCA(alldata, npcs = 30, verbose = FALSE) alldata <- RunUMAP(alldata , reduction = "pca", dims = 1:30) alldata <- FindNeighbors(alldata, reduction = "pca", dims = 1:30) alldata <- FindClusters(alldata, resolution = 0.5)

View(alldata@meta.data)

DimPlot(alldata, reduction = "umap", label=TRUE)

ref <- celldex::ImmGenData()

pred <- SingleR(test = as.SingleCellExperiment(alldata), ref = ref, labels = ref$label.main)

Please post issues in https://github.com/LTLA/SingleR

esoaress commented 1 month ago

issue solved