Commit b899b6ec authored by Midoux Cedric's avatar Midoux Cedric

transfo switch

parent ddb88463
...@@ -119,9 +119,9 @@ output$dataUI <- renderUI({ ...@@ -119,9 +119,9 @@ output$dataUI <- renderUI({
}) })
observeEvent(input$okData, { observeEvent(input$okData, {
physeq(NULL) raw_physeq(NULL)
try( try(
physeq( raw_physeq(
switch( switch(
input$dataset, input$dataset,
"demo" = "demo" =
...@@ -171,7 +171,8 @@ observeEvent(input$okData, { ...@@ -171,7 +171,8 @@ observeEvent(input$okData, {
outFile = showModal(dataInput(failed = TRUE)) outFile = showModal(dataInput(failed = TRUE))
) )
if (inherits(physeq(), "phyloseq")) { if (inherits(raw_physeq(), "phyloseq")) {
physeq(raw_physeq())
message(paste("[Easy16S] Correct upload with", input$dataset, "mode :", message)) message(paste("[Easy16S] Correct upload with", input$dataset, "mode :", message))
removeModal() removeModal()
} else { } else {
...@@ -190,7 +191,7 @@ filterSample <- function() { ...@@ -190,7 +191,7 @@ filterSample <- function() {
inline = TRUE, inline = TRUE,
choices = c( choices = c(
"Sample" = "sample", "Sample" = "sample",
sample_variables(physeq(), errorIfNULL = FALSE) sample_variables(raw_physeq(), errorIfNULL = FALSE)
), ),
selected = "sample" selected = "sample"
), ),
...@@ -211,10 +212,10 @@ output$filterUI <- renderUI({ ...@@ -211,10 +212,10 @@ output$filterUI <- renderUI({
if (input$filterCriteria == "sample") { if (input$filterCriteria == "sample") {
label <- "Sample to keep :" label <- "Sample to keep :"
choices <- sample_names(physeq()) choices <- sample_names(raw_physeq())
} else { } else {
label <- "Variable to keep :" label <- "Variable to keep :"
choices <- levels(get_variable(physeq(), input$filterCriteria)) choices <- levels(get_variable(raw_physeq(), input$filterCriteria))
} }
observe({ observe({
...@@ -250,16 +251,18 @@ observeEvent(input$selectData, { ...@@ -250,16 +251,18 @@ observeEvent(input$selectData, {
} else { } else {
try( try(
if (input$filterCriteria == "sample") { if (input$filterCriteria == "sample") {
physeq(prune_samples(samples = input$filterCheck, physeq())) raw_physeq(prune_samples(samples = input$filterCheck, raw_physeq()))
} else { } else {
criteria <<- input$filterCriteria criteria <<- input$filterCriteria
check <<- input$filterCheck check <<- input$filterCheck
physeq(subset_samples(physeq(), eval(parse(text = criteria)) %in% check)) raw_physeq(subset_samples(raw_physeq(), eval(parse(text = criteria)) %in% check))
}, },
silent = TRUE, silent = TRUE,
outFile = showModal(dataInput(failed = TRUE))) outFile = showModal(dataInput(failed = TRUE)))
if (inherits(physeq(), "phyloseq")) { if (inherits(raw_physeq(), "phyloseq")) {
message <- paste(input$filterCheck, collapse = ", ")
message(paste("[Easy16S] Select some samples :", message))
removeModal() removeModal()
} else { } else {
showModal(dataInput(failed = TRUE)) showModal(dataInput(failed = TRUE))
...@@ -275,9 +278,8 @@ transformSample <- function() { ...@@ -275,9 +278,8 @@ transformSample <- function() {
radioButtons( radioButtons(
inputId = "transformFun", inputId = "transformFun",
label = "Transform function : ", label = "Transform function : ",
selected = "none", selected = NULL,
choices = c("None" = "none", choices = c("Proportional Transformation" = "prop",
"Proportional Transformation" = "prop",
"Square Root Transformation" = "sqrt", "Square Root Transformation" = "sqrt",
"Square Root Proportional Transformation" = "sqrtprop", "Square Root Proportional Transformation" = "sqrtprop",
"Centered Log-Ratio (CLR) Transformation" = "clr") "Centered Log-Ratio (CLR) Transformation" = "clr")
...@@ -286,7 +288,6 @@ transformSample <- function() { ...@@ -286,7 +288,6 @@ transformSample <- function() {
wellPanel(verbatimTextOutput("transformFun")), wellPanel(verbatimTextOutput("transformFun")),
footer = tagList(modalButton("Cancel"), footer = tagList(modalButton("Cancel"),
actionButton(inputId = "okData", label = "Refresh transformation"),
actionButton(inputId = "transformData", label = "Transforme") actionButton(inputId = "transformData", label = "Transforme")
) )
) )
...@@ -295,7 +296,6 @@ transformSample <- function() { ...@@ -295,7 +296,6 @@ transformSample <- function() {
output$transformFun <- renderText({ output$transformFun <- renderText({
validate(need(input$transformFun, "")) validate(need(input$transformFun, ""))
switch (input$transformFun, switch (input$transformFun,
"none" = "",
"prop" = paste("count_to_prop <- function(x) {return( x / sum(x) )}", "prop" = paste("count_to_prop <- function(x) {return( x / sum(x) )}",
"data_prop <- transform_sample_counts(data, count_to_prop)", "data_prop <- transform_sample_counts(data, count_to_prop)",
sep = "\n"), sep = "\n"),
...@@ -321,19 +321,19 @@ observeEvent(input$transformData, { ...@@ -321,19 +321,19 @@ observeEvent(input$transformData, {
{ {
removeModal() removeModal()
} else { } else {
shinyWidgets::updateSwitchInput(session = session, inputId = "useTransf", value = FALSE)
try( try(
switch (input$transformFun, switch (input$transformFun,
"none" = {return(physeq())},
"prop" = { "prop" = {
count_to_prop <- function(x) {return( x / sum(x) )} count_to_prop <- function(x) {return( x / sum(x) )}
physeq(transform_sample_counts(physeq(), count_to_prop)) transform_physeq(transform_sample_counts(raw_physeq(), count_to_prop))
}, },
"sqrt" = { "sqrt" = {
physeq(transform_sample_counts(physeq(), sqrt)) transform_physeq(transform_sample_counts(raw_physeq(), sqrt))
}, },
"sqrtprop" = { "sqrtprop" = {
count_to_sqrtprop <- function(x) {return(sqrt(x / sum(x)))} count_to_sqrtprop <- function(x) {return(sqrt(x / sum(x)))}
physeq(transform_sample_counts(physeq(), count_to_sqrtprop)) transform_physeq(transform_sample_counts(raw_physeq(), count_to_sqrtprop))
}, },
"clr" = { "clr" = {
gm_mean <- function(x, na.rm=TRUE) { gm_mean <- function(x, na.rm=TRUE) {
...@@ -344,20 +344,30 @@ observeEvent(input$transformData, { ...@@ -344,20 +344,30 @@ observeEvent(input$transformData, {
x <- log(x/gm_mean(x), base) x <- log(x/gm_mean(x), base)
return(x) return(x)
} }
physeq(transform_sample_counts(physeq(), clr)) transform_physeq(transform_sample_counts(raw_physeq(), clr))
} }
), ),
silent = TRUE, silent = TRUE,
outFile = showModal(dataInput(failed = TRUE))) outFile = showModal(dataInput(failed = TRUE)))
if (class(physeq()) == "phyloseq") { if (class(transform_physeq()) == "phyloseq") {
message(paste("[Easy16S] Transfom data :", input$transformFun))
shinyWidgets::updateSwitchInput(session = session, inputId = "useTransf", value = TRUE)
removeModal() removeModal()
} else { } else {
showModal(dataInput(failed = TRUE)) showModal(dataInput(failed = TRUE))
} }
} }
}) })
observeEvent(input$useTransf,
if (input$useTransf) {
physeq(transform_physeq())
} else {
physeq(raw_physeq())
}
)
### Download Data ### ### Download Data ###
dataDownload <- function() { dataDownload <- function() {
modalDialog( modalDialog(
......
...@@ -27,7 +27,9 @@ shinyServer ...@@ -27,7 +27,9 @@ shinyServer
source("panels/tree-server.R", local = TRUE) source("panels/tree-server.R", local = TRUE)
physeq <- reactiveVal() physeq <- reactiveVal()
raw_physeq <- reactiveVal()
transform_physeq <- reactiveVal()
showModal(dataInput()) showModal(dataInput())
observeEvent(input$dataButton, { observeEvent(input$dataButton, {
......
...@@ -28,6 +28,13 @@ dashboardHeader(title = "Easy16S"), ...@@ -28,6 +28,13 @@ dashboardHeader(title = "Easy16S"),
"Transform abundance", "Transform abundance",
icon = icon("square-root-alt"), icon = icon("square-root-alt"),
style = "width: 80% ; color: black ; background-color: gray90"), style = "width: 80% ; color: black ; background-color: gray90"),
shinyWidgets::switchInput("useTransf",
value = FALSE,
label = "Transformed Data",
#inline = TRUE,
size = "mini",
labelWidth = "100%"
),
actionButton("downloadButton", actionButton("downloadButton",
"Download data", "Download data",
icon = icon("download"), icon = icon("download"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment