-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCellChat_Basics.Rmd
195 lines (156 loc) · 5.21 KB
/
CellChat_Basics.Rmd
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
---
title: "CellChatAnalysis"
author: "Daniel Lee"
date: "2023-08-01"
output: pdf_document
---
## Overall analysis
```{r global_options, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, eval = TRUE,
warning = FALSE, message = FALSE,
fig.align = "center",
R.options = list(max.print=100))
```
```{r}
getwd()
# running renv
# install.packages("renv")
library(renv)
# renv::init()
# renv::snapshot()
# renv::status()
# renv::clean()
# renv::restore()
# renv::history()
```
```{r}
# install.packages("devtools")
# if (!require("BiocManager", quietly = TRUE))
# install.packages("BiocManager")
# BiocManager::install(version = "3.17")
# BiocManager::install("NMF")
# BiocManager::install("BiocGenerics")
# install.packages("car")
# BiocManager::install("Biobase")
# BiocManager::install("ComplexHeatmap")
# BiocManager::install("Seurat")
# svglite, expm, RSpectra, ggpubr, car, gert, mgcv, BiocParallel, BiocNeighbors, clue manually downloaded from CRAN & BiocManager and moved to renv project directory
# devtools::install_github("sqjin/CellChat")
library(CellChat)
library(Seurat)
```
```{r}
# Load your data
setwd("/Volumes/biologos/Bioinformatics/Using-CellChat-for-Ligand-Receptor-Network-Analysis/Data")
myeloid <- readRDS("myeloid_srt_int.rds")
lymphoid <- readRDS("lymphoid_srt_int.rds")
# Assign cell types to myeloid clusters
myeloid$cell_type <- factor(
recode(myeloid$seurat_clusters,
`0` = "IL1B+ APOE+ Macrophages",
`1` = "IL1B+ APOE- Macrophages",
`2` = "Monocytes",
`3` = "KIT+ Mast cells",
`4` = "Dendritic cells",
`5` = "IL1B- APOE+ Macrophages",
`6` = "LYVE1+ Macrophages",
`7` = "IFN-associated Myeloid cells"
)
)
# Assign cell types to lymphoid clusters
lymphoid$cell_type <- factor(
recode(lymphoid$seurat_clusters,
`0` = "IL7R+ CD4+ Effector T cells",
`1` = "GZMK+ CD8+ T cells",
`2` = "GZMH+ CD8+ T cells",
`3` = "Natural Killer cells",
`4` = "CXCL8+ T cells",
`5` = "CD79A+ B cells type 1",
`6` = "CD79A+ B cells type 2",
`7` = "TIGIT+ CD4+ Treg cells",
`8` = "Plasma cells"
)
)
# Designate the specific clusters
myeloid_clusters <- c("IL1B+ APOE+ Macrophages",
"IL1B+ APOE- Macrophages",
"Dendritic cells",
"IL1B- APOE+ Macrophages",
"LYVE1+ Macrophages")
lymphoid_clusters <- c("IL7R+ CD4+ Effector T cells",
"GZMK+ CD8+ T cells",
"GZMH+ CD8+ T cells",
"CXCL8+ T cells",
"TIGIT+ CD4+ Treg cells")
# Subset the Seurat objects based on the cell type
myeloid_subset <- subset(myeloid, subset = cell_type %in% myeloid_clusters)
lymphoid_subset <- subset(lymphoid, subset = cell_type %in% lymphoid_clusters)
# Check the subset step
print(unique(myeloid_subset$cell_type))
print(unique(lymphoid_subset$cell_type))
# Combining the two datasets into a single Seurat object
combined_data <- merge(x = lymphoid_subset, y = myeloid_subset)
```
```{r}
# Check the merge
unique(combined_data$cell_type)
# Create a new CellChat object with the subsetted data
cellchat <- createCellChat(object = combined_data, meta = [email protected], group.by = "cell_type")
```
```{r}
# Set the ligand-receptor interaction database
CellChatDB.use <- CellChatDB.human
# Using a subset of CellChatDB for cell-cell communication analysis
CellChatDB.use <- subsetDB(CellChatDB.human, search = "Secreted Signaling")
# Add the Secreted Signaling database in the CellChat object
cellchat@DB <- CellChatDB.use
```
```{r}
# Pre-process the expression data
cellchat <- subsetData(cellchat)
cellchat <- identifyOverExpressedGenes(cellchat)
cellchat <- identifyOverExpressedInteractions(cellchat)
```
```{r}
# Project gene expression data onto protein-protein interaction (PPI)
cellchat <- projectData(cellchat, PPI.human)
```
```{r}
# Compute communication probabilities again
cellchat <- computeCommunProb(cellchat, raw.use = FALSE)
```
```{r}
# Filter out the cell-cell communication if there are only few number of cells
# in certain cell groups
cellchat <- filterCommunication(cellchat, min.cells = 10)
```
```{r}
# Infer the cell-cell communication at a signaling pathway level
cellchat <- computeCommunProbPathway(cellchat)
```
```{r}
# Calculate the aggregated cell-cell communication network
cellchat <- aggregateNet(cellchat)
cellchat@net$count
cellchat@net$weight
```
```{r}
# Create your plots
groupSize <- as.numeric(table(cellchat@idents))
par(mfrow = c(1, 2), xpd=TRUE)
netVisual_circle(cellchat@net$count, vertex.weight = groupSize,
weight.scale = T, label.edge= T, title.name = "Number of interactions")
netVisual_circle(cellchat@net$weight, vertex.weight = groupSize,
weight.scale = T, label.edge= T, title.name = "Interaction weights/strength")
```
```{r}
str(cellchat)
# Save the CellChat object for future reference
setwd("/Volumes/biologos/Bioinformatics/Using-CellChat-for-Ligand-Receptor-Network-Analysis/CellChatObjects")
saveRDS(cellchat, file = "Myeloid_Lymphoid_scRNA_cellchat.rds")
```
```{r, echo=F}
## DO NOT DELETE THIS BLOCK!
Sys.info()
sessionInfo()
```