Skip to content

Commit

Permalink
feat: static volcano plots
Browse files Browse the repository at this point in the history
  • Loading branch information
ESCRI11 committed Aug 29, 2024
1 parent f60aa03 commit 07b34fa
Show file tree
Hide file tree
Showing 4 changed files with 353 additions and 97 deletions.
108 changes: 87 additions & 21 deletions components/board.enrichment/R/enrichment_plot_volcano.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ enrichment_plot_volcano_ui <- function(
height = height,
width = width,
caption = caption,
plotlib = "plotly",
plotlib2 = "plotly",
download.fmt = c("png", "pdf")
plotlib = c("plotly", "ggplot"),
download.fmt = c("png", "pdf"),
cards = TRUE,
card_names = c("dynamic", "static")
)
}

Expand All @@ -43,7 +44,7 @@ enrichment_plot_volcano_server <- function(id,
geneDetails,
watermark = FALSE) {
moduleServer(id, function(input, output, session) {
volcano.RENDER <- shiny::reactive({
plot_data <- shiny::reactive({
par(mfrow = c(1, 1), mgp = c(1.2, 0.4, 0), oma = c(0, 0, 0, 0.4))
par(mar = subplot.MAR)

Expand Down Expand Up @@ -86,17 +87,32 @@ enrichment_plot_volcano_server <- function(id,
lfc <- 0.20
lfc <- as.numeric(gs_lfc())

playbase::plotlyVolcano(
return(list(
x = fx,
y = -log10(qval),
names = fc.genes,
label.names = fc.genes,
fc.genes = fc.genes,
sel.genes = sel.genes,
lab.cex = 1,
fdr = fdr,
lfc = lfc
))
})

plotly.RENDER <- function() {
pd <- plot_data()
shiny::req(pd)

playbase::plotlyVolcano(
x = pd[["x"]],
y = pd[["y"]],
names = pd[["fc.genes"]],
label.names = pd[["fc.genes"]],
source = "plot1",
marker.type = "scattergl",
highlight = sel.genes,
label = sel.genes,
psig = fdr,
lfc = lfc,
highlight = pd[["sel.genes"]],
label = pd[["sel.genes"]],
psig = pd[["fdr"]],
lfc = pd[["lfc"]],
xlab = "Effect size (log2FC)",
ylab = "Significance (-log10q)",
marker.size = 3,
Expand All @@ -105,17 +121,67 @@ enrichment_plot_volcano_server <- function(id,
color_up_down = TRUE
) %>%
plotly::layout(margin = list(b = 60))
})
}

base.RENDER <- function() {
pd <- plot_data()
shiny::req(pd)

playbase::pgx.Volcano2(
x = pd[["x"]],
y = pd[["y"]],
names = pd[["fc.genes"]],
label.names = pd[["fc.genes"]],
highlight = pd[["sel.genes"]],
label = pd[["sel.genes"]],
psig = pd[["fdr"]],
lfc = pd[["lfc"]],
xlab = "Effect size (log2FC)",
ylab = "Significance (-log10q)",
marker.size = 1,
showlegend = FALSE
)
}

base.RENDER.modal <- function() {
pd <- plot_data()
shiny::req(pd)

playbase::pgx.Volcano2(
x = pd[["x"]],
y = pd[["y"]],
names = pd[["fc.genes"]],
label.names = pd[["fc.genes"]],
highlight = pd[["sel.genes"]],
label = pd[["sel.genes"]],
psig = pd[["fdr"]],
lfc = pd[["lfc"]],
xlab = "Effect size (log2FC)",
ylab = "Significance (-log10q)",
marker.size = 1.5,
label.cex = 5,
axis.text.size = 22,
showlegend = FALSE
)
}

PlotModuleServer(
"plot",
func = volcano.RENDER,
func2 = volcano.RENDER,
plotlib = "plotly",
plotlib2 = "plotly",
pdf.width = 5, pdf.height = 5,
res = c(72, 100),
add.watermark = watermark
plot_grid <- list(
list(plotlib = "plotly", func = plotly.RENDER, func2 = plotly.RENDER, card = 1),
list(plotlib = "ggplot", func = base.RENDER, func2 = base.RENDER.modal, card = 2)
)

lapply(plot_grid, function(x) {
PlotModuleServer(
"plot",
plotlib = x$plotlib,
func = x$func,
func2 = x$func2,
res = c(80, 95), # resolution of plots
pdf.width = 10,
pdf.height = 8,
add.watermark = watermark,
card = x$card
)
})
})
}
93 changes: 81 additions & 12 deletions components/board.expression/R/expression_plot_volcano.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ expression_plot_volcano_ui <- function(id,
PlotModuleUI(
ns("pltmod"),
label = label,
plotlib = "plotly",
plotlib = c("plotly", "ggplot"),
info.text = info.text,
info.methods = info.methods,
info.references = info.references,
Expand All @@ -37,7 +37,9 @@ expression_plot_volcano_ui <- function(id,
caption = caption,
download.fmt = c("png", "pdf", "csv"),
width = width,
height = height
height = height,
cards = TRUE,
card_names = c("dynamic", "static")
)
}

Expand Down Expand Up @@ -142,6 +144,65 @@ expression_plot_volcano_server <- function(id,
plt
}

base.RENDER <- function() {
pd <- plot_data()
shiny::req(pd)

if (labeltype() == "symbol") {
names <- pd[["features"]]
label.names <- pd[["symbols"]]
} else {
names <- pd[["symbols"]]
label.names <- pd[["features"]]
}

playbase::pgx.Volcano2(
x = pd[["x"]],
y = pd[["y"]],
names = names,
highlight = pd[["sel.genes"]],
label = pd[["lab.genes"]],
label.names = label.names,
label.cex = 4,
psig = pd[["fdr"]],
lfc = pd[["lfc"]],
xlab = "Effect size (log2FC)",
ylab = pd[["ylab"]],
marker.size = 1,
showlegend = FALSE
)
}

base.RENDER.modal <- function() {
pd <- plot_data()
shiny::req(pd)

if (labeltype() == "symbol") {
names <- pd[["features"]]
label.names <- pd[["symbols"]]
} else {
names <- pd[["symbols"]]
label.names <- pd[["features"]]
}

playbase::pgx.Volcano2(
x = pd[["x"]],
y = pd[["y"]],
names = names,
highlight = pd[["sel.genes"]],
label = pd[["lab.genes"]],
label.names = label.names,
label.cex = 5,
axis.text.size = 22,
psig = pd[["fdr"]],
lfc = pd[["lfc"]],
xlab = "Effect size (log2FC)",
ylab = pd[["ylab"]],
marker.size = 1.5,
showlegend = FALSE
)
}

modal_plotly.RENDER <- function() {
fig <- plotly.RENDER() %>%
plotly::layout(
Expand All @@ -164,16 +225,24 @@ expression_plot_volcano_server <- function(id,
return(df)
}

PlotModuleServer(
"pltmod",
plotlib = "plotly",
func = plotly.RENDER,
func2 = modal_plotly.RENDER,
remove_margins = FALSE,
csvFunc = plot_data_csv, ## *** downloadable data as CSV
res = c(80, 95), ## resolution of plots
pdf.width = 6, pdf.height = 6,
add.watermark = watermark
plot_grid <- list(
list(plotlib = "plotly", func = plotly.RENDER, func2 = modal_plotly.RENDER, card = 1),
list(plotlib = "ggplot", func = base.RENDER, func2 = base.RENDER.modal, card = 2)
)

lapply(plot_grid, function(x) {
PlotModuleServer(
"pltmod",
plotlib = x$plotlib,
func = x$func,
func2 = x$func2,
csvFunc = plot_data_csv,
res = c(80, 95), # resolution of plots
pdf.width = 10,
pdf.height = 8,
add.watermark = watermark,
card = x$card
)
})
}) ## end of moduleServer
}
Loading

0 comments on commit 07b34fa

Please sign in to comment.