AggregateExpression() with return.seurat=TRUE not working as expected
0
0
Entering edit mode
3 months ago
BIANCO • 0

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 • 382 views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1825 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6