Question: Batch effect removal before SC3?
1
gravatar for muad.abdelhay
21 months ago by
muad.abdelhay10 wrote:

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?

 

ADD COMMENTlink modified 21 months ago by Vladimir Kiselev150 • written 21 months ago by muad.abdelhay10
Answer: Batch effect removal before SC3?
0
gravatar for Vladimir Kiselev
21 months ago by
Sanger Institute, Cambridge, UK
Vladimir Kiselev150 wrote:

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 COMMENTlink written 21 months ago by Vladimir Kiselev150
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 350 users visited in the last hour