forked from JinmiaoChenLab/SEDR_analyses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DLPFC_comp.R
executable file
·89 lines (65 loc) · 5.25 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
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)
sedr_cluster <- read.table(file.path('../output/DLPFC/', sample, 'SEDR/metadata.tsv'), sep='\t', header=TRUE, row.names =1)
sedr_cluster$sed_labels <- sedr_cluster$leiden_fixed_clusCount
seurat_cluster <- read.table(file.path('../output/DLPFC/', sample, '/Seurat/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)
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)
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, sedr_cluster$SEDR, col.name = 'SEDR')
sp_data <- AddMetaData(sp_data, seurat_cluster$seurat_clusters, col.name = 'Seurat')
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, Giotto_cluster[, 'HMRF_cluster', drop=F], col.name = 'Giotto')
sp_data <- AddMetaData(sp_data, stLearn_cluster$X_pca_kmeans, col.name = 'stLearn')
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,
SEDR = as.factor([email protected]$SEDR),
Seurat = as.factor([email protected]$Seurat),
SpaGCN = as.factor([email protected]$SpaGCN),
BayesSpace = as.factor([email protected]$BayesSpace),
Giotto = as.factor([email protected]$Giotto),
stLearn = as.factor([email protected]$stLearn))
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.1) + ggtitle('layer_guess') +
coord_fixed() + scale_y_reverse() + theme_void() + viridis::scale_color_viridis(option="plasma", discrete = T)
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)
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)
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)
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)
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)
p6 <- 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)
p0 + p1 + p2 + p3 + p4 + p5 + p6 + plot_layout(ncol = 4, widths = c(1,1,1,1), heights = c(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)