Skip to content

Commit

Permalink
update and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jfouyang committed Oct 24, 2020
1 parent 2425f22 commit 2b36efd
Show file tree
Hide file tree
Showing 27 changed files with 662 additions and 258 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Depends:
data.table (>= 1.12.2),
Matrix (>= 1.2-17),
hdf5r (>= 1.2.0),
R.utils (>= 2.8.0),
ggplot2 (>= 3.3.0),
grid ,
gridExtra (>= 2.3.0),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(addMeta)
export(checkConfig)
export(createConfig)
export(delMeta)
export(getExampleData)
export(makeShinyApp)
export(makeShinyCodes)
export(makeShinyCodesMulti)
Expand Down
2 changes: 1 addition & 1 deletion R/createConfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' scConf = createConfig(obj)
#'
#' @export
createConfig <- function(obj, meta.to.include = NA, legendCols = 3){
createConfig <- function(obj, meta.to.include = NA, legendCols = 4){
# Extract corresponding metadata
if(class(obj)[1] == "Seurat"){
objMeta = obj@meta.data
Expand Down
45 changes: 45 additions & 0 deletions R/getExampleData.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#' Download example Seurat objects
#'
#' Download example Seurat objects required for ShinyCell tutorial.
#'
#' @param type can be either "single" or "multi" which downloads one or two
#' Seurat objects respectively for the Quick Start/Detailed Tutorial or
#' Multi-dataset Tutorial respectively
#'
#' @return downloaded Seurat object
#'
#' @author John F. Ouyang
#'
#' @import data.table
#'
#' @examples
#' getExampleData()
#'
#' @export
getExampleData <- function(type = c("single", "multi")){
# Setup and checks
files = c("http://files.ddnetbio.com/hrpiFiles/readySeu_rset.rds",
"http://files.ddnetbio.com/hrpiFiles/readySeu_d21i.rds")
names(files) = c("./readySeu_rset.rds", "./readySeu_d21i.rds")
if(type[1] == "single"){
files = files[1]
} else if(type[1] != "multi"){
stop("argument has to be either 'single' or 'multi'!")
}

# Download files
for(i in seq_along(files)){
if(!file.exists(names(files)[i])) {
res <- tryCatch(download.file(files[i],
destfile = names(files)[i],
method = "auto"),
error = function(e) 1)
if(res == 1){
stop(paste0("Following file cannot be downloaded: ", names(files)[i]))
}
}
}
# return(scConf)
}


15 changes: 7 additions & 8 deletions R/makeShinyApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
#' objects (v3+) or the "logcounts" assay for SingleCellExperiment objects
#' @param gex.slot slot in single-cell assay to plot. This is only used
#' for Seurat objects (v3+). Default is to use the "data" slot
#' @param gene.mapping specify a mapping to convert gene identifiers. A
#' named vector must be supplied where \code{names(gene.mapping)} correspond
#' @param gene.mapping specifies whether to convert Ensembl gene IDs (e.g.
#' ENSG000xxx / ENSMUSG000xxx) into more "user-friendly" gene symbols. Set
#' this to \code{TRUE} if you are using Ensembl gene IDs. Default is
#' \code{FALSE} which is not to perform any conversion. Alternatively, users
#' can supply a named vector where \code{names(gene.mapping)} correspond
#' to the actual gene identifiers in the gene expression matrix whereas
#' \code{gene.mapping} correspond to new identifiers to map to. Partial
#' mapping is allowed where the mapping is only provided for some gene
#' identifiers, the remaining gene identifiers will remain unchanged and a
#' warning message will be presented. Default is \code{NA} which is not to
#' perform any mapping
#' \code{gene.mapping} correspond to new identifiers to map to
#' @param shiny.title title for shiny app
#' @param shiny.footnotes text for shiny app footnote. Can be used to insert
#' citations for the single-cell data
Expand Down Expand Up @@ -55,7 +54,7 @@
#' @export
makeShinyApp <- function(
obj, scConf, gex.assay = NA, gex.slot = c("data", "scale.data", "counts"),
gene.mapping = NA,
gene.mapping = FALSE,
shiny.title = "scRNA-seq shiny app", shiny.footnotes = '""',
shiny.dir = "shinyApp/",
default.gene1 = NA, default.gene2 = NA, default.multigene = NA,
Expand Down
63 changes: 44 additions & 19 deletions R/makeShinyCodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,51 @@
#' @export
makeShinyCodes <- function(shiny.title, shiny.footnotes,
shiny.prefix, shiny.dir){
### Write code for server.R
fname = paste0(shiny.dir, "/server.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr","ggplot2",
"hdf5r","ggdendro","gridExtra")), path = fname)
readr::write_file(wrSVload(shiny.prefix), append = TRUE, path = fname)
readr::write_file(wrSVfix(), append = TRUE, path = fname)
readr::write_file(wrSVmain(shiny.prefix), append = TRUE, path = fname)
readr::write_file(wrSVend(), append = TRUE, path = fname)

if(packageVersion("readr") >= "1.4.0"){
### Write code for server.R
fname = paste0(shiny.dir, "/server.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr","ggplot2",
"hdf5r","ggdendro","gridExtra")), file = fname)
readr::write_file(wrSVload(shiny.prefix), append = TRUE, file = fname)
readr::write_file(wrSVfix(), append = TRUE, file = fname)
readr::write_file(wrSVmain(shiny.prefix), append = TRUE, file = fname)
readr::write_file(wrSVend(), append = TRUE, file = fname)


### Write code for ui.R
fname = paste0(shiny.dir, "/ui.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr")), file = fname)
readr::write_file(wrUIload(shiny.prefix), append = TRUE, file = fname)
readr::write_file(wrUIsingle(shiny.title), append = TRUE, file = fname)
readr::write_file(wrUImain(shiny.prefix), append = TRUE, file = fname)
readr::write_file(glue::glue(', \n'), append = TRUE, file = fname)
readr::write_file(wrUIend(shiny.footnotes), append = TRUE, file = fname)

} else {
### Write code for server.R
fname = paste0(shiny.dir, "/server.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr","ggplot2",
"hdf5r","ggdendro","gridExtra")), path = fname)
readr::write_file(wrSVload(shiny.prefix), append = TRUE, path = fname)
readr::write_file(wrSVfix(), append = TRUE, path = fname)
readr::write_file(wrSVmain(shiny.prefix), append = TRUE, path = fname)
readr::write_file(wrSVend(), append = TRUE, path = fname)


