Commit b899b6ec authored by Midoux Cedric's avatar Midoux Cedric

transfo switch

parent ddb88463
......@@ -119,9 +119,9 @@ output$dataUI <- renderUI({
})
observeEvent(input$okData, {
physeq(NULL)
raw_physeq(NULL)
try(
physeq(
raw_physeq(
switch(
input$dataset,
"demo" =
......@@ -171,7 +171,8 @@ observeEvent(input$okData, {
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))
removeModal()
} else {
......@@ -190,7 +191,7 @@ filterSample <- function() {
inline = TRUE,
choices = c(
"Sample" = "sample",
sample_variables(physeq(), errorIfNULL = FALSE)
sample_variables(raw_physeq(), errorIfNULL = FALSE)
),
selected = "sample"
),
......@@ -211,10 +212,10 @@ output$filterUI <- renderUI({
if (input$filterCriteria == "sample") {
label <- "Sample to keep :"
choices <- sample_names(physeq())
choices <- sample_names(raw_physeq())
} else {
label <- "Variable to keep :"
choices <- levels(get_variable(physeq(), input$filterCriteria))
choices <- levels(get_variable(raw_physeq(), input$filterCriteria))
}
observe({
......@@ -250,16 +251,18 @@ observeEvent(input$selectData, {
} else {
try(
if (input$filterCriteria == "sample") {
physeq(prune_samples(samples = input$filterCheck, physeq()))
raw_physeq(prune_samples(samples = input$filterCheck, raw_physeq()))
} else {
criteria <<- input$filterCriteria
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,
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()
} else {
showModal(dataInput(failed = TRUE))
......@@ -275,9 +278,8 @@ transformSample <- function() {
radioButtons(
inputId = "transformFun",
label = "Transform function : ",
selected = "none",
choices = c("None" = "none",
"Proportional Transformation" = "prop",
selected = NULL,
choices = c("Proportional Transformation" = "prop",
"Square Root Transformation" = "sqrt",
"Square Root Proportional Transformation" = "sqrtprop",
"Centered Log-Ratio (CLR) Transformation" = "clr")
......@@ -286,7 +288,6 @@ transformSample <- function() {
wellPanel(verbatimTextOutput("transformFun")),
footer = tagList(modalButton("Cancel"),
actionButton(inputId = "okData", label = "Refresh transformation"),
actionButton(inputId = "transformData", label = "Transforme")
)
)
......@@ -295,7 +296,6 @@ transformSample <- function() {
output$transformFun <- renderText({
validate(need(input$transformFun, ""))
switch (input$transformFun,
"none" = "",
"prop" = paste("count_to_prop <- function(x) {return( x / sum(x) )}",
"data_prop <- transform_sample_counts(data, count_to_prop)",
sep = "\n"),
......@@ -321,19 +321,19 @@ observeEvent(input$transformData, {
{
removeModal()
} else {
shinyWidgets::updateSwitchInput(session = session, inputId = "useTransf", value = FALSE)
try(
switch (input$transformFun,
"none" = {return(physeq())},
"prop" = {
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" = {
physeq(transform_sample_counts(physeq(), sqrt))
transform_physeq(transform_sample_counts(raw_physeq(), sqrt))
},
"sqrtprop" = {
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" = {
gm_mean <- function(x, na.rm=TRUE) {
......@@ -344,20 +344,30 @@ observeEvent(input$transformData, {
x <- log(x/gm_mean(x), base)
return(x)
}
physeq(transform_sample_counts(physeq(), clr))
transform_physeq(transform_sample_counts(raw_physeq(), clr))
}
),
silent = 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()
} else {
showModal(dataInput(failed = TRUE))
}
}
}
})
observeEvent(input$useTransf,
if (input$useTransf) {
physeq(transform_physeq())
} else {
physeq(raw_physeq())
}
)
### Download Data ###
dataDownload <- function() {
modalDialog(
......
......@@ -27,7 +27,9 @@ shinyServer
source("panels/tree-server.R", local = TRUE)
physeq <- reactiveVal()
raw_physeq <- reactiveVal()
transform_physeq <- reactiveVal()
showModal(dataInput())
observeEvent(input$dataButton, {
......
......@@ -28,6 +28,13 @@ dashboardHeader(title = "Easy16S"),
"Transform abundance",
icon = icon("square-root-alt"),
style = "width: 80% ; color: black ; background-color: gray90"),
shinyWidgets::switchInput("useTransf",
value = FALSE,
label = "Transformed Data",
#inline = TRUE,
size = "mini",
labelWidth = "100%"
),
actionButton("downloadButton",
"Download data",
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