batch_effects_howto.md 1.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49



## Scater

```r

load_pack(SingleCellExperiment)
load_pack(scater)

data("sc_example_counts")
data("sc_example_cell_info")


# https://www.rdocumentation.org/packages/scater/versions/1.0.4/topics/plotExplanatoryVariables
example_sce <- SingleCellExperiment(assays = list(counts = sc_example_counts), colData = sc_example_cell_info)

example_sce <- SingleCellExperiment(assays = list(counts = sc_example_counts[,1:10]), colData = sc_example_cell_info[1:10,])

exprs(example_sce) <- log2(calculateCPM(example_sce, use.size.factors = FALSE) + 1)

example_sceset <- calculateQCMetrics(example_sce)
# example_sceset <- calculateQCMetrics(example_sce, feature_controls = 1:20)
# example_sceset <- calculateQCMetrics(example_sce, feature_controls = 1:3)
# example_sceset <- calculateQCMetrics(example_sce, feature_controls = list(covariates=c("Cell_Cycle", "Treatment")))

example_sceset <- plotPCA(example_sce)


plotQC(example_sceset, type = "expl")


varLabels(example_sceset)

plotExplanatoryVariables(example_sce)

plotQC(example_sce, type = "expl", method = "pairs", theme_size = 6)
plotQC(example_sce, type = "expl", method = "pairs", theme_size = 6)
plotExplanatoryVariables(example_sce, variables = c("Treatment", "Cell_Cycle"))
# +
#     theme(axis.text = element_text(size = 12), axis.title = element_text(size = 12)) +
#     ggtitle("Influence of putative batch factors on sample variance")


plotExpression(example_sce, rownames(example_sce)[1 : 6], x = "Mutation_Status", exprs_values = "exprs")
plotExpression(example_sce, rownames(example_sce)[1 : 6], x = "Mutation_Status", exprs_values = "exprs", colour = "Treatment")

plotReducedDim(example_sce, use_dimred = "PCA", ncomponents = 2)
```