### Write code for ui.R
fname = paste0(shiny.dir, "/ui.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr")), path = fname)
readr::write_file(wrUIload(shiny.prefix), append = TRUE, path = fname)
readr::write_file(wrUIsingle(shiny.title), append = TRUE, path = fname)
readr::write_file(wrUImain(shiny.prefix), append = TRUE, path = fname)
readr::write_file(glue::glue(', \n'), append = TRUE, path = fname)
readr::write_file(wrUIend(shiny.footnotes), append = TRUE, path = fname)
}

### Write code for ui.R
fname = paste0(shiny.dir, "/ui.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr")), path = fname)
readr::write_file(wrUIload(shiny.prefix), append = TRUE, path = fname)
readr::write_file(wrUIsingle(shiny.title), append = TRUE, path = fname)
readr::write_file(wrUImain(shiny.prefix), append = TRUE, path = fname)
readr::write_file(glue::glue(', \n'), append = TRUE, path = fname)
readr::write_file(wrUIend(shiny.footnotes), append = TRUE, path = fname)
}


94 changes: 65 additions & 29 deletions R/makeShinyCodesMulti.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,73 @@ makeShinyCodesMulti <- function(shiny.title, shiny.footnotes,
stop("length of shiny.prefix and shiny.headers does not match!")
}

