## ----"install", eval = FALSE--------------------------------------------------
# if (!requireNamespace("BiocManager", quietly = TRUE)) {
#       install.packages("BiocManager")
#   }
# 
# BiocManager::install("betterChromVAR")
# 
# ## Check that you have a valid Bioconductor installation
# BiocManager::valid()

## ----loadData-----------------------------------------------------------------
suppressPackageStartupMessages({
  library(SummarizedExperiment)
  library(betterChromVAR)
})
attach(getDummyData())
counts
head(motifMatches)

## ----inspectRowData-----------------------------------------------------------
rowData(counts)

## ----addGCBias, eval=FALSE----------------------------------------------------
# # not run
# counts <- addGCBias(counts, genome=my_genome)

## ----betterChromVAR-----------------------------------------------------------
dev <- betterChromVAR(counts, motifMatches)
dev

## ----variability--------------------------------------------------------------
rowData(dev)

## ----getBackgroundBins--------------------------------------------------------
bg <- getBackgroundBins(counts)
bg

## ----computeBackgrounds-------------------------------------------------------
bg <- computeBackgrounds(counts, bg)
bg

## ----computeDeviations--------------------------------------------------------
dev <- computeDeviationsAnalytic(counts, background=bg, annotations=motifMatches)
dev

## ----getExpectations----------------------------------------------------------
ex <- getExpectation(counts)
bg <- getBackgroundBins(ex, bias=rowData(counts)$bias)
# this is equivalent to bg <- getBackgroundBins(counts)

## ----chunkCompute-------------------------------------------------------------
bg2 <- computeBackgrounds(counts[,1:3], bg, expectation = ex)
dev2 <- computeDeviationsAnalytic(counts[,1:3], bg2, motifMatches)
# this should be identical to what we had run on the whole object:
identical(assay(dev)[,1:3], assay(dev2))

## ----CVnorm-------------------------------------------------------------------
# we assign arbitrary groups to the samples:
counts$group <- rep(LETTERS[1:2], each=5)
# we run the smoothed CVnorm:
counts <- CVnorm(counts, grouping=counts$group)
# (the normal CVnorm could be run by omitting the grouping)
counts

## -----------------------------------------------------------------------------
bg <- getBackgroundKNN(counts)
dev <- computeDeviationsFromKNN(counts, bg, motifMatches)

## ----sessionInfo, echo=FALSE--------------------------------------------------
sessionInfo()

