From 85dc44c846ea0cc2eef558f65eea26af14182eb0 Mon Sep 17 00:00:00 2001 From: fsoubes Date: Fri, 8 Mar 2019 10:02:12 +0100 Subject: [PATCH] add getdegenes to MATRiX --- function/decideTestTrix.R | 9 +-- function/vennplot.R | 2 - global.R | 4 +- man/cutoffElements.Rd | 21 +++++ man/downloadFilestab.Rd | 19 +++++ man/downoutputables.Rd | 31 +++++++ man/getDegenes.Rd | 34 ++++++++ man/tracketCutoff.Rd | 17 ++++ module/Savemoduletable.R | 85 +++++++++++++++++++ module/Selgroup.R | 20 +++-- module/getdegenes.R | 112 ++++++++++++++++++++++++++ module/{tablexport.R => renderplot.R} | 0 server/GetDEgenes.R | 17 +--- server/Groupstripshiny.R | 42 +--------- server/Heatmapshiny.R | 18 +---- server/Plotreact.R | 2 +- server/Shinygohm.R | 31 +------ server/Trackerhm.R | 9 --- server/Trackervenn.R | 8 -- server/Utilities.R | 93 +++++++++++---------- server/Venn.R | 105 +++++++----------------- server/Venninter.R | 10 --- ui.R | 72 +++++------------ 23 files changed, 444 insertions(+), 317 deletions(-) create mode 100644 man/cutoffElements.Rd create mode 100644 man/downloadFilestab.Rd create mode 100644 man/downoutputables.Rd create mode 100644 man/getDegenes.Rd create mode 100644 man/tracketCutoff.Rd create mode 100644 module/Savemoduletable.R create mode 100644 module/getdegenes.R rename module/{tablexport.R => renderplot.R} (100%) diff --git a/function/decideTestTrix.R b/function/decideTestTrix.R index e73bec7..32c6b6c 100644 --- a/function/decideTestTrix.R +++ b/function/decideTestTrix.R @@ -23,9 +23,7 @@ #' #' @export -decTestTRiX <- function(adj,logfc,pval, DEGcutoff = 0.05 ,FC = 1,cutoff_meth = "FDR",maxDE = NULL,contrast = 1:ncol(adj)) - -{ +decTestTRiX <- function(adj,logfc,pval, DEGcutoff = 0.05 ,FC = 1,cutoff_meth = "FDR",maxDE = NULL,contrast = 1:ncol(adj)){ ## select probes with cutoff_meth<= DEGcutoff and FoldChange > FC and nbr of selected probes < maxDE (if nb FC selected >maxDE) @@ -33,6 +31,7 @@ decTestTRiX <- function(adj,logfc,pval, DEGcutoff = 0.05 ,FC = 1,cutoff_meth = " contrast = c(contrast, contrast) + if (is.na(maxDE) || is.null(maxDE)) maxDE = nrow(adj) @@ -41,18 +40,19 @@ decTestTRiX <- function(adj,logfc,pval, DEGcutoff = 0.05 ,FC = 1,cutoff_meth = " pList = adj[, contrast] + if(cutoff_meth=="None") pList= pval[,contrast] ## select on pvalue DEp = pList <= DEGcutoff + ## select on FC DEFC = 2 ** abs(logfc[, contrast]) >= FC - ## reduce selection to maxDE if (any(colSums(DEFC) > maxDE)) { @@ -84,7 +84,6 @@ decTestTRiX <- function(adj,logfc,pval, DEGcutoff = 0.05 ,FC = 1,cutoff_meth = " DEsel = which(rowSums(DEsel, na.rm = T) > 0) elements= list(DEsel, length(DEsel)) - return(elements) } diff --git a/function/vennplot.R b/function/vennplot.R index 18b49a3..b851ae3 100644 --- a/function/vennplot.R +++ b/function/vennplot.R @@ -204,7 +204,6 @@ Vennfinal <- function(myl,adj, cex=1, cutoffpval, cutofffc, statimet, meandup = #' myventocsv <- function(myven, adj){ - max.length <- max(sapply(myven, length)) myven %>% lapply(function(v){ c(v, rep("", max.length-length(v)))}) %>% setNames(names(adj)) %>% as.data.frame() } @@ -221,7 +220,6 @@ myventocsv <- function(myven, adj){ mysetventocsv <- function(myven){ - max.length <- max(sapply(myven, length)) myven %>%lapply(function(v){ c(v, rep("", max.length-length(v)))}) %>% as.data.frame() } diff --git a/global.R b/global.R index c8d3152..b84a640 100644 --- a/global.R +++ b/global.R @@ -54,8 +54,8 @@ source("./module/Selgroup.R") source("./module/enrichmodule.R") source("./module/groupcol.R") source("./module/magnificentables.R") -source("./module/tablexport.R") - +source("./module/Savemoduletable.R") +source("./module/getdegenes.R") ################################ diff --git a/man/cutoffElements.Rd b/man/cutoffElements.Rd new file mode 100644 index 0000000..b77ecf4 --- /dev/null +++ b/man/cutoffElements.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getdegenes.R +\name{cutoffElements} +\alias{cutoffElements} +\title{cutoffElements is a global namespace containing a list of shiny widgets filter the restable with cutoff parameters} +\usage{ +cutoffElements(id, c1 = 6, c2 = 6) +} +\arguments{ +\item{id}{Shiny id} + +\item{c1}{A numeric value to specify the column size of the first element} + +\item{c2}{A numeric value to specify the column size of the second element} +} +\value{ +Widgets in the gui +} +\description{ +cutoffElements is a global namespace containing a list of shiny widgets filter the restable with cutoff parameters +} diff --git a/man/downloadFilestab.Rd b/man/downloadFilestab.Rd new file mode 100644 index 0000000..2e5a30d --- /dev/null +++ b/man/downloadFilestab.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Savemoduletable.R +\name{downloadFilestab} +\alias{downloadFilestab} +\title{downloadFilestab is a shiny widget which aims is to download a reactive plot} +\usage{ +downloadFilestab(id, label = "Save your Scree plot") +} +\arguments{ +\item{id}{Shiny id} + +\item{label}{Shiny label} +} +\value{ +Widget in the gui +} +\description{ +downloadFilestab is a shiny widget which aims is to download a reactive plot +} diff --git a/man/downoutputables.Rd b/man/downoutputables.Rd new file mode 100644 index 0000000..5860027 --- /dev/null +++ b/man/downoutputables.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Savemoduletable.R +\name{downoutputables} +\alias{downoutputables} +\title{downoutputables is a shiny module which aims is to export reactive table} +\usage{ +downoutputables(input, output, session, projectname, suffix = "plot.csv", + data = NULL, cont = NULL, xlsx = F, case) +} +\arguments{ +\item{input}{Internal} + +\item{output}{Internal} + +\item{session}{Internal} + +\item{projectname}{A reactive character (MA project or session data)} + +\item{suffix}{A character} + +\item{data}{A reactive expression to be plot} + +\item{cont}{A reactive character vector of the selected comparison(s)} + +\item{xlsx}{A boolean value} + +\item{case}{A numeric value} +} +\description{ +downoutputables is a shiny module which aims is to export reactive table +} diff --git a/man/getDegenes.Rd b/man/getDegenes.Rd new file mode 100644 index 0000000..35428a5 --- /dev/null +++ b/man/getDegenes.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getdegenes.R +\name{getDegenes} +\alias{getDegenes} +\title{getDegenes is a shiny module which aims is to return an index or list of each significant genes from the restable for a set of comparison(s)} +\usage{ +getDegenes(input, output, session, data, dflogfc = NULL, maxDe = NULL, + case = NULL, reg = NULL, meth = NULL) +} +\arguments{ +\item{input}{Internal} + +\item{output}{Internal} + +\item{session}{Internal} + +\item{data}{A subset data frame with the selected comparisons for the adj.p.val or p.val and with the logfc for the hm} + +\item{dflogfc}{A subset data frame with the selected comparisons for the logfc} + +\item{maxDe}{A reactive numeric value} + +\item{case}{A numeric value (case = 1 for heatmap and strip and 2 for venn diagram)} + +\item{reg}{A reactive character} + +\item{meth}{A reactive Character} +} +\value{ + +} +\description{ +getDegenes is a shiny module which aims is to return an index or list of each significant genes from the restable for a set of comparison(s) +} diff --git a/man/tracketCutoff.Rd b/man/tracketCutoff.Rd new file mode 100644 index 0000000..0caedd2 --- /dev/null +++ b/man/tracketCutoff.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getdegenes.R +\name{tracketCutoff} +\alias{tracketCutoff} +\title{cutoffElements is a global namespace containing a list of htmlOuput from widget inputs} +\usage{ +tracketCutoff(id) +} +\arguments{ +\item{id}{Shiny widget} +} +\value{ +Widgets in the gui +} +\description{ +cutoffElements is a global namespace containing a list of htmlOuput from widget inputs +} diff --git a/module/Savemoduletable.R b/module/Savemoduletable.R new file mode 100644 index 0000000..351e50a --- /dev/null +++ b/module/Savemoduletable.R @@ -0,0 +1,85 @@ +#' downloadFilestab is a shiny widget which aims is to download a reactive plot +#' +#' @param id Shiny id +#' @param label Shiny label +#' +#' @return Widget in the gui +#' +#' @export +#' + +downloadFilestab <- function(id, label = "Save your Scree plot") { + ns <- NS(id) + downloadButton(ns("downloadtable"), label , style ="color: #fff; background-color: #337ab7; border-color: #2e6da4") +} + + + +#' downoutputables is a shiny module which aims is to export reactive table +#' +#' @param input Internal +#' @param output Internal +#' @param session Internal +#' @param projectname A reactive character (MA project or session data) +#' @param suffix A character +#' @param data A reactive expression to be plot +#' @param cont A reactive character vector of the selected comparison(s) +#' @param case A numeric value +#' @param xlsx A boolean value +#' +#' @export +#' + +downoutputables <- function(input, output, session , projectname, suffix = "plot.csv", data = NULL , cont = NULL, xlsx = F , case ) { + + + + output$downloadtable <- downloadHandler( + + filename <- function() { + + paste0(basename(file_path_sans_ext(projectname())), suffix , sep ='')}, + + + content <- function(file) { + + if(!xlsx) + write.table(try(switch(case, + myventocsv(data() ,cont()), + mysetventocsv(setvglobalvenn(data(), cont(), dll =T )), + data())), + file, + na = "", + row.names = F, + col.names = T, + append = TRUE, + sep = ";" + ) + else + withProgress(message = 'Creation of the xlsx table:', + value = 0, { + n <- NROW(50) + for (i in 1:n) { + incProgress(1 / n, detail = "Please wait...") + } + + + library(xlsx) + + for (i in 1:length(data())) { + if (i == 1) + write.xlsx(file = file,data()[[i]], + sheetName = paste("Cluster", i)) + else + write.xlsx( + file = file, + data()[[i]], + sheetName = paste("Cluster", i), + append = TRUE + ) + } + }) + + }) + +} diff --git a/module/Selgroup.R b/module/Selgroup.R index 2b21c0a..4429ad2 100644 --- a/module/Selgroup.R +++ b/module/Selgroup.R @@ -38,42 +38,50 @@ checkboxElements <- function(id){ #' boxChooser <- function(input, output, session, label, data, group, case, empty =F) { + + isinline <- reactiveValues(inline = F) + + observe({ + req(group()[[2]]$Grp) + isinline$format <- ifelse(length(levels(group()[[2]]$Grp)) >= 6, T, F) + }) output$usercheck <- renderUI({ - + ns <- session$ns + groupinline <- ifelse(length(levels(group()[[2]]$Grp)) >= 6, T, F) case = ifelse(empty, 2, 1) checkboxGroupInput( ns("box"), label, choices =data(), selected = switch(case,data(), NULL), - inline = ifelse(length(levels(group()[[2]]$Grp)) > 6, T, F) + inline = isinline$format ) }) #Select all the contrasts observeEvent(input$allcomphm, { - groupinline = ifelse(length(levels(group()[[2]]$Grp)) > 6, T, F) + #groupinline = ifelse(length(levels(group()[[2]]$Grp)) >= 6, T, F) updateCheckboxGroupInput( session, "box", label , choices = data(), selected = data(), - inline = groupinline + inline = isinline$format ) }) #Unselect all the contrasts observeEvent(input$nocomphm, { - groupinline = ifelse(length(levels(group()[[2]]$Grp)) > 6, T, F) + #groupinline = ifelse(length(levels(group()[[2]]$Grp)) >= 6, T, F) updateCheckboxGroupInput(session, "box", label , choices = data(), - inline= groupinline + inline= isinline$format ) }) diff --git a/module/getdegenes.R b/module/getdegenes.R new file mode 100644 index 0000000..e7913fe --- /dev/null +++ b/module/getdegenes.R @@ -0,0 +1,112 @@ +#' cutoffElements is a global namespace containing a list of shiny widgets filter the restable with cutoff parameters +#' +#' @param id Shiny id +#' @param c1 A numeric value to specify the column size of the first element +#' @param c2 A numeric value to specify the column size of the second element +#' +#' @return Widgets in the gui +#' +#' @export +#' + +cutoffElements <- function(id, c1 =6 ,c2=6){ + + ns <- NS(id) + tagList(column(c1, + sliderInput(ns("pval"),"P-value treshold", + + min = 0.01,max = 0.05, + value = 0.05,step = 0.01 + )), + + column(c2, + sliderInput(ns("fc"),"FC treshold",min = 1, max = 10, + value = 1,step = 1 + )) +)} + + +#' cutoffElements is a global namespace containing a list of htmlOuput from widget inputs +#' +#' @param id Shiny widget +#' +#' @return Widgets in the gui +#' +#' @export +#' + +tracketCutoff <- function(id){ + ns <- NS(id) + tagList( + htmlOutput(ns("myPVAL")), + p("and"), + htmlOutput(ns("myFC")) + ) +} + + + +#' getDegenes is a shiny module which aims is to return an index or list of each significant genes from the restable for a set of comparison(s) +#' +#' @param input Internal +#' @param output Internal +#' @param session Internal +#' @param data A subset data frame with the selected comparisons for the adj.p.val or p.val and with the logfc for the hm +#' @param dflogfc A subset data frame with the selected comparisons for the logfc +#' @param maxDe A reactive numeric value +#' @param case A numeric value (case = 1 for heatmap and strip and 2 for venn diagram) +#' @param reg A reactive character +#' @param meth A reactive Character +#' +#' @return +#' +#' @export +#' + +getDegenes <- function(input, output, session, data, dflogfc=NULL, maxDe = NULL , case = NULL, reg = NULL, meth = NULL ){ + + + ######################################### + ######## FC step 0.1 if FC <2 # + ######################################### + + observe({ + + req(input$fc) + if (input$fc < 2) + updateSliderInput(session,"fc", + label = "FC treshold",value = NULL, + min = 1,max = 10, + step = .1 + ) + else + updateSliderInput(session,"fc", + label = "FC treshold",value = NULL, + min = 1,max = 10, + step = 1 + ) + + }) + + output$myPVAL <- renderText({ #pvalue selected + ns <- session$ns + input$pval + }) + + + output$myFC <- renderText({ #Fold change value selected, default =1 + ns <- session$ns + input$fc + }) + + +return(reactive({ + switch(case, + decTestTRiX(data()[[1]],data()[[2]],data()[[3]], DEGcutoff = input$pval, FC = input$fc, cutoff_meth = meth(), maxDE=maxDe()), + Vennlist(data(),dflogfc(), reg(), input$pval, input$fc)) +})) + +} + + + diff --git a/module/tablexport.R b/module/renderplot.R similarity index 100% rename from module/tablexport.R rename to module/renderplot.R diff --git a/server/GetDEgenes.R b/server/GetDEgenes.R index 51b1983..cbec901 100644 --- a/server/GetDEgenes.R +++ b/server/GetDEgenes.R @@ -85,9 +85,7 @@ subsetcomp <- reactive({ #' subsetDEG is a reactive function that return the indexes for the signficant genes #' #' @param subsetcomp a list of three data frame with rows selected according to the contrasts selected -#' @param intput$fc a numeric FC selected #' @param input$decidemethod a character method, default = BH -#' @param input$pval a numeric pvalue #' @param input$maxgen a numeric maxgen, default = NULL #' #' @return subsetDEG a reactive data frame with the indexes corresponding to the sigificant genes @@ -96,19 +94,6 @@ subsetcomp <- reactive({ #' -subsetDEG <- reactive({ +subsetDEG <- callModule(getDegenes, "deghm", data = subsetcomp , meth = reactive(input$decidemethod), case = 1 , maxDe = reactive(input$maxgen)) - req(subsetcomp()) - indexDEG = decTestTRiX( - subsetcomp()[[1]], - subsetcomp()[[2]], - subsetcomp()[[3]], - DEGcutoff = input$pval, - FC = input$fc, - cutoff_meth = input$decidemethod, - maxDE = input$maxgen) - - return(indexDEG) - -}) diff --git a/server/Groupstripshiny.R b/server/Groupstripshiny.R index 43827b1..fd2c401 100644 --- a/server/Groupstripshiny.R +++ b/server/Groupstripshiny.R @@ -38,9 +38,8 @@ filenamestrip <- reactive({ filterwkingset <- reactive({ - req(myreorderwk()) - myreorderwk() %>% select(dataid() ,GeneName, sort(names(.[-1]))) %>% slice(., getDegenes()[[1]]) %>% mutate_if(is.numeric, funs(format(., digits = 3))) + myreorderwk() %>% select(dataid() ,GeneName, sort(names(.[-1]))) %>% slice(., getDegenestrip()[[1]]) %>% mutate_if(is.numeric, funs(format(., digits = 3))) }) @@ -63,43 +62,8 @@ selectedrow <- callModule(stylishTables, "orderedwk", data = filterwkingset , selection = 'single', case = 2 ) -# output$orderedwk <- DT::renderDataTable(DT::datatable(filterwkingset(), -# options = list(scrollX = TRUE, -# pageLength = 150, -# scrollY=550, -# stateSave = T, -# dom = 'Bfrtip', -# buttons = list( -# list(extend = 'csv', -# filename = filenamestrip()[1]), -# list(extend = 'pdf', -# filename = filenamestrip()[1], -# title = "My Title", -# header = FALSE) -# )), -# selection = 'single', -# extensions=c("Buttons",'Scroller'), -# filter =c("none"), -# rownames= FALSE )) - - - -getDegenes <- reactive({ - - req(subsetstat(), csvf(), input$pvalstrip) - - indexDEG = decTestTRiX( - subsetstat()[[1]], - subsetstat()[[2]], - subsetstat()[[3]], - DEGcutoff = input$pvalstrip, - FC = input$fcstrip, - cutoff_meth = input$decidemethodstrip, maxDE=NULL ) - return(indexDEG) - -}) - +getDegenestrip <- callModule(getDegenes, "degstrip", data = subsetstat , meth = reactive(input$decidemethodstrip), case = 1 , maxDe = reactive(NULL) ) callstripgenes <- reactive({ @@ -107,7 +71,7 @@ callstripgenes <- reactive({ validate( need(selectedrow(), 'Search your gene and select the corresponding row')) - req(getDegenes(), filterwkingset()) + req(filterwkingset()) grps <- gsub("[.][0-9]*","",colnames(filterwkingset()[-(1:2)]), perl=T) print(grps) ggp=ggstrip_groups(grps=grps , wSet= filterwkingset() , probesID= selectedrow() ) diff --git a/server/Heatmapshiny.R b/server/Heatmapshiny.R index 1ac11f2..c41bcaf 100644 --- a/server/Heatmapshiny.R +++ b/server/Heatmapshiny.R @@ -171,18 +171,10 @@ observe({ callModule(downoutputfiles, "savehm", projectname = projectname , suffix = "_heatmap." , data = hmobj$obj , w =9, h = 12, hm =T, rown = reactive(input$rowname)) }) - output$downloadcut <- downloadHandler( - filename = function() { - paste(basename(file_path_sans_ext(projectname())), - '_clustered_hm', - '.csv', - sep = '') - }, - content = function(file) { - write.csv(ordered(), file, row.names = FALSE) - } - ) - + + callModule(downoutputables, "downloadcut", projectname = projectname , suffix = "_clustered_hm.csv" , data = ordered , case = 3 ) + + ordered <- reactive({ @@ -224,8 +216,6 @@ observe({ }) - #output$clustering <- DT::renderDataTable(DT::datatable(ordered() , options = list(scrollX = TRUE) )) - #output$totalgenbyc <- DT::renderDataTable(DT::datatable(grouplength())) callModule(stylishTables, "totalgenbyc", data = grouplength , searching = F, pageLength = 10) callModule(stylishTables, "clusteringtable", data = ordered , searching = F, scrollX = T,lengthpage= c('5', '10', '15'), pageLength = 10) diff --git a/server/Plotreact.R b/server/Plotreact.R index 54142eb..2a53f60 100644 --- a/server/Plotreact.R +++ b/server/Plotreact.R @@ -16,7 +16,7 @@ shinyjs::disable("heatm") #' hmbis is an event reactive function that pre-computed hierarchical clustering on microarray data #' -#' @param subsetwset a data frame with all the individuals selected +#' @param subsetwset a data frame with all the selected groups #' @param subsetDEG a data frame with the indexes corresponding to the sigificant genes #' @param subsetgroup_hm a data frame with the corresponding groups #' @param k a numeric value which aim is to defined the treshold value to cut the dendogram input$clusters diff --git a/server/Shinygohm.R b/server/Shinygohm.R index f283cdc..f7b10fb 100644 --- a/server/Shinygohm.R +++ b/server/Shinygohm.R @@ -40,7 +40,6 @@ observe({ selectInput("cutgo", "Choose your cluster", choices = seq(1, NROW(n) , by = 1)) - }) @@ -117,7 +116,6 @@ output$printmessage <- renderPrint({ cat("You can select the rows in the table above in order to display the gene names") cat("\n") cat("\n") - }) @@ -154,33 +152,6 @@ output$titlegotop <- renderText({ mytitlevenn <<- print("Top 10 Significantly Enriched GO and KEGG Terms") }) +callModule(downoutputables, "savegohmdavxlsx", projectname = projectname , suffix = "_go.xlsx" , data = reactive(davidwebservice()$mygodavid) , xlsx = T ) -output$savegohmdavxlsx = downloadHandler(filename <- function() { paste0(basename(file_path_sans_ext(projectname())), '_go.',"xlsx", sep = '')}, - content = function(file) { - - withProgress(message = 'Creation of the xlsx table:', - value = 0, { - n <- NROW(50) - for (i in 1:n) { - incProgress(1 / n, detail = "Please wait...") - } - - - library(xlsx) - - for (i in 1:length(davidwebservice()$mygodavid)) { - if (i == 1) - write.xlsx(file = file,davidwebservice()$mygodavid[[i]], - sheetName = paste("Cluster", i)) - else - write.xlsx( - file = file, - davidwebservice()$mygodavid[[i]], - sheetName = paste("Cluster", i), - append = TRUE - ) - } - }) - } -) diff --git a/server/Trackerhm.R b/server/Trackerhm.R index f7d8c44..06dd3be 100644 --- a/server/Trackerhm.R +++ b/server/Trackerhm.R @@ -34,15 +34,6 @@ output$testtt <- renderText({ #Contrast selected }) -output$myPVAL <- renderText({ #pvalue selected - input$pval -}) - - -output$myFC <- renderText({ #Fold change value selected, default =1 - input$fc -}) - output$myMET <- renderText({ #Method for choosing the signficant genes, default = FDR (BH method) input$decidemethod }) diff --git a/server/Trackervenn.R b/server/Trackervenn.R index 724316f..8e880bf 100644 --- a/server/Trackervenn.R +++ b/server/Trackervenn.R @@ -31,14 +31,6 @@ output$totalgenes <- renderText({ }) -output$myPVALvenn <- renderText({ #pvalue selected - input$pvalvenn -}) - - -output$myFCvenn <- renderText({ #Fold change value selected, default =1 - input$fcvenn -}) output$topgenesdf <- renderText({ #Method for choosing the signficant genes, default = FDR (BH method) input$topgenes diff --git a/server/Utilities.R b/server/Utilities.R index 46a247b..bb34f17 100644 --- a/server/Utilities.R +++ b/server/Utilities.R @@ -46,55 +46,52 @@ isolate( ) }) -######################################### -######## FC step 0.1 if FC <2 # -######################################### - -observe({ - if (input$fcvenn <= 2) - updateSliderInput( - session, - "fcvenn", - label = "FC treshold", - value = NULL, - min = 1, - max = 10, - step = .1 - ) - else - updateSliderInput( - session, - "fcvenn", - label = "FC treshold", - value = NULL, - min = 1, - max = 10, - step = 1 - ) - - if (input$fc <= 2) - updateSliderInput( - session, - "fc", - label = "FC treshold", - value = NULL, - min = 1, - max = 10, - step = .1 - ) - else - updateSliderInput( - session, - "fc", - label = "FC treshold", - value = NULL, - min = 1, - max = 10, - step = 1 - ) - -}) +# observe({ +# +# if (input$fcvenn <= 2) +# updateSliderInput( +# session, +# "fcvenn", +# label = "FC treshold", +# value = NULL, +# min = 1, +# max = 10, +# step = .1 +# ) +# else +# updateSliderInput( +# session, +# "fcvenn", +# label = "FC treshold", +# value = NULL, +# min = 1, +# max = 10, +# step = 1 +# ) +# +# if (input$fc <= 2) +# updateSliderInput( +# session, +# "fc", +# label = "FC treshold", +# value = NULL, +# min = 1, +# max = 10, +# step = .1 +# ) +# else +# updateSliderInput( +# session, +# "fc", +# label = "FC treshold", +# value = NULL, +# min = 1, +# max = 10, +# step = 1 +# ) +# +# }) ################################################# ######## Download data and reset button heatmap # diff --git a/server/Venn.R b/server/Venn.R index 002c240..ae4445b 100644 --- a/server/Venn.R +++ b/server/Venn.R @@ -24,25 +24,23 @@ output$bool <- reactive({ value }) + outputOptions(output,"bool",suspendWhenHidden=F) +getvennlist <- reactiveValues(vennlist = NULL) # Initiliazition of the reactive values for the vennlist +mycont <- callModule(getDegenes, "degvenn", data = user_cont , meth = NULL, dflogfc = user_fc , maxDe = NULL, reg = reactive(input$regulation), case =2) #Outisde observe to update fc widget step (0.1, [1;2] and (1, [2;10])) + + +observe({ + req(user_cont()>0) # User selection + getvennlist$vennlist <- mycont() # push shiny module vennlist to the reactive values object +}) -#' vennlist is a reactive function which aim is to return a list of signficant probenames -#' -#' @param csvf a data frame -#' @param user_cont a subset data frame with the selected comparisons for the adj.p.val or p.val -#' @param user_fc a subset data frame with the selected comparisons for the logfc -#' @param regulation vector input -#' @param pvalvenn numeric input for the p value cutoff -#' @param fcvenn numeric input for the logfc value cutoff -#' -#' @return probven a reactive list of probenames -#' -#' @export vennlist <- reactive({ - req(user_cont() > 0) + req(getvennlist$vennlist) if (is.null(csvf())) return(NULL) + # adj <- user_cont() # fc <- user_fc() # cutoffpval <-input$pvalvenn @@ -52,10 +50,8 @@ vennlist <- reactive({ # clusterExport(cl,c("adj","fc","cutoffpval","cutofffc","reg","cutoffpval"),envir=environment()) #mycont = Vennlist(adj,fc, reg, cutoffpval, cutofffc,cl) #stopCluster(cl) - mycont = Vennlist(user_cont(),user_fc(), input$regulation, input$pvalvenn, input$fcvenn) - probven = rowtoprob(mycont,csvf()[[3]], user_cont()) - - + + probven = rowtoprob(getvennlist$vennlist,csvf()[[3]], user_cont()) if(input$dispvenn == "genes") if(input$Notanno){ @@ -111,17 +107,18 @@ subsetstatRm <- reactive({ choix_cont <- callModule(boxChooser, "selcompvenn", label = "Choose your comparison", data = reactive(colnames(subsetstatRm())) , group = csvf, case = 2 , empty = T ) -#' user_cont is a reactive function that return the contrast selected by the user +#' user_cont is a reactive function that return the a subset dataframe with the comparison(s) selected #' -#' @param subsetstat data frame corresponding to the pvalue or subsetstat pvalue -#' @param choix_cont a set of contrasts selected by the user +#' @param subsetstat A data frame corresponding to the pvalue or subsetstat pvalue +#' @param choix_cont A set of contrasts selected by the user #' -#' @return user_cont a reactive data frame with the contrast selected +#' @return A reactive dataframe with the contrast selected #' #' @export #' user_cont <- reactive({ + req(subsetstat()) if (input$methodforvenn == "FDR") mysel = (subset(subsetstat()[[1]], @@ -133,12 +130,12 @@ user_cont <- reactive({ }) -#' user_cont is a reactive function that return the contrast selected by the user +#' user_fc is a reactive function that return the a subset dataframe with the comparison(s) selected #' -#' @param subsetstat data frame corresponding to the logfc value -#' @param choix_cont a set of contrasts selected by the user +#' @param subsetstat A data frame corresponding to the logfc value +#' @param choix_cont A set of contrasts selected by the user #' -#' @return user_cont a reactive data frame with the contrast selected +#' @return A reactive dataframe with the contrast selected #' #' @export #' @@ -151,58 +148,14 @@ user_fc <- reactive({ }) -output$downloadvenn <- downloadHandler( - filename = function() { - paste(basename(file_path_sans_ext(projectname())), - '_filtered_venn', - '.csv', - sep = '') - }, - content = function(fname) { - write.table( - try(myventocsv(vennlist()[[2]] , user_cont())), - fname, - na = "", - row.names = F, - col.names = T, - append = TRUE, - sep = ";" - ) - } -) - - -output$downloadsetven <- downloadHandler( - filename = function() { - paste(basename(file_path_sans_ext(projectname())), - '_inter_venn', - '.csv', - sep = '') - }, - content = function(fname) { - if(input$dispvenn == "genes") - write.table( - try(mysetventocsv(setvglobalvenn(vennlist()[[2]], user_cont(), dll = T))), - fname, - na = "", - row.names = F, - col.names = T, - append = TRUE, - sep = ";" - ) - else - write.table( - try(mysetventocsv(setvglobalvenn(vennlist()[[1]], user_cont(), dll = T))), - fname, - na = "", - row.names = F, - col.names = T, - append = TRUE, - sep = ";" - ) +callModule(downoutputables, "savevennlist", projectname = projectname , suffix = "_filtered_venn.csv" , data = reactive(vennlist()[[2]]) , cont = user_cont, case = 1 ) + + +observe({ +req(input$dispvenn) +callModule(downoutputables, "saveallset", projectname = projectname , suffix = "_inter_venn.csv" , data = switch(input$dispvenn, genes = reactive(vennlist()[[2]]), transcripts =, probes = reactive(vennlist()[[1]])) , cont = user_cont , case = 2 ) +}) - } -) #' myindex is a reactive function returning the column indices for which there's more than one significant genes diff --git a/server/Venninter.R b/server/Venninter.R index 05536f1..4a0ac7a 100644 --- a/server/Venninter.R +++ b/server/Venninter.R @@ -141,16 +141,6 @@ venntopgenes <- reactive({ -output$downloadvennset = downloadHandler('venns-filtered.csv', - content = function(file) { - s = isolate(jvennrows$all()) - if(any(grepl("probes|transcripts", input$dispvenn)) ) - write.csv2(vennfinal()[[1]][s, , drop = FALSE], file) - else - write.csv2(vennfinal()[[2]][s, , drop = FALSE], file) - } -) - #' plottopgenes is an event reactive function which aim is to plot the top n genes selected by the user from the rendering data table #' diff --git a/ui.R b/ui.R index 495ce7f..a4c2ad2 100644 --- a/ui.R +++ b/ui.R @@ -342,8 +342,7 @@ body <- dashboardBody( div(id = "stripbox", box(title="Filter the table",width = 10, status = "primary", solidHeader = TRUE,collapsible = TRUE,collapsed = TRUE,icon = icon("arrow-down"), column(width=4, radioButtons("decidemethodstrip",label = "Choose your statistical method",choices = c("adj.p.val (FDR)" = "FDR", "p.value (raw)" = "None"),inline = TRUE)), - div( class= "myslidermain", column(3, sliderInput('fcstrip', "Choose your FC cutoff",min = 1, max=10, step = 1,value=1)), - column(3,sliderInput('pvalstrip', "Choose your pval cutoff", min=0.01, max=0.05, step=0.01,value=0.05))), + div( class= "myslidermain", cutoffElements("degstrip",3,3)), column(width=12, textOutput("selected_stripgene") @@ -558,12 +557,12 @@ body <- dashboardBody( div(style="display:inline-block", fluidRow( column(3, style="width:43%", - downloadButton('downloadvenn', "Download the data", - style ="color: #fff; background-color: #337ab7; border-color: #2e6da4")), + downloadFilestab("savevennlist", "Download the data")), column(3, - downloadButton("downloadsetven", "Download venn set" , style = - "color: #fff; background-color: #337ab7; border-color: #2e6da4"))))), + downloadFilestab("saveallset", "Download venn set")) + + ))), column(width=6, offset = 0, style='padding:0px;', @@ -649,10 +648,7 @@ body <- dashboardBody( p("for a total of"), htmlOutput("totalgenes"), p("genes with a P-value and FC treshold respectively set to "), - htmlOutput("myPVALvenn"), - p("and"), - htmlOutput("myFCvenn") - + tracketCutoff("degvenn") ), div( id = "container", @@ -709,16 +705,9 @@ body <- dashboardBody( placeholder = "grey70, white, steelblue4",width = "100%" ), - fluidRow( column(6, - sliderInput("pvalvenn","P-value treshold", - min = 0.01,max = 0.05, - value = 0.05,step = 0.01 - )), - - column(6, - sliderInput("fcvenn","FC treshold",min = 1, max = 10, - value = 1,step = 1 - ))), + fluidRow( + + cutoffElements("degvenn",c1=6,c2=6)), br(), fluidRow( @@ -825,7 +814,6 @@ body <- dashboardBody( actionButton("submit", "Submit")) ), - #plotOutput("warningsheat") conditionalPanel(condition = 'output.heatmbool', plotOutput("distPlot", width = "100%" , height = 1300) @@ -850,9 +838,7 @@ body <- dashboardBody( p('The selected rows for your heatmap are based on the '), textOutput("myMET"), p("method, with a P-value and FC treshold respectively set to "), - textOutput("myPVAL"), - p('and'), - textOutput("myFC") + tracketCutoff("deghm") ), conditionalPanel(condition = "input.maxgen != null", @@ -893,8 +879,7 @@ body <- dashboardBody( tabPanel( strong("Heatmap clusters"), value = "dfhmclu", - downloadButton('downloadcut', "Download the data", - style ="color: #fff; background-color: #337ab7; border-color: #2e6da4"), + downloadFilestab("downloadcut", "Download the data"), column( 12, h3("Table summarizing the heatmap"), @@ -912,7 +897,7 @@ body <- dashboardBody( )), tabPanel( strong("(GO) enrichment-based cluster analysis"),value="maingo", - downloadButton("savegohmdavxlsx", "Save your enrichment as xlsx" , style ="color: #fff; background-color: #337ab7; border-color: #2e6da4"), + downloadFilestab("savegohmdavxlsx", "Save your enrichment as xlsx"), conditionalPanel(condition = "input.GOana", div(class= "highvenn" , style="font-size:24px; text-align: center;", @@ -978,38 +963,23 @@ body <- dashboardBody( br(),br(), fluidRow( column(6, - numericInput( - # Create an input control for entry of numeric values + numericInput(# Create an input control for entry of numeric values 'maxgen', 'Maximal number of genes by comparison(s)', - NULL,min = 100,max = 2500 - )),column(6, - br(), - selectInput( + NULL, min = 100,max = 2500 + )), + column(6,br(), + selectInput( "decidemethod", "Choose your statistical method", choices = c("adj.p.val (FDR)"= "FDR", "p.value (raw)" = "None") ))), br(), - fluidRow( column(6, - sliderInput( - "pval", - "P-value treshold", - min = 0.01, - max = 0.05, - value = 0.05, - step = 0.01 - )), - column(6, - sliderInput( - "fc", - "FC treshold", - min = 1, - max = 10, - value = 1, - step = 1 - ))), + fluidRow( + cutoffElements("deghm",c1=6,c2=6) + ), + br(), div(id = 'center', strong("Advanced settings",style = "font-family: 'times'; font-size:20px; font-style: strong; ")), br(),