Skip to content

Commit f1c255c

Browse files
committed
Changed default organism parameters to NULL in generateShinyApp function so that the rows of the expression matrix are used directly if no values are supplied by the user
1 parent 32445e3 commit f1c255c

1 file changed

Lines changed: 37 additions & 19 deletions

File tree

R/generateShinyApp.R

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@
1818
#' @param app.title title to be displayed within the app
1919
#' @param organism organism name to be passed on to \code{gprofiler2::gost};
2020
#' organism names are constructed by concatenating the first letter of the
21-
#' name and the family name; default is human - 'hsapiens'
21+
#' name and the family name; default is NULL - enrichment is not included
22+
#' to ensure compatibility with datasets that have non-standard gene names
2223
#' @param org.db database for annotations to transform ENSEMBL IDs to
2324
#' gene names; a list of bioconductor packaged databases can be found with
24-
#' \code{BiocManager::available("^org\\.")}; default is human - 'org.Hs.eg.db'
25+
#' \code{BiocManager::available("^org\\.")}; default is human - 'org.Hs.eg.db';
26+
#' default in NULL, in which case the row names of the expression matrix are
27+
#' used directly - it is recommended to provide ENSEMBL IDs if the database
28+
#' for your model organism is available
2529
#' @param theme shiny theme to be used in the app; default is 'flatly'
2630
#' @param panels.default argument to control which of the default panels
27-
#' will be included in the app; default is all; not that the 'DE' panel is
28-
#' required for 'DEplot' and 'Enrichment'
31+
#' will be included in the app; default is all, but the enrichment panel
32+
#' will not appear unless organism is also supplied; note that the 'DE' panel
33+
#' is required for 'DEplot' and 'Enrichment'
2934
#' @param panels.extra,data.extra,packages.extra functionality to add new
3035
#' user-created panels to the app to extend functionality or change the default
3136
#' behaviour of existing panels; a data frame of the panel UI and server names
@@ -50,7 +55,7 @@
5055
#' app.dir <- generateShinyApp(
5156
#' expression.matrix = expression.matrix.preproc,
5257
#' metadata = metadata,
53-
#' shiny.dir = paste0(tempdir(), "ssshiny_Yang2019"),
58+
#' shiny.dir = paste0(tempdir(), "shiny_Yang2019"),
5459
#' app.title = "Shiny app for the Yang 2019 data",
5560
#' organism = "mmusculus",
5661
#' org.db = "org.Mm.eg.db"
@@ -79,8 +84,8 @@ generateShinyApp <- function(
7984
metadata,
8085
shiny.dir = "shiny_bulkAnalyseR",
8186
app.title = "Visualisation of RNA-Seq data",
82-
organism = "hsapiens",
83-
org.db = "org.Hs.eg.db",
87+
organism = NULL,
88+
org.db = NULL,
8489
theme = "flatly",
8590
panels.default = c("SampleSelect", "QC", "DE", "DEplot", "DEsummary",
8691
"Patterns", "Enrichment", "Cross", "GRN"),
@@ -172,22 +177,32 @@ generateAppFile <- function(
172177
code.load.packages <- paste0("library(", packages.to.load, ")")
173178
lines.out <- c(lines.out, code.load.packages, "")
174179

175-
shiny.dir <- normalizePath(shiny.dir)
176180
code.source.objects <- c(
177181
paste0("r.files <- list.files(path = getwd(), pattern = '\\.R$')"),
178182
"r.files <- setdiff(r.files, 'app.R')",
179183
"for(fl in r.files) source(fl)",
180184
"rda.files <- list.files(pattern = '\\.rda$')",
181-
"for(fl in rda.files) load(fl)",
182-
"anno <- AnnotationDbi::select(",
183-
glue::glue("getExportedValue('{org.db}', '{org.db}'),"),
184-
"keys = rownames(expression.matrix),",
185-
"keytype = 'ENSEMBL',",
186-
"columns = 'SYMBOL'",
187-
") %>%",
188-
"dplyr::distinct(ENSEMBL, .keep_all = TRUE) %>%",
189-
"dplyr::mutate(NAME = ifelse(is.na(SYMBOL), ENSEMBL, SYMBOL))"
185+
"for(fl in rda.files) load(fl)"
190186
)
187+
if(is.null(org.db)){
188+
code.source.objects <- c(
189+
code.source.objects,
190+
"anno <- data.frame(ENSEMBL = rownames(expression.matrix),",
191+
"NAME = rownames(expression.matrix))"
192+
)
193+
}else{
194+
code.source.objects <- c(
195+
code.source.objects,
196+
"anno <- AnnotationDbi::select(",
197+
glue::glue("getExportedValue('{org.db}', '{org.db}'),"),
198+
"keys = rownames(expression.matrix),",
199+
"keytype = 'ENSEMBL',",
200+
"columns = 'SYMBOL'",
201+
") %>%",
202+
"dplyr::distinct(ENSEMBL, .keep_all = TRUE) %>%",
203+
"dplyr::mutate(NAME = ifelse(is.na(SYMBOL), ENSEMBL, SYMBOL))"
204+
)
205+
}
191206
lines.out <- c(lines.out, code.source.objects, "")
192207

193208
code.ui <- c(
@@ -203,7 +218,9 @@ generateAppFile <- function(
203218
code.ui <- c(code.ui, "DEpanelUI('DE', metadata),")
204219
if("DEplot" %in% panels.default) code.ui <- c(code.ui, "DEplotPanelUI('DEplot'),")
205220
if("DEsummary" %in% panels.default) code.ui <- c(code.ui, "DEsummaryPanelUI('DEsummary', metadata),")
206-
if("Enrichment" %in% panels.default) code.ui <- c(code.ui, "enrichmentPanelUI('Enrichment'),")
221+
if("Enrichment" %in% panels.default & !is.null(organism)){
222+
code.ui <- c(code.ui, "enrichmentPanelUI('Enrichment'),")
223+
}
207224
}
208225
if("Patterns" %in% panels.default) code.ui <- c(code.ui, "patternPanelUI('Patterns', metadata),")
209226
if("Cross" %in% panels.default) code.ui <- c(code.ui, "crossPanelUI('Cross', metadata),")
@@ -240,7 +257,7 @@ generateAppFile <- function(
240257
if("DEsummary" %in% panels.default){
241258
code.server <- c(code.server, "DEsummaryPanelServer('DEsummary', expression.matrix, metadata, DEresults, anno)")
242259
}
243-
if("Enrichment" %in% panels.default){
260+
if("Enrichment" %in% panels.default & !is.null(organism)){
244261
code.server <- c(
245262
code.server,
246263
glue::glue("enrichmentPanelServer('Enrichment', DEresults, organism = '{organism}')")
@@ -267,6 +284,7 @@ generateAppFile <- function(
267284

268285
lines.out <- gsub("\\\\", "\\\\\\\\", lines.out)
269286

287+
shiny.dir <- normalizePath(shiny.dir)
270288
write(lines.out, paste0(shiny.dir, "/app.R"))
271289

272290
}

0 commit comments

Comments
 (0)