-
Notifications
You must be signed in to change notification settings - Fork 128
/
singleCell_integrate_harmony.R
67 lines (47 loc) · 1.58 KB
/
singleCell_integrate_harmony.R
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
# script to integrate across conditions using Harmony
# setwd("~/Desktop/demo/single_cell_integrate/")
# set seed for reproducibility
set.seed(1234)
library(harmony)
library(Seurat)
library(SeuratData)
library(tidyverse)
library(ggplot2)
# get data -------------------------
AvailableData()
# install dataset
InstallData("ifnb")
# load dataset
LoadData("ifnb")
str(ifnb)
# QC and filtering
ifnb$mito.percent <- PercentageFeatureSet(ifnb, pattern = '^MT-')
View([email protected])
# explore QC
# filter
ifnb
ifnb.filtered <- subset(ifnb, subset = nCount_RNA > 800 &
nFeature_RNA > 200 &
mito.percent < 5)
# standard workflow steps
ifnb.filtered <- NormalizeData(ifnb.filtered)
ifnb.filtered <- FindVariableFeatures(ifnb.filtered)
ifnb.filtered <- ScaleData(ifnb.filtered)
ifnb.filtered <- RunPCA(ifnb.filtered)
ElbowPlot(ifnb.filtered)
ifnb.filtered <- RunUMAP(ifnb.filtered, dims = 1:20, reduction = 'pca')
before <- DimPlot(ifnb.filtered, reduction = 'umap', group.by = 'stim')
# run Harmony -----------
ifnb.harmony <- ifnb.filtered %>%
RunHarmony(group.by.vars = 'stim', plot_convergence = FALSE)
ifnb.harmony@reductions
ifnb.harmony.embed <- Embeddings(ifnb.harmony, "harmony")
ifnb.harmony.embed[1:10,1:10]
# Do UMAP and clustering using ** Harmony embeddings instead of PCA **
ifnb.harmony <- ifnb.harmony %>%
RunUMAP(reduction = 'harmony', dims = 1:20) %>%
FindNeighbors(reduction = "harmony", dims = 1:20) %>%
FindClusters(resolution = 0.5)
# visualize
after <- DimPlot(ifnb.harmony, reduction = 'umap', group.by = 'stim')
before|after