Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

simExperiment.pdf, Summaries of Advanced Computer Programming

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

2021/2022

Uploaded on 09/12/2022

edmond
edmond 🇺🇸

3.8

(10)

251 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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)
## Uncomment to install kBet & lisi
## Note: the packages will require compilation
# if (!require(drat)) {install.packages("drat"); library(drat)}
# drat::addRepo("daynefiler")
# install.packages(c("lisi", "kBET", "harmony", "dlfUtils"))
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))
}
1
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download simExperiment.pdf and more Summaries Advanced Computer Programming in PDF only on Docsity!

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)

Uncomment to install kBet & lisi

Note: the packages will require compilation

if (!require(drat)) {install.packages("drat"); library(drat)}

drat::addRepo("daynefiler")

install.packages(c("lisi", "kBET", "harmony", "dlfUtils"))

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") }

t−SNE

Batch:

Cell−type:

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") }

Harmony−logcounts

Batch:

Cell−type:

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") }

Harmony−centered

Batch:

Cell−type:

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") }

mnnRes

Batch:

Cell−type:

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in max(pcCorr[setsignif]): no non-missing arguments to

max; returning -Inf

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in max(pcCorr[setsignif]): no non-missing arguments to

max; returning -Inf

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

1 and only the first element will be used

Warning in if (class(knn) == "list") {: the condition has length

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)