forked from PMBio/SingleCellCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_batch_correction.Rmd
More file actions
73 lines (61 loc) · 2.16 KB
/
tutorial_batch_correction.Rmd
File metadata and controls
73 lines (61 loc) · 2.16 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
title: "Batch correctionusing Seurat"
author: "Britta Velten"
date: "5/26/2020"
output: html_document
---
Following the tutorial provided by Seurat we will integrate human pancreatic islet cells profiled by different technologies.
# Getting the data
```{r, warning=FALSE, message=FALSE}
library(Seurat)
library(SeuratData)
```
```{r}
# InstallData("panc8")
data("panc8")
pancreas.list <- SplitObject(panc8, split.by = "tech")
pancreas.list <- pancreas.list[c("celseq", "celseq2", "fluidigmc1", "smartseq2")]
```
# Just for illustration: Data without integration
```{r}
panc8 <- NormalizeData(panc8)
panc8 <- FindVariableFeatures(panc8)
panc8 <- ScaleData(panc8)
panc8 <- RunPCA(panc8, npcs = 30, verbose = FALSE)
panc8 <- RunUMAP(panc8, reduction = "pca", dims = 1:30)
DimPlot(panc8, group.by = "tech", reduction = "umap")
DimPlot(panc8, group.by ="celltype", reduction = "umap")
```
# Data normalization
```{r}
for (i in 1:length(pancreas.list)) {
pancreas.list[[i]] <- NormalizeData(pancreas.list[[i]], verbose = FALSE)
pancreas.list[[i]] <- FindVariableFeatures(pancreas.list[[i]], selection.method = "vst",
nfeatures = 2000, verbose = FALSE)
}
```
# Integration
```{r}
reference.list <- pancreas.list[c("celseq", "celseq2", "smartseq2")]
pancreas.anchors <- FindIntegrationAnchors(object.list = reference.list, dims = 1:30)
```
```{r}
pancreas.integrated <- IntegrateData(anchorset = pancreas.anchors, dims = 1:30)
```
# Plotting after integration
```{r}
library(ggplot2)
library(cowplot)
library(patchwork)
# switch to integrated assay. The variable features of this assay are automatically
# set during IntegrateData
DefaultAssay(pancreas.integrated) <- "integrated"
# Run the standard workflow for visualization and clustering
pancreas.integrated <- ScaleData(pancreas.integrated, verbose = FALSE)
pancreas.integrated <- RunPCA(pancreas.integrated, npcs = 30, verbose = FALSE)
pancreas.integrated <- RunUMAP(pancreas.integrated, reduction = "pca", dims = 1:30)
p1 <- DimPlot(pancreas.integrated, reduction = "umap", group.by = "tech")
p2 <- DimPlot(pancreas.integrated, reduction = "umap", group.by = "celltype", label = TRUE,
repel = TRUE) + NoLegend()
p1 + p2
```