Skip to content

Commit

Permalink
Merge pull request #183 from bigomics/develop-board-expression-refactor
Browse files Browse the repository at this point in the history
Develop board expression refactor
  • Loading branch information
ESCRI11 authored Feb 2, 2023
2 parents 2671070 + b08b08f commit dd6072d
Show file tree
Hide file tree
Showing 14 changed files with 1,118 additions and 1,032 deletions.
102 changes: 0 additions & 102 deletions components/board.expression/R/expression_plot.R

This file was deleted.

76 changes: 34 additions & 42 deletions components/board.expression/R/expression_plot_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ expression_plot_boxplot_ui <- function(id,
height,
width) {
ns <- shiny::NS(id)
options <- tagList(
actionButton(ns("button1"), "some action")

plots_boxplot_opts <- shiny::tagList(
withTooltip(shiny::checkboxInput(ns("boxplot_grouped"), "grouped", TRUE),
"Group expression values by conditions.",
placement = "right", options = list(container = "body")
),
withTooltip(shiny::checkboxInput(ns("boxplot_logscale"), "log scale", TRUE),
"Show logarithmic (log2CPM) expression values.",
placement = "right", options = list(container = "body")
)
)

info_text <- "The top N = {12} differentially (both positively and negatively) expressed gene barplot for the selected comparison under the <code>Contrast</code> settings."
Expand All @@ -29,7 +37,7 @@ expression_plot_boxplot_ui <- function(id,
label = label,
plotlib = "base",
info.text = info_text,
options = NULL,
options = plots_boxplot_opts,
download.fmt = c("png", "pdf", "csv"),
width = width,
height = height
Expand All @@ -41,7 +49,8 @@ expression_plot_boxplot_ui <- function(id,
#' @description A shiny Module for plotting (server code).
#'
#' @param id
#' @param inputData
#' @param comp
#' @param ngs
#' @param sel
#' @param res
#' @param watermark
Expand All @@ -50,58 +59,53 @@ expression_plot_boxplot_ui <- function(id,
#'
#' @export
expression_plot_boxplot_server <- function(id,
inputData,
comp,
ngs,
sel,
res,
watermark = FALSE) {
moduleServer(id, function(input, output, session) {
# #calculate required inputs for plotting ---------------------------------

plot_data <- shiny::reactive({
ngs <- inputData()
shiny::req(ngs)

## get table
## sel=1
comp <- comp() # input$gx_contrast
grouped <- input$boxplot_grouped
logscale <- input$boxplot_logscale
ngs <- ngs()
sel <- sel()
if (is.null(sel) || length(sel) == 0) {
frame()
text(0.5, 0.5, "No gene selected", col = "black")
return(NULL)
}

res <- res()
if (is.null(res) || is.null(sel)) {
return(NULL)
}

psel <- rownames(res)[sel]
gene <- ngs$genes[1, "gene_name"]
comp <- 1
grouped <- TRUE
logscale <- TRUE
srt <- 45

gene <- ngs$genes[psel, "gene_name"]
comp <- input$gx_contrast
shiny::req(comp)
grouped <- input$boxplot_grouped
logscale <- input$boxplot_logscale
srt <- ifelse(grouped, 0, 35)

return(
return(list(
ngs = ngs,
gene = gene,
comp = comp,
sel = sel,
grouped = grouped,
logscale = logscale,
srt = srt
)
))
})

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

if (is.null(pd[["sel"]]) || length(pd[["sel"]]) == 0) {
frame()
text(0.5, 0.5, "No gene selected", col = "black")
return(NULL)
}

if (is.null(res) || is.null(sel)) {
return(NULL)
}

par(mfrow = c(1, 1), mar = c(4, 3, 1.5, 1.5), mgp = c(2, 0.8, 0), oma = c(1, 0.5, 0, 0.5))
pgx.plotExpression(pd[["ngs"]],
pd[["gene"]],
Expand All @@ -114,23 +118,11 @@ expression_plot_boxplot_server <- function(id,
)
}

modal_plotly.RENDER <- function() {
fig <- plotly.RENDER() %>%
plotly::layout(
font = list(size = 18),
legend = list(
font = list(size = 18)
)
)
fig <- plotly::style(fig, marker.size = 20)
fig
}

PlotModuleServer(
"pltmod",
plotlib = "base",
func = plotly.RENDER,
func2 = modal_plotly.RENDER,
# func2 = modal_plotly.RENDER,
csvFunc = plot_data, ## *** downloadable data as CSV
res = c(80, 95), ## resolution of plots
pdf.width = 6, pdf.height = 6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,11 @@ expression_plot_maplot_server <- function(id,
return(NULL)
}
fc.genes <- as.character(res[, grep("^gene$|gene_name", colnames(res))])
## pval = res$P.Value
## pval = res[,grep("P.Value|meta.p|pval|p.val",colnames(res))[1]]

## filter genes by gene family or gene set
fam.genes <- unique(unlist(ngs$families[10]))
## fam.genes = unique(unlist(ngs$families[input$gx_features]))
fam.genes <- res$gene_name
if (gx_features() != "<all>") {
## gset <- GSETS[input$gx_features]
gset <- getGSETS(gx_features())
fam.genes <- unique(unlist(gset))
}
Expand All @@ -121,10 +117,8 @@ expression_plot_maplot_server <- function(id,
sel.genes <- intersect(sig.genes, sel.genes)

## are there any genes/genesets selected?
# sel1 = genetable$rows_selected()
sel1 <- sel1()
df1 <- df1()
# sel2 = gsettable$rows_selected()
sel2 <- sel2()
df2 <- df2()
lab.cex <- 1
Expand Down Expand Up @@ -168,9 +162,6 @@ expression_plot_maplot_server <- function(id,
head(sel.genes[order(-impt(sel.genes))], 10)
)




return(list(
x = x,
y = y,
Expand Down Expand Up @@ -200,8 +191,6 @@ expression_plot_maplot_server <- function(id,
highlight = pd[["sel.genes"]],
label = pd[["lab.genes"]], label.cex = pd[["lab.cex"]],
group.names = c("group1", "group0"),
## xlim=xlim, ylim=ylim, ## hi.col="#222222",
## use.fdr=TRUE,
psig = pd[["fdr"]], lfc = pd[["lfc"]],
xlab = "average expression (log2.CPM)",
ylab = "effect size (log2.FC)",
Expand Down
Loading

0 comments on commit dd6072d

Please sign in to comment.