### Write code for server.R
fname = paste0(shiny.dir, "/server.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr","ggplot2",
"hdf5r","ggdendro","gridExtra")), path = fname)
for(i in shiny.prefix){
readr::write_file(wrSVload(i), append = TRUE, path = fname)
if(packageVersion("readr") >= "1.4.0"){
### Write code for server.R
fname = paste0(shiny.dir, "/server.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr","ggplot2",
"hdf5r","ggdendro","gridExtra")), file = fname)
for(i in shiny.prefix){
readr::write_file(wrSVload(i), append = TRUE, file = fname)
}
readr::write_file(wrSVfix(), append = TRUE, file = fname)
for(i in shiny.prefix){
readr::write_file(wrSVmain(i), append = TRUE, file = fname)
}
readr::write_file(wrSVend(), append = TRUE, file = fname)


### Write code for ui.R
fname = paste0(shiny.dir, "/ui.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr")), file = fname)
for(i in shiny.prefix){
readr::write_file(wrUIload(i), append = TRUE, file = fname)
}
readr::write_file(wrUIsingle(shiny.title), append = TRUE, file = fname)
for(i in seq_along(shiny.prefix)){
hhh = shiny.headers[i]
readr::write_file(glue::glue('navbarMenu("{hhh}",'),
append = TRUE, file = fname)
readr::write_file(wrUImain(shiny.prefix[i]), append = TRUE, file = fname)
readr::write_file(glue::glue('), \n\n\n'), append = TRUE, file = fname)
}
readr::write_file(wrUIend(shiny.footnotes), append = TRUE, file = fname)

} else {
### Write code for server.R
fname = paste0(shiny.dir, "/server.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr","ggplot2",
"hdf5r","ggdendro","gridExtra")), path = fname)
for(i in shiny.prefix){
readr::write_file(wrSVload(i), append = TRUE, path = fname)
}
readr::write_file(wrSVfix(), append = TRUE, path = fname)
for(i in shiny.prefix){
readr::write_file(wrSVmain(i), append = TRUE, path = fname)
}
readr::write_file(wrSVend(), append = TRUE, path = fname)


### Write code for ui.R
fname = paste0(shiny.dir, "/ui.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr")), path = fname)
for(i in shiny.prefix){
readr::write_file(wrUIload(i), append = TRUE, path = fname)
}
readr::write_file(wrUIsingle(shiny.title), append = TRUE, path = fname)
for(i in seq_along(shiny.prefix)){
hhh = shiny.headers[i]
readr::write_file(glue::glue('navbarMenu("{hhh}",'),
append = TRUE, path = fname)
readr::write_file(wrUImain(shiny.prefix[i]), append = TRUE, path = fname)
readr::write_file(glue::glue('), \n\n\n'), append = TRUE, path = fname)
}
readr::write_file(wrUIend(shiny.footnotes), append = TRUE, path = fname)
}
readr::write_file(wrSVfix(), append = TRUE, path = fname)
for(i in shiny.prefix){
readr::write_file(wrSVmain(i), append = TRUE, path = fname)
}
readr::write_file(wrSVend(), append = TRUE, path = fname)


### Write code for ui.R
fname = paste0(shiny.dir, "/ui.R")
readr::write_file(wrLib(
c("shiny","shinyhelper","data.table","Matrix","magrittr")), path = fname)
for(i in shiny.prefix){
readr::write_file(wrUIload(i), append = TRUE, path = fname)
}
readr::write_file(wrUIsingle(shiny.title), append = TRUE, path = fname)
for(i in seq_along(shiny.prefix)){
hhh = shiny.headers[i]
readr::write_file(glue::glue('navbarMenu("{hhh}",'),
append = TRUE, path = fname)
readr::write_file(wrUImain(shiny.prefix[i]), append = TRUE, path = fname)
readr::write_file(glue::glue('), \n\n\n'), append = TRUE, path = fname)
}
readr::write_file(wrUIend(shiny.footnotes), append = TRUE, path = fname)
}


Loading

0 comments on commit 2b36efd

Please sign in to comment.