Skip to content

Instantly share code, notes, and snippets.

@tiagochst
Last active May 5, 2017 16:22
Show Gist options
  • Save tiagochst/846a0fac53003e01b6bacc46d73ce25c to your computer and use it in GitHub Desktop.
Save tiagochst/846a0fac53003e01b6bacc46d73ce25c to your computer and use it in GitHub Desktop.
deps <- c("shiny","shinyFiles","methylumi")
for(pkg in deps) if (!pkg %in% installed.packages()) biocLite(pkg, dependencies = TRUE)
library(shiny)
library(shinyFiles)
library(methylumi)
ui <- pageWithSidebar(
headerPanel(
'DNA methylation idat normalization with methylumi',
'methylumi normalization'
),
sidebarPanel(
shinyFilesButton('file', 'Select idat files', 'Please select a file', TRUE),
actionButton("normalize",
"Normalize",
style = "background-color: #000080;
color: #FFFFFF;
margin-left: auto;
margin-right: auto;
width: auto",
icon = icon("flask"))
),
mainPanel(
tags$h4('The output of a file selection'),
tags$p(HTML('Files selected:')),
verbatimTextOutput('filepaths')
)
)
server <- function(input, output, session) {
volumes <- c(wd="./",home=Sys.getenv("HOME"), getVolumes()(), temp=tempdir())
# A notification ID
shinyFileChoose(input, 'file', roots=volumes, session=session, restrictions=system.file(package='base'),filetypes=c('', 'idat'))
output$filepaths <- renderPrint({parseFilePaths(volumes, input$file)})
observeEvent(input$normalize, {
files <- as.character(parseFilePaths(volumes, isolate({input$file}))$datapath)
withProgress(message = 'Calculation in progress',
detail = 'This may take a while...', value = 0, {
incProgress(1/4,message = "Reading data")
idat <- methylumIDAT(unique(gsub("_Red.idat|_Grn.idat","",basename(files))),idatPath = unique(dirname(files)))
incProgress(1/4,message = "Normalizing data")
proc <- stripOOB(normalizeMethyLumiSet(methylumi.bgcorr(idat)))
betaValue <- betas(proc)
incProgress(1/4,message = "Saving results")
save(betaValue, file="betaValues.Rda")
})
showNotification("File saved as: betaValues.Rda", duration = NULL)
})
}
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment