-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCellChat_CarotidvsFemoral_Scaled.Rmd
105 lines (92 loc) · 3.61 KB
/
CellChat_CarotidvsFemoral_Scaled.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
---
title: "CellChat_CarotidvsFemoral_Scaled"
author: "Daniel Lee"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: pdf_document
---
```{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}
library(CellChat)
library(Seurat)
```
## Read CellChat Objects
```{r}
# set the working directory for retrieving CellChat objects
setwd("/Volumes/biologos/Bioinformatics/Using-CellChat-for-Ligand-Receptor-Network-Analysis/CellChatObjects")
# Save CellChat objects
# saveRDS(cellchat_carotid, file = "carotid_cellchat.rds")
# saveRDS(cellchat_femoral, file = "femoral_cellchat.rds")
# Recall CellChat objects
cellchat_carotid <- readRDS("carotid_cellchat.rds")
cellchat_femoral <- readRDS("femoral_cellchat.rds")
cellchat_carotid <- updateCellChat(cellchat_carotid)
cellchat_femoral <- updateCellChat(cellchat_femoral)
```
```{r}
object.list <- list(carotid=cellchat_carotid, femoral=cellchat_femoral)
cellchat <- mergeCellChat(object.list, add.names = names(object.list), cell.prefix = TRUE)
```
```{r}
gg1 <- netVisual_heatmap(cellchat)
#> Do heatmap based on a merged object
gg2 <- netVisual_heatmap(cellchat, measure = "weight")
#> Do heatmap based on a merged object
gg1 + gg2
```
```{r}
# Compute and visualize the pathway distance in the learned joint manifold
rankSimilarity(cellchat, type = "functional")
rankNet(cellchat, mode = "comparison", stacked = T, do.stat = TRUE)
```
```{r}
library(ComplexHeatmap)
i = 1
# combining all the identified signaling pathways from different datasets
pathway.union <- union(object.list[[i]]@netP$pathways, object.list[[i+1]]@netP$pathways)
ht1 = netAnalysis_signalingRole_heatmap(object.list[[i]], pattern = "incoming", signaling = pathway.union, title = names(object.list)[i], width = 5, height = 6)
ht2 = netAnalysis_signalingRole_heatmap(object.list[[i+1]], pattern = "incoming", signaling = pathway.union, title = names(object.list)[i+1], width = 5, height = 6)
draw(ht1 + ht2, ht_gap = unit(0.5, "cm"))
```
```{r}
library(ComplexHeatmap)
i = 1
# combining all the identified signaling pathways from different datasets
pathway.union <- union(object.list[[i]]@netP$pathways, object.list[[i+1]]@netP$pathways)
ht3 = netAnalysis_signalingRole_heatmap(object.list[[i]], pattern = "outgoing", signaling = pathway.union, title = names(object.list)[i], width = 5, height = 6)
ht4 = netAnalysis_signalingRole_heatmap(object.list[[i+1]], pattern = "outgoing", signaling = pathway.union, title = names(object.list)[i+1], width = 5, height = 6)
draw(ht3 + ht4, ht_gap = unit(0.5, "cm"))
```
```{r}
# Set the working directory
setwd("/Volumes/biologos/Bioinformatics/Using-CellChat-for-Ligand-Receptor-Network-Analysis/Visuals/Comparison")
# png("BubblePlot.png", width=12, height=5, units="in", res=600)
# bubble <- netVisual_bubble(cellchat, sources.use = c(6,7,9), targets.use = c(1,3,4,8,10), comparison = c(1, 2), remove.isolate = TRUE, angle.x=45, thresh = 0.05, font.size = 7)
# print(bubble)
# dev.off()
png("BubblePlot-Refined.png", width=7, height=5, units="in", res=3000)
bubble_refined <- netVisual_bubble(cellchat, sources.use = 7, targets.use = c(1,3,4,8,10), comparison = c(1, 2), remove.isolate = TRUE, angle.x=45, thresh = 0.05, font.size = 5.5)
print(bubble_refined)
dev.off()
```
```{r, echo=F}
## DO NOT DELETE THIS BLOCK!
Sys.info()
sessionInfo()
```