forked from kpatel427/YouTubeTutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
singleCell_CI_markers.R
101 lines (63 loc) · 2.62 KB
/
singleCell_CI_markers.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# script to identify cluster identity -----------------
# Finding markers in every cluster
# Finding conserved markers
# Finding markers DE between conditions
# setwd("~/Desktop/demo/single_cell_DEG/script")
set.seed(1234)
library(Seurat)
library(tidyverse)
# load data
ifnb_harmony <- readRDS('../ifnb_harmony.rds')
str(ifnb_harmony)
View([email protected])
# visualize data
clusters <- DimPlot(ifnb_harmony, reduction = 'umap', group.by = 'seurat_clusters', label = TRUE)
condition <- DimPlot(ifnb_harmony, reduction = 'umap', group.by = 'stim')
condition|clusters
# findAll markers -----------------
FindAllMarkers(ifnb_harmony,
logfc.threshold = 0.25,
min.pct = 0.1,
only.pos = TRUE,
test.use = 'DESeq2',
slot = 'counts')
# findConserved markers -------------
# Notes:
# slot depends on the type of the test used,
# default is data slot that stores normalized data
# DefaultAssay(ifnb_harmony) <- 'RNA'
DefaultAssay(ifnb_harmony)
markers_cluster3 <- FindConservedMarkers(ifnb_harmony,
ident.1 = 3,
grouping.var = 'stim')
head(markers_cluster3)
# let's visualize top features
FeaturePlot(ifnb_harmony, features = c('FCGR3A'), min.cutoff = 'q10')
# min-cut off explanation:
seq(1,5)
SetQuantile('q50', seq(1,5))
SetQuantile('q10', seq(1,5))
# rename cluster 3 ident
Idents(ifnb_harmony)
ifnb_harmony <- RenameIdents(ifnb_harmony, `3` = 'CD16 Mono')
DimPlot(ifnb_harmony, reduction = 'umap', label = T)
# cells already have annotations provided in the metadata
View([email protected])
# Settings cluster identities is an iterative step
# multiple approaches could be taken - automatic/manual anotations (sometimes both)
# need to make sure each cell type forms a separate cluster
# setting Idents as Seurat annotations provided (also a sanity check!)
Idents(ifnb_harmony) <- [email protected]$seurat_annotations
Idents(ifnb_harmony)
DimPlot(ifnb_harmony, reduction = 'umap', label = TRUE)
# findMarkers between conditions ---------------------
ifnb_harmony$celltype.cnd <- paste0(ifnb_harmony$seurat_annotations,'_', ifnb_harmony$stim)
View([email protected])
Idents(ifnb_harmony) <- ifnb_harmony$celltype.cnd
DimPlot(ifnb_harmony, reduction = 'umap', label = TRUE)
# find markers
b.interferon.response <- FindMarkers(ifnb_harmony, ident.1 = 'CD16 Mono_STIM', ident.2 = 'CD16 Mono_CTRL')
head(b.interferon.response)
# plotting conserved features vs DE features between conditions
head(markers_cluster3)
FeaturePlot(ifnb_harmony, features = c('FCGR3A', 'AIF1', 'IFIT1'), split.by = 'stim', min.cutoff = 'q10')