title | author | date |
---|---|---|
kBET short introduction |
Maren Büttner |
9/18/2017 |
The R package provides a test for batch effects in high-dimensional single-cell RNA sequencing data. It evaluates the accordance of replicates based on Pearson's
Installation should take less than 5 min.
If you want to install the package directly from Github, I recommend to use the devtools
package.
library(devtools)
install_github('theislab/kBET')
Please download the package as zip
archive and install it via
install.packages('kBET.zip', repos = NULL, type = 'source')
#data: a matrix (rows: samples, columns: features (genes))
#batch: vector or factor with batch label of each cell
batch.estimate <- kBET(data, batch)
kBET creates (if plot = TRUE
) a boxplot of the kBET rejection rates (for neighbourhoods and randomly chosen subsets of size k) and kBET returns a list with several parts:
- summary: summarizes the test results (with 95% confidence interval)
- results: the p-values of all tested samples
- average.pval: an average over all p-values of the tested samples
- stats: the results for each of
n_repeat
runs - they can be used to reproduce the boxplot that is returned by kBET - params: the parameters used in kBET
- outsider: samples without mutual nearest neighbour, their batch labels and a p-value whether their batch label composition varies from the global batch label frequencies
For a single-cell RNAseq dataset with less than 1,000 samples, the estimated run time is less than 2 minutes.
By default (plot = TRUE
), kBET returns a boxplot of observed and expected rejection rates for a data set. You might want to turn off the display of these plots and create them elsewhere. kBET returns all information that is needed in the stats
part of the results.
library(ggplot2)
batch.estimate <- kBET(data, batch, plot=FALSE)
plot.data <- data.frame(class=rep(c('observed', 'expected'),
each=length(batch.estimate$stats$kBET.observed)),
data = c(batch.estimate$stats$kBET.observed,
batch.estimate$stats$kBET.expected))
g <- ggplot(plot.data, aes(class, data)) + geom_boxplot() +
labs(x='Test', y='Rejection rate',title='kBET test results') +
theme_bw() +
scale_y_continuous(limits=c(0,1))
The standard implementation of kBET performs a k-nearest neighbour search (if knn = NULL
) with a pre-defined neighbourhood size k0, computes an optimal neighbourhood size (heuristics = TRUE
) and finally 10% of the samples is randomly chosen to compute the test statistics itself (repeatedly by default to derive a confidence interval, n_repeat = 100
). For repeated runs of kBET, we recommend to run the k-nearest neighbour search separately:
require('FNN')
# data: a matrix (rows: samples, columns: features (genes))
k0=floor(mean(table(batch))) #neighbourhood size: mean batch size
knn <- get.knn(data, k=k0, algorithm = 'cover_tree')
#now run kBET with pre-defined nearest neighbours.
batch.estimate <- kBET(data, batch, k = k0, knn = knn)
#data: a matrix (rows: samples, columns: features (genes))
#batch: vector or factor with batch label of each cell
pca.data <- prcomp(data, center=TRUE) #compute PCA representation of the data
batch.silhouette <- batch_sil(pca.data, batch)
batch.pca <- pcRegression(pca.data, batch)
For a single-cell RNAseq dataset with less than 1,000 samples, the estimated run time is less than 2 minutes.