This is a test version of Biostars. For the public version, visit https://www.biostars.org.
AggregateExpression() with return.seurat=TRUE not working as expected

Hi! I am trying to understand what is happening when I use AggregateExpression() in Seurat v5 for pseudobulk. This is my code

pseudobulk <- AggregateExpression(seurat_obj, assays = "RNA" , group.by = c("subtype", "DiseaseStage", 
                                                                           "DiseaseStage_subtype"), return.seurat = TRUE)
pseudobulk@meta.data <- as.data.frame(lapply(pseudobulk@meta.data, function(column) {
  column <- gsub("-", "_", column)
  column <- sub("^g", "", column)
  return(column)
}))


DEGs <- data.frame()

subtype_list <- sort(unique(seurat_obj@meta.data[["subtype"]]))

ident.1_list <- sort(unique(seurat_obj@meta.data[["DiseaseStage"]]))
ident.1_list <- ident.1_list[2:length(ident.1_list)] 

for (subtype in subtype_list){
  for (DiseaseStage in ident.1_list) {
    control_group <- paste0("WT", "__", subtype)
    disease_group <- paste0(DiseaseStage, "__", subtype)
    if (control_group %in% unique(pseudobulk@meta.data$DiseaseStage_subtype) &
        disease_group %in% unique(pseudobulk@meta.data$DiseaseStage_subtype)){

      Idents(pseudobulk) <- "DiseaseStage_subtype" 
      DiseaseStage_DEGs <- FindMarkers(pseudobulk, ident.1 = disease_group, ident.2 = control_group, verbose = FALSE,
                                   test.use = "wilcox", only.pos = FALSE, logfc.threshold = 0.5)
      DEGs <- rbind(DEGs, DiseaseStage_DEGs)
    }
  }
}

and I get

Error in `FindMarkers()`:
! Cells in one or both identity groups are not present in the data requested

which is odd because both

control_group %in% unique(pseudobulk@meta.data$DiseaseStage_subtype)

and

disease_group %in% unique(pseudobulk@meta.data$DiseaseStage_subtype)

return TRUE. Anyone has an explanation?

seurat seurat5 aggregateexpression

Without a proper example of the dataset, it is hard to reproduce the error. Try to simplify it as much as possible to narrow down possible culprits.

My random guess would be on the level factor of your pseudobulk$DiseaseStage_subtype

0 answers

No answers yet.

Log in to answer this question.