





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
1 and only the first element will be used. ## Warning in if (class(knn) == "list") 1: the condition has length. > 1 and only the first element will be used.
Typology: Summaries
1 / 9
This page cannot be seen from the preview
Don't miss anything!






First, load the following packages. Note, some of the packages are not available on CRAN or BioConductor. They can, however, be installed by using the drat package.
pkgLoaded <- suppressPackageStartupMessages({ c(require(bcTSNE), require(data.table), require(batchelor), require(kBET), require(splatter), require(scater), require(Rtsne), require(lisi), require(harmony), require(dlfUtils), require(xtable)) }) pkgLoaded <- all(pkgLoaded)
Create simulated single-cell RNA sequencing data using the splatter package.
if (pkgLoaded) { p <- newSplatParams(seed = 1234, batchCells = rep(200, 4), batch.facLoc = 0.2, batch.facScale = 0.1, group.prob = c(0.1, 0.2, 0.3, 0.4), de.facLoc = 0.1, de.facScale = 0.4) sim <- splatSimulate(p, method = "groups", verbose = FALSE) sizeFactors(sim) <- librarySizeFactors(sim) sim <- logNormCounts(sim) sim <- logNormCounts(sim, log = FALSE) assay(sim, "centered") <- t(scale(t(normcounts(sim)), center = TRUE, scale = FALSE)) Z <- model.matrix( ~ -1 + factor(colData(sim)$Batch)) grp <- factor(sim$Group) bch <- as.integer(factor(sim$Batch)) }
Setup a placeholder for the results:
res <- vector(mode = "list", length = 6) names(res) <- c("btcc", "btlc", "hmlc", "hmcc", "mnn", "tsne")
Start by running the regular t-SNE algorithm:
if (pkgLoaded) { set.seed(1234) res$tsne <- Rtsne(t(assay(sim, "centered")), inital_dims = 50)$Y pltSimRes(res$tsne, "t-SNE") }
Run the BC-t-SNE algorithm on centered:
if (pkgLoaded) { set.seed(1234) res$btcc <- bctsne(t(assay(sim, "centered")), Z, k = 50)$Y pltSimRes(res$btcc, "bcTSNE-centered") }
if (pkgLoaded) { set.seed(1234) sim <- runPCA(sim, 50, exprs_values = "logcounts") sim <- RunHarmony(sim, group.by.vars = "Batch") res$hmlc = Rtsne(reducedDim(sim, "HARMONY"), pca = FALSE)$Y pltSimRes(res$hmlc, "Harmony-logcounts") }
Run the harmony algorithm on the same set as bcTSNE, centered:
if (pkgLoaded) { set.seed(1234) sim <- runPCA(sim, 50, exprs_values = "centered") sim <- RunHarmony(sim, group.by.vars = "Batch") res$hmcc = Rtsne(reducedDim(sim, "HARMONY"), pca = FALSE)$Y pltSimRes(res$hmcc, "Harmony-centered") }
Run the MNN algorithm:
if (pkgLoaded) { set.seed(1234) tmp <- mnnCorrect(sim, batch = factor(sim$Batch)) res$mnn <- Rtsne(t(assay(tmp, "corrected")), initial_dims = 50)$Y rm(tmp) pltSimRes(res$mnn, "mnnRes") }
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
max; returning -Inf
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
max; returning -Inf
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
> 1 and only the first element will be used
if (pkgLoaded) { calcMetrics <- function(Y, bchLst) { calcSil <- function(x) { s <- batch_sil(pca.data = list(x = Y), batch = x, nPCs = 2) 1 - abs(s)