casanova-lab/iMUBAC

batch effect detection

Closed this issue · 1 comments

Hi developer,

Thanks for creating this package.
Is there a function in this package that can test the batch effect before I run the iMUBAC::batchCorrection() function?
Thanks.

Hi,

Below is the benchmarking function we used during the study. The core function is implemented in the EMDomics package. Please also refer to the Fig. 2 of our paper (https://www.jimmunol.org/content/206/1/206.long) which is freely available.
Thanks for your interest.

computeEMD <- function(f, a="exprs"){
print(f)
print(a)
sce <- readRDS(f)
sce <- sce[,which(is.finite(colSums(assay(sce, a))))] ## excluding cells with infinite values
sce <- iMUBAC::downsampleSCE(
sce,
maxN=10000,
group_by="batch",
indiv_by="file_name",
seed=12345
)
cellIDs <- paste0("Cell",1:ncol(sce))
exp_data <- SummarizedExperiment::assay(sce, a)
colnames(exp_data) <- cellIDs
labels <- sce$"batch"
names(labels) <- cellIDs
results <- EMDomics::calculate_emd(exp_data, labels, nperm=100, parallel=T, verbose=T)
data.table::data.table("file_name"=f, "assay"=a, "antigen"=rownames(results[["emd"]]), "emd"=results[["emd"]][,"emd"], "qvalue"=results[["emd"]][,"q-value"])
}