scripts: Add comparison to other datasets

This commit is contained in:
Elias Projahn 2024-09-30 21:15:46 +02:00
parent ed796853af
commit 1ed42c53aa

132
scripts/comparison.R Normal file
View file

@ -0,0 +1,132 @@
library(data.table)
library(here)
i_am("scripts/comparison.R")
w2000 <- scan(here("scripts/input/datasets/warrington_2000.txt"), character())
z2008 <- scan(here("scripts/input/datasets/zhu_2008.txt"), character())
e2013 <- scan(here("scripts/input/datasets/eisenberg_2013.txt"), character())
c2011 <- scan(here("scripts/input/datasets/chang_2011.txt"), character())
j2022 <- scan(here("scripts/input/datasets/joshi_2022.txt"), character())
datasets <- list(
"Warrington 2000" = w2000,
"Zhu 2008" = z2008,
"Eisenberg 2013" = e2013,
"Chang 2011" = c2011,
"Joshi 2022" = j2022
)
ranking_gtex <- ubigen::rank_genes(ubigen::gtex_all)
ranking_cmap <- ubigen::rank_genes(ubigen::cmap)
data <- merge(
ranking_gtex[, .(gene, score, percentile)],
ranking_cmap[, .(gene, score, percentile)],
by = "gene",
suffixes = c(x = "_gtex", y = "_cmap")
)
data[, count := 0]
for (dataset in datasets) {
data[gene %chin% dataset, count := count + 1]
}
threshold_gtex <- data[percentile_gtex >= 0.95, min(score_gtex)]
threshold_cmap <- data[percentile_cmap >= 0.95, min(score_cmap)]
fig <- plotly::plot_ly() |>
plotly::add_markers(
data = data,
x = ~score_gtex,
y = ~score_cmap,
color = ~count,
colors = c("#7d19bf", "#ff7f2a"),
marker = list(
size = 4,
opacity = 0.8
),
cliponaxis = FALSE
) |>
plotly::layout(
xaxis = list(
title = "Ranking based on GTEx",
range = c(0, 1)
),
yaxis = list(
title = "Ranking based on CMap",
range = c(0, 1)
),
annotations = list(
list(
text = "95%",
x = threshold_gtex,
y = 1,
xshift = 2,
yshift = 3,
yref = "paper",
xanchor = "left",
yanchor = "top",
showarrow = FALSE
),
list(
text = "95%",
x = 1,
y = threshold_cmap,
yshift = 2,
xref = "paper",
xanchor = "right",
yanchor = "bottom",
showarrow = FALSE
)
),
shapes = list(
list(
type = "line",
y0 = 0,
y1 = 1,
yref = "paper",
x0 = threshold_gtex,
x1 = threshold_gtex,
line = list(
color = "#00000080",
opacity = 0.5,
width = 1,
dash = "dot"
)
),
list(
type = "line",
y0 = threshold_cmap,
y1 = threshold_cmap,
x0 = 0,
x1 = 1,
xref = "paper",
line = list(
color = "#00000080",
width = 1,
opacity = 0.5,
dash = "dot"
)
)
),
font = list(size = 8),
margin = list(
pad = 2,
l = 36,
r = 0,
t = 0,
b = 36
)
) |>
plotly::hide_legend() |>
plotly::hide_colorbar()
plotly::save_image(
fig,
file = here("scripts/output/comparison.svg"),
width = 6.27 * 72,
height = 6.27 * 72,
scale = 96 / 72
)