## ----intro, echo=FALSE, results="hide", message=FALSE-------------------------
knitr::opts_chunk$set(echo = TRUE)

## ----installation,eval=FALSE--------------------------------------------------
# if (!requireNamespace("BiocManager", quietly = TRUE)) {
#   install.packages("BiocManager")
# }
# BiocManager::install("BatChef")

## ----sce,  include=TRUE, message=FALSE, warning=FALSE-------------------------
library(BatChef)
sce <- simulate_data(
  n_genes = 2148, batch_cells = c(1210, 2251), compute_hvgs = TRUE,
  batch_fac_loc = c(0.1, 0.1), batch_fac_scale = c(0.1, 0.1),
  mean_shape = 0.4, lib_loc = 11.5,
  group_prob = c(0.17, 0.46, 0.37),
  compute_pca = TRUE, pca_ncomp = 10, output_format = "SingleCellExperiment"
)
sce

## ----so, eval=FALSE-----------------------------------------------------------
# so <- simulate_data(
#   n_genes = 2148, batch_cells = c(1210, 2251), compute_hvgs = TRUE,
#   batch_fac_loc = c(0.1, 0.1), batch_fac_scale = c(0.1, 0.1),
#   mean_shape = 0.4, lib_loc = 11.5,
#   group_prob = c(0.17, 0.46, 0.37),
#   compute_pca = TRUE, pca_ncomp = 10, output_format = "Seurat"
# )
# 
# adata <- simulate_data(
#   n_genes = 2148, batch_cells = c(1210, 2251), compute_hvgs = TRUE,
#   batch_fac_loc = c(0.1, 0.1), batch_fac_scale = c(0.1, 0.1),
#   mean_shape = 0.4, lib_loc = 11.5,
#   group_prob = c(0.17, 0.46, 0.37),
#   compute_pca = TRUE, pca_ncomp = 10, output_format = "AnnData"
# )

## ----pred, warning=FALSE------------------------------------------------------
pred <- suggested_method(input = sce, batch = "Batch")

## ----scmerge2, message=FALSE, warning=FALSE, results='hide', fig.keep='none'----
sce <- sce[SingleCellExperiment::rowData(sce)$hvg, ]
sce <- batchCorrect(input = sce, batch = "Batch", params = ScMerge2Params())
library(scater)
sce <- runPCA(sce,
  subset_row = rownames(sce),
  assay.type = "scmerge2", name = "scmerge2", ncomponent = 10
)

## ----out----------------------------------------------------------------------
sce

## ----perf, message=FALSE, warning=FALSE---------------------------------------
red <- SingleCellExperiment::reducedDimNames(sce)
metrics <- lapply(red, function(x) {
  metrics(
    input = sce, batch = "Batch",
    group = "Group", reduction = x,
    rep = 1
  )
})
metrics <- do.call(rbind, metrics)
metrics

## ----wassari------------------------------------------------------------------
metrics[, c(1:2, 5)]

## ----sessioninfo--------------------------------------------------------------
sessionInfo()

