Batch effect removal before SC3?
1
1
Entering edit mode
@muadabdelhay-14075
Last seen 3.8 years ago

I wanted to run SC3 on normalized (scran/scater) logcounts that were then sent through limma's removeBatchEffect using the follwing script:

library(scater)
library(scran)
library(SC3)

txi.bbsplit <- readRDS("txi-bbsplit.rds")

counts.annotated <- txi.bbsplit$counts

### Removes genes that have no expression at all
counts.annotated <- counts.annotated[rowSums(counts.annotated)>0,]

### Load phenotypes
labels <- read.csv(file = "../118-phenotype-table.csv")

### Leave out the cells that were not added to the pool
labels <- labels[labels$CellNumber %in% as.character(colnames(counts.annotated)),]
labels$X <- NULL

## removed sex as it is complitely contained in the animal number
labels$Sex <- NULL

## removed Date as it is also completely contained in the animal
labels$Date <- NULL

rownames(labels) <- labels$CellNumber
labels$Animal <- factor(labels$Animal)
labels$AmpBatch <- factor(labels$AmpBatch)

pd <- new("AnnotatedDataFrame", data = labels)
sce <- newSCESet(countData = data.matrix(counts.annotated), phenoData = pd)

is.mito <- grepl("^mt.", rownames(sce))


sce <- calculateQCMetrics(sce, feature_controls = list(Mt = is.mito))

libsize.drop <- isOutlier(sce$total_counts, nmads=3, type="lower", log=TRUE)
feature.drop <- isOutlier(sce$total_features, nmads=3, type="lower", log=TRUE)
mito.drop <- isOutlier(sce$pct_counts_Mt, nmads=3, type="higher")
sce <- sce[,!(libsize.drop | feature.drop | mito.drop)]
filtered.out <- data.frame(ByLibSize=sum(libsize.drop), ByFeature=sum(feature.drop),
                           ByMito=sum(mito.drop), Remaining=ncol(sce))

## ave.counts <- calcAverage(sce)

## keep <- ave.counts >= 1

## sce <- sce[keep,]

sce <- computeSumFactors(sce)
sce <- normalize(sce)

library(limma)
logcounts.sce <- logcounts(sce)
logcounts(sce) <- removeBatchEffect(logcounts.sce, batch=sce$AmpBatch)

sce <- sc3_prepare(sce, ks = 2:6)

I get the following error:

Error in sc3_prepare(sce, ks = 2:6) :
  All genes were removed after the gene filter! Stopping now...

 

The above script runs fine without the batch effect removal step. Any idea why this happens?

 

SC3 batch effect removebatcheffect • 1.5k views
ADD COMMENT
0
Entering edit mode
@vladimir-kiselev-9342
Last seen 5.0 years ago
Sanger Institute, Cambridge, UK

Hi, what does removeBatchEffect return? If it remove zeros from your matrix this is not good for SC3 gene filter, which removes genes that have either very high or very low number of zeros. So, if there are no zeros in your data after batch correction, please switch the gene filter off by setting gene_filter = FALSE inside of sc3_prepare.

ADD COMMENT

Login before adding your answer.

Traffic: 804 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