-
Notifications
You must be signed in to change notification settings - Fork 17
/
DLPFC_comp.R
executable file
·122 lines (95 loc) · 6.85 KB
/
DLPFC_comp.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
library(mclust)
library(ggplot2)
library(patchwork)
library(Seurat)
library(mclust)
options(bitmapType = 'cairo')
args <- commandArgs(trailingOnly = TRUE)
sample <- args[1]
sp_data <- readRDS(file.path('./output/DLPFC/', sample, '/Seurat/Seurat_final.rds'))
##### SpatialDimPlot
metadata <- read.table(file.path('./data/DLPFC/', sample, 'metadata.tsv'), sep='\t', header=TRUE)
seurat_cluster <- read.table(file.path('./output/DLPFC/', sample, '/Seurat/metadata.tsv'), sep='\t', header=TRUE)
Giotto_cluster <- read.table(file.path('./output/DLPFC/', sample, '/Giotto/metadata.tsv'), sep='\t', header=TRUE)
row.names(Giotto_cluster) <- Giotto_cluster$cell_ID
stLearn_cluster <- read.table(file.path('./output/DLPFC/', sample, '/stLearn/metadata.tsv'), sep='\t', header=TRUE)
spaGCN_cluster <- read.table(file.path('./output/DLPFC/', sample, '/SpaGCN/metadata.tsv'), sep='\t', header=TRUE)
BayesSpace_cluster <- read.table(file.path('./output/DLPFC/', sample, '/BayesSpace/metadata.tsv'), sep='\t', header=TRUE)
DeepST_cluster <- read.table(file.path('./output/DLPFC/', sample, '/DeepST/metadata.tsv'), sep='\t', header=TRUE, row.names=1)
STAGATE_cluster <- read.table(file.path('./output/DLPFC/', sample, '/STAGATE/metadata.tsv'), sep='\t', header=TRUE, row.names=1)
sedr_cluster <- read.table(file.path('./output/DLPFC/', sample, '/SEDR/metadata.tsv'), sep='\t', header=TRUE, row.names =1)
truth <- as.factor(metadata$layer_guess)
truth <- factor(truth, levels=c('WM', 'nan', 'Layer6', 'Layer5', 'Layer4', 'Layer3', 'Layer2', 'Layer1'))
sp_data <- AddMetaData(sp_data, truth, col.name = 'layer_guess')
sp_data <- AddMetaData(sp_data, seurat_cluster$seurat_clusters, col.name = 'Seurat')
sp_data <- AddMetaData(sp_data, Giotto_cluster[, 'HMRF_cluster', drop=F], col.name = 'Giotto')
sp_data <- AddMetaData(sp_data, stLearn_cluster$X_pca_kmeans, col.name = 'stLearn')
sp_data <- AddMetaData(sp_data, spaGCN_cluster$refined_pred, col.name = 'SpaGCN')
sp_data <- AddMetaData(sp_data, BayesSpace_cluster$spatial.cluster, col.name = 'BayesSpace')
sp_data <- AddMetaData(sp_data, DeepST_cluster$DeepST, col.name = 'DeepST')
sp_data <- AddMetaData(sp_data, STAGATE_cluster$mclust, col.name = 'STAGATE')
sp_data <- AddMetaData(sp_data, sedr_cluster$SEDR, col.name = 'SEDR')
SEDR_ARI = adjustedRandIndex([email protected]$layer_guess, [email protected]$SEDR)
Seurat_ARI = adjustedRandIndex([email protected]$layer_guess, [email protected]$Seurat)
SpaGCN_ARI = adjustedRandIndex([email protected]$layer_guess, [email protected]$SpaGCN)
BayesSpace_ARI = adjustedRandIndex([email protected]$layer_guess, [email protected]$BayesSpace)
Giotto_ARI = adjustedRandIndex([email protected]$layer_guess, [email protected]$Giotto)
stLearn_ARI = adjustedRandIndex([email protected]$layer_guess, [email protected]$stLearn)
df_clusters <- data.frame(
layer_guess = [email protected]$layer_guess,
Seurat = as.factor([email protected]$Seurat),
Giotto = as.factor([email protected]$Giotto),
stLearn = as.factor([email protected]$stLearn)
SpaGCN = as.factor([email protected]$SpaGCN),
BayesSpace = as.factor([email protected]$BayesSpace),
DeepST = as.factor(sp_data@metadata$DeepST),
STAGATE = as.factor(sp_data@metadata$STAGATE),
SEDR = as.factor([email protected]$SEDR),
)
## plot
df <- sp_data@images$slice1@coordinates
df <- cbind(df, df_clusters)
p0 <- ggplot(df, aes(imagecol, imagerow, color=layer_guess)) + geom_point(stroke=0, size=1.5) + ggtitle('ground_truth') +
coord_fixed() + scale_y_reverse() + theme_void() + viridis::scale_color_viridis(option="plasma", discrete = T) +
theme(plot.title = element_text(hjust=0.5),
legend.title = element_blank())
p1 <- ggplot(df, aes(imagecol, imagerow, color=Seurat)) + geom_point(stroke=0, size=1.1) + ggtitle(paste('Seurat: ARI=', round(Seurat_ARI, 3))) +
coord_fixed() + scale_y_reverse() + theme_void() + viridis::scale_color_viridis(option="plasma", discrete = T)+
theme(plot.title = element_text(hjust=0.5),
legend.title = element_blank())
p2 <- ggplot(df, aes(imagecol, imagerow, color=Giotto)) + geom_point(stroke=0, size=1.1) + ggtitle(paste('Giotto: ARI=', round(Giotto_ARI, 3))) +
coord_fixed() + scale_y_reverse() + theme_void() + viridis::scale_color_viridis(option="plasma", discrete = T)+
theme(plot.title = element_text(hjust=0.5),
legend.title = element_blank())
p3 <- ggplot(df, aes(imagecol, imagerow, color=stLearn)) + geom_point(stroke=0, size=1.1) + ggtitle(paste('stLearn: ARI=', round(stLearn_ARI, 3))) +
coord_fixed() + scale_y_reverse() + theme_void() + viridis::scale_color_viridis(option="plasma", discrete = T)+
theme(plot.title = element_text(hjust=0.5),
legend.title = element_blank())
p4 <- ggplot(df, aes(imagecol, imagerow, color=SpaGCN)) + geom_point(stroke=0, size=1.1) + ggtitle(paste('SpaGCN: ARI=', round(SpaGCN_ARI, 3))) +
coord_fixed() + scale_y_reverse() + theme_void() + viridis::scale_color_viridis(option="plasma", discrete = T)+
theme(plot.title = element_text(hjust=0.5),
legend.title = element_blank())
p5 <- ggplot(df, aes(imagecol, imagerow, color=BayesSpace)) + geom_point(stroke=0, size=1.1) + ggtitle(paste('BayesSpace: ARI=', round(BayesSpace_ARI, 3))) +
coord_fixed() + scale_y_reverse() + theme_void() + viridis::scale_color_viridis(option="plasma", discrete = T)+
theme(plot.title = element_text(hjust=0.5),
legend.title = element_blank())
p7 <- ggplot(df, aes(imagecol, imagerow, color=STAGATE)) + geom_point(stroke=0, size=1.1) + ggtitle(paste('STAGATE: ARI=', round(STAGATE_ARI, 3))) +
coord_fixed() + scale_y_reverse() + theme_void() + viridis::scale_color_viridis(option="plasma", discrete = T)+
theme(plot.title = element_text(hjust=0.5),
legend.title = element_blank())
p6 <- ggplot(df, aes(imagecol, imagerow, color=DeepST)) + geom_point(stroke=0, size=1.1) + ggtitle(paste('DeepST: ARI=', round(DeepST_ARI, 3))) +
coord_fixed() + scale_y_reverse() + theme_void() + viridis::scale_color_viridis(option="plasma", discrete = T)+
theme(plot.title = element_text(hjust=0.5),
legend.title = element_blank())
p8 <- ggplot(df, aes(imagecol, imagerow, color=SEDR)) + geom_point(stroke=0, size=1.1) + ggtitle(paste('SEDR: ARI=', round(SEDR_ARI, 3))) +
coord_fixed() + scale_y_reverse() + theme_void() + viridis::scale_color_viridis(option="plasma", discrete = T)+
theme(plot.title = element_text(hjust=0.5),
legend.title = element_blank())
p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + plot_layout(ncol = 3, widths = c(1,1,1), heights = c(1,1,1)) & NoLegend()
dir.output <- file.path('./output/DLPFC/', sample, '/Comparison/')
if(!dir.exists(file.path(dir.output))){
dir.create(file.path(dir.output), recursive = TRUE)
}
ggsave(filename = file.path(dir.output, 'comparison.png'), width=11, height=5.5)
ggsave(filename = file.path(dir.output, 'comparison.pdf'), width=11, height=5.5)
write.table(df, file.path(dir.output, 'comparison.tsv'), sep='\t', quote=FALSE)