-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCellChat_comparison_7hours.Rmd
691 lines (510 loc) · 28.7 KB
/
CellChat_comparison_7hours.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
---
title: "Cell-cell interactions with CellChat"
output:
html_document:
df_print: paged
pdf_document: default
---
## Cell-cell interactions for in vitro samples (7 hours post vaccination)
```{r setup, include=FALSE}
#knitr::opts_chunk$set(dev = 'pdf')
```
```{r load_libraries, echo = F}
# libraries
#devtools::install_github("sqjin/CellChat")
#devtools::install_github("thomasp85/patchwork")
suppressPackageStartupMessages(library(CellChat))
suppressPackageStartupMessages(library(patchwork))
suppressPackageStartupMessages(library(ComplexHeatmap))
suppressPackageStartupMessages(library(circlize))
suppressPackageStartupMessages(library(RColorBrewer))
suppressPackageStartupMessages(library(svglite))
suppressPackageStartupMessages(library(NMF))
suppressPackageStartupMessages(library(ggalluvial))
#library(pheatmap)
options(stringsAsFactors = FALSE)
#options(bitmapType="cairo")
```
```{r clusters, echo = F}
levels(cellchat@idents)
```
### Condition 1: Control
```{r show_cond1, echo = F}
# Pick a condition
# BNT162b2 or AZD1222 or Ctrl
cellchat <- readRDS("~/Documents/charite/Sophia/cellchat_7h_Ctrl.rds")
cellchat <- computeCommunProbPathway(cellchat)
cellchat@netP$pathways
```
```{r CCC_signaling1, echo = F}
#Infer the cell-cell communication at a signaling pathway level
#CellChat computes the communication probability on signaling pathway level by summarizing the communication probabilities of all ligands-receptors interactions associated with each signaling pathway.
#NB: The inferred intercellular communication network of each ligand-receptor pair and each signaling pathway is stored in the slot ‘net’ and ‘netP’, respectively.
cellchat <- aggregateNet(cellchat)
pathways.show <- c("CCL")
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= F, title.name = "Number of interactions")
netVisual_circle(cellchat@net$weight, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")
mat <- cellchat@net$weight
par(mfrow = c(3,4), xpd=TRUE)
for (i in 1:nrow(mat)) {
mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat))
mat2[i, ] <- mat[i, ]
netVisual_circle(mat2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i])
}
# Hierarchy plot
# Here we define `vertex.receive` so that the left portion of the hierarchy plot shows signaling to fibroblast and the right portion shows signaling to immune cells
vertex.receiver = seq(1,4) # a numeric vector.
netVisual_aggregate(cellchat, signaling = pathways.show, vertex.receiver = vertex.receiver, layout = "hierarchy")
```
```{r ch1, echo = F}
# Chord diagram
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "chord")
```
```{r cont1, echo = F}
par(mfrow=c(1,1))
netVisual_heatmap(cellchat, signaling = pathways.show, color.heatmap = "Reds")
cellchat.C <- cellchat
pairLR.CCL <- extractEnrichedLR(cellchat, signaling = pathways.show, geneLR.return = FALSE)
LR.show <- pairLR.CCL[1,]
netAnalysis_contribution(cellchat, signaling = pathways.show)
netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, vertex.receiver = vertex.receiver, layout = "hierarchy")
```
```{r, echo = F}
netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, layout = "circle")
```
```{r multiple_LR1, echo = F}
# show all the significant interactions (L-R pairs) from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use')
netVisual_bubble(cellchat, sources.use = c(9), targets.use = c(2,5,6), remove.isolate = FALSE)
#> Comparing communications on a single object
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
netVisual_bubble(cellchat, sources.use = c(9), targets.use = c(2, 5, 6, 8), signaling = pathways.show, remove.isolate = FALSE)
#> Comparing communications on a single object
```
```{r chord1, echo = F}
# show all the significant interactions (L-R pairs) from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use')
# show all the interactions sending from Inflam.FIB
netVisual_chord_gene(cellchat, sources.use = c(9), targets.use =c(2,5,6), lab.cex = 0.5,legend.pos.y = 30)
# show all the interactions received by Inflam.DC
netVisual_chord_gene(cellchat, sources.use = c(9), targets.use = c(2,5,6), legend.pos.x = 15)
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
netVisual_chord_gene(cellchat, sources.use = c(9), targets.use = c(2,5,6), signaling = c("CCL", "CXCL"),legend.pos.x = 8)
#> Note: The second link end is drawn out of sector 'CXCR4 '.
#> Note: The first link end is drawn out of sector 'CXCL12 '.
```
### Plot the signaling gene expression distribution using violin/dot plot
```{r violins1, echo = F}
plotGeneExpression(cellchat, signaling = pathways.show, enriched.only = T)
#> Registered S3 method overwritten by 'spatstat':
#> method from
#> print.boxx cli
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
```
### Part IV: Systems analysis of cell-cell communication network
```{r sys1, echo = F}
# Compute the network centrality scores
cellchat <- netAnalysis_computeCentrality(cellchat, slot.name = "netP") # the slot 'netP' means the inferred intercellular communication network of signaling pathways
# Visualize the computed centrality scores using heatmap, allowing ready identification of major signaling roles of cell groups
netAnalysis_signalingRole_network(cellchat, signaling = pathways.show, width = 8, height = 2.5, font.size = 10)
```
```{r dom1, echo = F}
#Visualize the dominant senders (sources) and receivers (targets) in a 2D space
#We also provide another intutive way to visualize the dominant senders (sources) and receivers (targets) in a 2D space using scatter plot.
# Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
gg1 <- netAnalysis_signalingRole_scatter(cellchat)
#> Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
# Signaling role analysis on the cell-cell communication networks of interest
gg2 <- netAnalysis_signalingRole_scatter(cellchat, signaling = c("CXCL", "CCL"))
#> Signaling role analysis on the cell-cell communication network from user's input
gg1 + gg2
```
```{r cont_1, echo = F}
# Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
ht1 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "outgoing")
ht2 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "incoming")
ht1 + ht2
# Signaling role analysis on the cell-cell communication networks of interest
ht <- netAnalysis_signalingRole_heatmap(cellchat, signaling = c("CXCL", "CCL"))
ht
```
```{r patterns1, echo = F}
CellChat::selectK(cellchat, pattern = "outgoing")
nPatterns = 3
cellchat <- identifyCommunicationPatterns(cellchat, pattern = "outgoing", k = nPatterns)
# river plot
netAnalysis_river(cellchat, pattern = "outgoing")
#> Please make sure you have load `library(ggalluvial)` when running this function
# dot plot
netAnalysis_dot(cellchat, pattern = "outgoing")
cellchat.C <- cellchat
```
### Condition 2: AZD
```{r show_cond2, echo = F}
# Pick a condition
# BNT162b2 or AZD1222 or Ctrl
cellchat <- readRDS("~/Documents/charite/Sophia/cellchat_7h_AZD.rds")
cellchat <- computeCommunProbPathway(cellchat)
cellchat@netP$pathways
```
```{r CCC_signaling2, echo = F}
#Infer the cell-cell communication at a signaling pathway level
#CellChat computes the communication probability on signaling pathway level by summarizing the communication probabilities of all ligands-receptors interactions associated with each signaling pathway.
#NB: The inferred intercellular communication network of each ligand-receptor pair and each signaling pathway is stored in the slot ‘net’ and ‘netP’, respectively.
cellchat <- aggregateNet(cellchat)
pathways.show <- c("CCL")
pathways.show <- cellchat@netP$pathways
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= F, title.name = "Number of interactions")
netVisual_circle(cellchat@net$weight, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")
mat <- cellchat@net$weight
par(mfrow = c(3,4), xpd=TRUE)
for (i in 1:nrow(mat)) {
mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat))
mat2[i, ] <- mat[i, ]
netVisual_circle(mat2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i])
}
# Hierarchy plot
# Here we define `vertex.receive` so that the left portion of the hierarchy plot shows signaling to fibroblast and the right portion shows signaling to immune cells
vertex.receiver = seq(1,4) # a numeric vector.
netVisual_aggregate(cellchat, signaling = pathways.show, vertex.receiver = vertex.receiver, layout = "hierarchy")
```
```{r ch2, echo = F}
# Chord diagram
par(mfrow=c((length(pathways.show)/3), 3))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "chord")
```
```{r cont2, echo = F}
par(mfrow=c(1,1))
netVisual_heatmap(cellchat, signaling = pathways.show, color.heatmap = "Reds")
cellchat.A <- cellchat
pairLR.CCL <- extractEnrichedLR(cellchat, signaling = pathways.show, geneLR.return = TRUE)
LR.show <- pairLR.CCL[1,]
netAnalysis_contribution(cellchat, signaling = pathways.show, font.size = 4, return.data = T)
netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, vertex.receiver = vertex.receiver, layout = "circle")
```
```{r, echo = F}
netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, layout = "circle")
```
```{r multiple_LR2, echo = F}
# show all the significant interactions (L-R pairs) from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use')
netVisual_bubble(cellchat, sources.use = c(9), targets.use = c(2,5,6), remove.isolate = FALSE)
#> Comparing communications on a single object
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
netVisual_bubble(cellchat, sources.use = c(9), targets.use = c(2, 5, 6, 8), signaling = pathways.show, remove.isolate = FALSE)
#> Comparing communications on a single object
```
```{r chord2, echo = F}
# show all the significant interactions (L-R pairs) from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use')
# show all the interactions sending from Inflam.FIB
#netVisual_chord_gene(cellchat, sources.use = c(9), targets.use =c(5,6), lab.cex = 0.5,legend.pos.y = 30)
# show all the interactions received by Inflam.DC
#netVisual_chord_gene(cellchat, sources.use = c(9), targets.use = c(2,5,6), legend.pos.x = 15)
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
netVisual_chord_gene(cellchat, sources.use = c(9), targets.use = c(2,5,6), signaling = c("CCL", "CXCL"),legend.pos.x = 8)
#> Note: The second link end is drawn out of sector 'CXCR4 '.
#> Note: The first link end is drawn out of sector 'CXCL12 '.
```
### Plot the signaling gene expression distribution using violin/dot plot
```{r violins2, echo = F}
plotGeneExpression(cellchat, signaling = "CCL", enriched.only = T)
#> Registered S3 method overwritten by 'spatstat':
#> method from
#> print.boxx cli
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
```
### Part IV: Systems analysis of cell-cell communication network
```{r sys2, echo = F}
# Compute the network centrality scores
cellchat <- netAnalysis_computeCentrality(cellchat, slot.name = "netP") # the slot 'netP' means the inferred intercellular communication network of signaling pathways
# Visualize the computed centrality scores using heatmap, allowing ready identification of major signaling roles of cell groups
netAnalysis_signalingRole_network(cellchat, signaling = pathways.show, width = 8, height = 2.5, font.size = 10)
```
```{r dom2, echo = F}
#Visualize the dominant senders (sources) and receivers (targets) in a 2D space
#We also provide another intutive way to visualize the dominant senders (sources) and receivers (targets) in a 2D space using scatter plot.
# Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
gg1 <- netAnalysis_signalingRole_scatter(cellchat)
#> Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
# Signaling role analysis on the cell-cell communication networks of interest
gg2 <- netAnalysis_signalingRole_scatter(cellchat, signaling = c("CXCL", "CCL"))
#> Signaling role analysis on the cell-cell communication network from user's input
gg1 + gg2
```
```{r cont_2, echo = F}
# Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
ht1 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "outgoing")
ht2 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "incoming")
ht1 + ht2
# Signaling role analysis on the cell-cell communication networks of interest
ht <- netAnalysis_signalingRole_heatmap(cellchat, signaling = c("CXCL", "CCL"))
ht
```
```{r patterns2, echo = F}
selectK(cellchat, pattern = "outgoing")
nPatterns = 3
cellchat <- identifyCommunicationPatterns(cellchat, pattern = "outgoing", k = nPatterns)
# river plot
netAnalysis_river(cellchat, pattern = "outgoing")
#> Please make sure you have load `library(ggalluvial)` when running this function
# dot plot
netAnalysis_dot(cellchat, pattern = "outgoing")
```
```{r CCC_signaling2.5, scho = F}
#Infer the cell-cell communication at a signaling pathway level
#CellChat computes the communication probability on signaling pathway level by summarizing the communication probabilities of all ligands-receptors interactions associated with each signaling pathway.
#NB: The inferred intercellular communication network of each ligand-receptor pair and each signaling pathway is stored in the slot ‘net’ and ‘netP’, respectively.
pathways.show <- c("IFN-I")
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= F, title.name = "Number of interactions")
netVisual_circle(cellchat@net$weight, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")
mat <- cellchat@net$weight
par(mfrow = c(3,4), xpd=TRUE)
for (i in 1:nrow(mat)) {
mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat))
mat2[i, ] <- mat[i, ]
netVisual_circle(mat2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i])
}
# Hierarchy plot
# Here we define `vertex.receive` so that the left portion of the hierarchy plot shows signaling to fibroblast and the right portion shows signaling to immune cells
vertex.receiver = seq(1,4) # a numeric vector.
netVisual_aggregate(cellchat, signaling = pathways.show, vertex.receiver = vertex.receiver, layout = "hierarchy")
```
```{r ch2.5, echo = F}
# Chord diagram
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "chord")
```
```{r cont_2.5, echo = F}
par(mfrow=c(1,1))
netVisual_heatmap(cellchat, signaling = pathways.show, color.heatmap = "Reds")
pairLR.IFN <- extractEnrichedLR(cellchat, signaling = pathways.show, geneLR.return = FALSE)
netAnalysis_contribution(cellchat, signaling = pathways.show)
LR.show <- pairLR.IFN[1,]
netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, vertex.receiver = vertex.receiver, layout = "hierarchy")
```
```{r, echo = F}
netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, layout = "circle")
```
```{r multiple_LR2.5, echo = F}
# show all the significant interactions (L-R pairs) from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use')
netVisual_bubble(cellchat, sources.use = c(9), targets.use = c(2,5,6), remove.isolate = FALSE)
#> Comparing communications on a single object
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
netVisual_bubble(cellchat, sources.use = c(9), targets.use = c(2, 5, 6, 8), signaling = pathways.show, remove.isolate = FALSE)
#> Comparing communications on a single object
```
```{r chord2.5, echo = F}
# show all the significant interactions (L-R pairs) from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use')
# show all the interactions sending from Inflam.FIB
netVisual_chord_gene(cellchat, sources.use = c(9), targets.use =c(2,5,6), lab.cex = 0.5,legend.pos.y = 30)
# show all the interactions received by Inflam.DC
netVisual_chord_gene(cellchat, sources.use = c(9), targets.use = c(2,5,6), legend.pos.x = 15)
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
netVisual_chord_gene(cellchat, sources.use = c(9), targets.use = c(2,5,6), signaling = c("IFN-I"),legend.pos.x = 8)
#> Note: The second link end is drawn out of sector 'CXCR4 '.
#> Note: The first link end is drawn out of sector 'CXCL12 '.
```
### Plot the signaling gene expression distribution using violin/dot plot
```{r violins2.5, echo = F}
plotGeneExpression(cellchat, signaling = "IFN-I", enriched.only = T)
#> Registered S3 method overwritten by 'spatstat':
#> method from
#> print.boxx cli
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
```
### Part IV: Systems analysis of cell-cell communication network
```{r sys2.5, echo = F}
# Compute the network centrality scores
cellchat <- netAnalysis_computeCentrality(cellchat, slot.name = "netP") # the slot 'netP' means the inferred intercellular communication network of signaling pathways
# Visualize the computed centrality scores using heatmap, allowing ready identification of major signaling roles of cell groups
netAnalysis_signalingRole_network(cellchat, signaling = pathways.show, width = 8, height = 2.5, font.size = 10)
```
```{r dom2.5, echo = F}
#Visualize the dominant senders (sources) and receivers (targets) in a 2D space
#We also provide another intutive way to visualize the dominant senders (sources) and receivers (targets) in a 2D space using scatter plot.
# Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
gg1 <- netAnalysis_signalingRole_scatter(cellchat)
#> Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
# Signaling role analysis on the cell-cell communication networks of interest
gg2 <- netAnalysis_signalingRole_scatter(cellchat, signaling = c("IFN-I"))
#> Signaling role analysis on the cell-cell communication network from user's input
gg1 + gg2
```
<!-- ```{r cont2.5, echo = F} -->
<!-- # Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways -->
<!-- ht1 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "outgoing") -->
<!-- ht2 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "incoming") -->
<!-- ht1 + ht2 -->
<!-- # Signaling role analysis on the cell-cell communication networks of interest -->
<!-- ht <- netAnalysis_signalingRole_heatmap(cellchat, signaling = c("IFN-I")) -->
<!-- ht -->
<!-- ``` -->
```{r patterns2.5, echo = F}
selectK(cellchat, pattern = "outgoing")
nPatterns = 3
cellchat <- identifyCommunicationPatterns(cellchat, pattern = "outgoing", k = nPatterns)
# river plot
netAnalysis_river(cellchat, pattern = "outgoing")
#> Please make sure you have load `library(ggalluvial)` when running this function
# dot plot
netAnalysis_dot(cellchat, pattern = "outgoing")
```
### Condition 3: BNT
```{r show_cond3, echo = F}
# Pick a condition
# BNT162b2 or AZD1222 or Ctrl
cellchat <- readRDS("~/Documents/charite/Sophia/cellchat_7h_BNT.rds")
cellchat <- computeCommunProbPathway(cellchat)
cellchat@netP$pathways
```
```{r CCC_signaling3, echo = F}
#Infer the cell-cell communication at a signaling pathway level
#CellChat computes the communication probability on signaling pathway level by summarizing the communication probabilities of all ligands-receptors interactions associated with each signaling pathway.
#NB: The inferred intercellular communication network of each ligand-receptor pair and each signaling pathway is stored in the slot ‘net’ and ‘netP’, respectively.
cellchat <- aggregateNet(cellchat)
pathways.show <- c("CCL")
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= F, title.name = "Number of interactions")
netVisual_circle(cellchat@net$weight, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")
mat <- cellchat@net$weight
par(mfrow = c(3,4), xpd=TRUE)
for (i in 1:nrow(mat)) {
mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat))
mat2[i, ] <- mat[i, ]
netVisual_circle(mat2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i])
}
# Hierarchy plot
# Here we define `vertex.receive` so that the left portion of the hierarchy plot shows signaling to fibroblast and the right portion shows signaling to immune cells
vertex.receiver = seq(1,4) # a numeric vector.
netVisual_aggregate(cellchat, signaling = pathways.show, vertex.receiver = vertex.receiver, layout = "hierarchy")
```
```{r ch5, echo = F}
# Chord diagram
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "chord")
```
```{r cont3, echo = F}
par(mfrow=c(1,1))
netVisual_heatmap(cellchat, signaling = pathways.show, color.heatmap = "Reds")
cellchat.B <- cellchat
pairLR.CCL <- extractEnrichedLR(cellchat, signaling = pathways.show, geneLR.return = FALSE)
LR.show = pairLR.CCL[1,]
netAnalysis_contribution(cellchat, signaling = pathways.show)
netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, vertex.receiver = vertex.receiver, layout = "hierarchy")
```
```{r, echo = F}
netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, layout = "circle")
```
```{r multiple_LR3, echo = F}
# show all the significant interactions (L-R pairs) from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use')
netVisual_bubble(cellchat, sources.use = c(2), targets.use = c(2,5,6), remove.isolate = FALSE)
#> Comparing communications on a single object
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
netVisual_bubble(cellchat, sources.use = c(2), targets.use = c(2, 5, 6, 8), signaling = pathways.show, remove.isolate = FALSE)
#> Comparing communications on a single object
```
```{r chord3, echo = F}
# show all the significant interactions (L-R pairs) from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use')
# show all the interactions sending from Inflam.FIB
netVisual_chord_gene(cellchat, sources.use = c(2), targets.use =c(5,6), lab.cex = 0.5,legend.pos.y = 30)
# show all the interactions received by Inflam.DC
netVisual_chord_gene(cellchat, sources.use = c(2), targets.use = c(5,6), legend.pos.x = 15)
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
netVisual_chord_gene(cellchat, sources.use = c(2), targets.use = c(5,6), signaling = c("CCL", "CXCL"),legend.pos.x = 8)
#> Note: The second link end is drawn out of sector 'CXCR4 '.
#> Note: The first link end is drawn out of sector 'CXCL12 '.
```
### Plot the signaling gene expression distribution using violin/dot plot
```{r violins3, echo = F}
plotGeneExpression(cellchat, signaling = "CCL", enriched.only = T)
#> Registered S3 method overwritten by 'spatstat':
#> method from
#> print.boxx cli
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
```
### Part IV: Systems analysis of cell-cell communication network
```{r sys3, echo = F}
# Compute the network centrality scores
cellchat <- netAnalysis_computeCentrality(cellchat, slot.name = "netP") # the slot 'netP' means the inferred intercellular communication network of signaling pathways
# Visualize the computed centrality scores using heatmap, allowing ready identification of major signaling roles of cell groups
netAnalysis_signalingRole_network(cellchat, signaling = pathways.show, width = 8, height = 2.5, font.size = 10)
```
```{r dom3, echo = F}
#Visualize the dominant senders (sources) and receivers (targets) in a 2D space
#We also provide another intutive way to visualize the dominant senders (sources) and receivers (targets) in a 2D space using scatter plot.
# Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
gg1 <- netAnalysis_signalingRole_scatter(cellchat)
#> Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
# Signaling role analysis on the cell-cell communication networks of interest
gg2 <- netAnalysis_signalingRole_scatter(cellchat, signaling = c("CXCL", "CCL"))
#> Signaling role analysis on the cell-cell communication network from user's input
gg1 + gg2
```
```{r cont_3, echo = F}
# Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
ht1 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "outgoing")
ht2 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "incoming")
ht1 + ht2
# Signaling role analysis on the cell-cell communication networks of interest
ht <- netAnalysis_signalingRole_heatmap(cellchat, signaling = c("CXCL", "CCL"))
ht
```
```{r patterns3, echo = F}
selectK(cellchat, pattern = "outgoing")
nPatterns = 3
cellchat <- identifyCommunicationPatterns(cellchat, pattern = "outgoing", k = nPatterns)
# river plot
netAnalysis_river(cellchat, pattern = "outgoing")
#> Please make sure you have load `library(ggalluvial)` when running this function
# dot plot
netAnalysis_dot(cellchat, pattern = "outgoing")
```
### Common pathways in the three conditions
```{r intersections, echo = F, fig.height=18}
CTR.p <- data.frame(Pathway = cellchat.C@netP$pathways) %>%
mutate(Ctrl = rep(1, length(cellchat.C@netP$pathways)))
AZD.p <- data.frame(Pathway = cellchat.A@netP$pathways) %>%
mutate(AZD = rep(1, length(cellchat.A@netP$pathways)))
BNT.p <- data.frame(Pathway = cellchat.B@netP$pathways) %>%
mutate(BNT = rep(1, length(cellchat.B@netP$pathways)))
heatmap.counter <-
plyr::join_all(list(CTR.p, AZD.p, BNT.p), by='Pathway', type='full') %>%
mutate_all(~replace(., is.na(.), 0)) %>%
tibble::column_to_rownames("Pathway")
#par(cex.main = 2)
#pheatmap(heatmap.counter, cluster_rows = F, cluster_cols = F, scale = "none", cellwidth = 2, cellheight = 2, legend = F, annotation_legend = F, main = "Enriched pathways at 18 hours", fontsize = 5 )
#{heatmap(as.matrix(heatmap.counter), Colv = NA, Rowv = NA,scale = "none", cexCol = 1, bty = "o", col = colorRampPalette(brewer.pal(3,"Blues"))(3), main = "Enriched pathways at 18 hours") ; legend(x="bottomright", legend=c("Absent", "Present"), fill = colorRampPalette(brewer.pal(3, "Blues"))(3), xjust = 1, cex = 0.7)}
col_fun = colorRamp2(c(0, 1), c("blue", "red"))
at = seq(0, 1, by = 1)
lgd = Legend(at = at, title = "Presence", legend_gp = gpar(fill = col_fun(at)))
hm <- Heatmap(as.matrix(heatmap.counter), width = ncol(heatmap.counter)*unit(5, "mm"),
height = nrow(heatmap.counter)*unit(5, "mm"),
cluster_rows = T, show_row_dend = F, show_column_dend = F,
show_heatmap_legend = F, row_names_gp = grid::gpar(fontsize = 7), column_names_gp = grid::gpar(fontsize = 7))
draw(hm, annotation_legend_list = lgd, annotation_legend_side = "right")
```