-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8_Giotto_Communication.R
More file actions
100 lines (94 loc) · 3.93 KB
/
8_Giotto_Communication.R
File metadata and controls
100 lines (94 loc) · 3.93 KB
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
library(Giotto)
library(Seurat)
seurat_obj_A1 <- readRDS("./data/seurat_obj_A1_deconvoluted.rds")
seurat_obj_B1 <- readRDS("./data/seurat_obj_B1_deconvoluted.rds")
fromSeuratToGiotto <- function(obj){
expr_matrix <- GetAssayData(obj, assay = "Spatial", slot = "counts")
# 提取空间坐标信息
coords <- GetTissueCoordinates(obj)
giotto_obj <- createGiottoObject(expression = expr_matrix, spatial_locs = coords)
}
giotto_A1 <- fromSeuratToGiotto(seurat_obj_A1)
spatPlot(giotto_A1, show_image = FALSE, point_alpha = 0.7,
save_param = list(save_name = "spatplot_with_image"))
# create spatial network
giotto_A1 <- createSpatialNetwork(giotto_A1 ,
method = "Delaunay",
name = "Delaunay_network")
# loading lr network data(ligand-receptor)
# reference: https://zenodo.org/api/records/15168114/files/lr_network_mouse.csv/content
prop_mat <- readRDS("./data/SPOTlight_deconvolution_matrix_A1.rds")
celltype_major <- colnames(prop_mat)[max.col(prop_mat, ties.method = "first")]
cell_metadata <- pDataDT(giotto_A1)
cell_metadata[, celltype_major := celltype_major]
# add meta to giotto object
giotto_A1 <- addCellMetadata(
gobject = giotto_A1,
new_metadata = cell_metadata,
by_column = TRUE,
column_cell_ID = "cell_ID"
)
giotto_A1 <- normalizeGiotto(giotto_A1)
lr_net <- read.csv("./data/mouse_lr_network.csv")
lr_from <- lr_net$from[lr_net$from %in% rownames(giotto_A1) & lr_net$to %in% rownames(giotto_A1)]
lr_to <- lr_net$to[lr_net$from %in% rownames(giotto_A1) & lr_net$to %in% rownames(giotto_A1)]
ccc_res <- exprCellCellcom(
giotto_A1,
cluster_column = "celltype_major",
feat_set_1=lr_from,
feat_set_2=lr_to,
verbose = T
)
p <- ggplot(ccc_res[(p.adj < 0.05) & log2fc>2, ], aes(x = LR_cell_comb, y = LR_comb, size = log2fc, color = LR_cell_comb)) +
geom_point(alpha = 0.7) +
theme_minimal() +
labs(title = "Custom Cell-Cell Communication Plot",
x = "Cell Types",
y = "Ligand-Receptor") +
scale_size_continuous(range = c(1, 10))+
theme(
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)
)
ggsave("./results/Giotto_A1_cellcell_communication.tiff", p, width = 8, height = 24)
giotto_B1 <- fromSeuratToGiotto(seurat_obj_B1)
spatPlot(giotto_B1, show_image = FALSE, point_alpha = 0.7,
save_param = list(save_name = "spatplot_with_image"))
# create spatial network
giotto_B1 <- createSpatialNetwork(giotto_B1 ,
method = "Delaunay",
name = "Delaunay_network")
# loading lr network data(ligand-receptor)
# reference: https://zenodo.org/api/records/15168114/files/lr_network_mouse.csv/content
prop_mat <- readRDS("./data/SPOTlight_deconvolution_matrix_B1.rds")
celltype_major <- colnames(prop_mat)[max.col(prop_mat, ties.method = "first")]
cell_metadata <- pDataDT(giotto_B1)
cell_metadata[, celltype_major := celltype_major]
# add meta to giotto object
giotto_B1 <- addCellMetadata(
gobject = giotto_B1,
new_metadata = cell_metadata,
by_column = TRUE,
column_cell_ID = "cell_ID"
)
giotto_B1 <- normalizeGiotto(giotto_B1)
lr_net <- read.csv("./data/mouse_lr_network.csv")
lr_from <- lr_net$from[lr_net$from %in% rownames(giotto_B1) & lr_net$to %in% rownames(giotto_B1)]
lr_to <- lr_net$to[lr_net$from %in% rownames(giotto_B1) & lr_net$to %in% rownames(giotto_B1)]
ccc_res <- exprCellCellcom(
giotto_B1,
cluster_column = "celltype_major",
feat_set_1=lr_from,
feat_set_2=lr_to,
verbose = T
)
p <- ggplot(ccc_res[(p.adj < 0.05) & log2fc>1, ], aes(x = LR_cell_comb, y = LR_comb, size = log2fc, color = LR_cell_comb)) +
geom_point(alpha = 0.7) +
theme_minimal() +
labs(title = "Custom Cell-Cell Communication Plot",
x = "Cell Types",
y = "Ligand-Receptor") +
scale_size_continuous(range = c(1, 10))+
theme(
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)
)
ggsave("./results/Giotto_B1_cellcell_communication.tiff", p, width = 14, height = 24)