Closed LiuCanidk closed 4 months ago
I've encountered similar issue. Also, I think METAFlux package is not compatible with Seurat v5, yet.
Therefore, in Issue #5, I generated new codes for calculate_avg_exp() function by editing its source codes. Also, I slightly changed these codes, from Issue #5, in order to get counts matrix from seurat v5 object.
For Seurat v5, I think it will be working if you execute below codes and use 'edit_calculate_avg_exp()' function instead of 'calculate_avg_exp()'. All parameters are same with vignette.
generate_boots <- function(celltype, n) {
dt <- data.frame(cluster = celltype, id = 1:length(celltype))
index <- do.call(cbind, sapply(1:n, function(x) {
splits <- dt %>%
group_by(cluster) %>%
sample_n(dplyr::n(), replace = TRUE) %>%
ungroup() %>%
dplyr::select("id")
}))
return(index)
}
get_ave_exp <- function(i, myseurat, samples,myident) {
meta.data=myseurat@meta.data[samples[,i],]
sample <-GetAssayData(myseurat, assay = "RNA")[,samples[,i]]
name <- colnames(sample)
for (j in 1:length(name)) {
name[j] <- paste0(name[j], "_", j)
}
colnames(sample) <- name
rownames(meta.data) <- name
SeuratObject<-suppressWarnings(
CreateSeuratObject(count=sample, meta.data = meta.data))
SeuratObject<-NormalizeData(SeuratObject,verbose = TRUE)
ave<-GetAssayData(AverageExpression(SeuratObject,group.by = myident,return.seurat = T), assay = "RNA") %>% as.data.frame()
return(ave)
}
edit_calculate_avg_exp <- function(myseurat,myident,n_bootstrap,seed) {
set.seed(seed)
samples=generate_boots(myseurat@meta.data[,myident],n_bootstrap)
exp <- lapply(1:n_bootstrap,get_ave_exp,myseurat,samples,myident)
exp <- do.call(cbind, exp)
return(exp)
}
mean_exp = edit_calculate_avg_exp(myseurat = sc, myident = 'celltype', n_bootstrap = 50, seed = 1)
Great! Thanks for your kind sharing code! @yechanYS It worked after adjusting the source code. And I notice seuratV5 recommend using AggrerateExpression to perform pseudobulk analysis, maybe it is relevant. Anyway, again thank you very much!
Hi, I encountered an error when computing averaged expression values from the seurat object.
Error
I guess it's a problem with seuratV5 but found no specific information on how to solve this. My seurat object indeed has the counts layer.
Any help would be greatly appreciated!