je découvre shiny en arrivant sur un nouveau projet où je reprend un pipeline.
Le pipeline a été écrit sous R 3.4.3 et shiny 1.0.5, et s'exécute avec Rstudio. Je dois faire évoluer ce pipeline et je suis sous R 3.5.1 et shiny 1.2 mais dans cet environnement, il plante.
La page user-friendly (à destination du biologiste) permet :
- le choix du répertoire pour sauvegarder les résultats : le répertoire choisi apparaît sur la page
- le choix du répertoire (rep_data) où sont les données NGS à analyser (dans des sous-répertoires) : le répertoire choisi apparaît sur la page
- le choix de l'analyse à faire (j'ai restreint à une seule pour simplification)
- et lancer l'analyse
J'ai simplifié l'analyse NGS pour mes tests à :
Code : Tout sélectionner
pour chaque sous-répertoire du rép_data
ajouter le chemin complet du sous-répertoire dans un fichier
fin_pour
voici le code correspondant :
Code : Tout sélectionner
library(shiny)
packages <- c("data.table", "Biostrings", "ggplot2", "ggridges", "plyr", "reshape2", "rstudioapi", "scales",
"shinyBS", "shinycssloaders","shinyFiles", "shinyjs", "tidyr", "viridis", "viridisLite", "yaml")
# shinyBS = shiny Bootstrap Controls as bsTooltip
## If a package if not available, install it.
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())))}
#Load the packages
lapply(packages, require, character.only = TRUE)
# /***** Define UI for app *****/
ui <- fluidPage(
## App title
titlePanel(title ="My_pipeline"),
## ask for main directory
sidebarLayout(
sidebarPanel(shinyDirButton("nanopath", "Main directory", "Please choose main directory")),
mainPanel(h4("Main directory"),
verbatimTextOutput("nanopath", placeholder = TRUE))),
## tooltip for main directory
bsTooltip('nanopath', "The folder where you save the outcome of Nanoflow.", placement="top"),
## ask for fast5 raw directory
sidebarLayout( #
sidebarPanel(shinyDirButton("rawFast5Dir", "Fast5 raw directory", "Please choose Fast5 raw directory")),
mainPanel(h4("Fast5 raw directory"),
verbatimTextOutput("rawFast5Dir", placeholder = TRUE))),
## tooltip for fast5 raw directory
bsTooltip('rawFast5Dir', "A Fast5 folder created during the MinION run.", placement="top"),
## set the launch button
sidebarLayout(
sidebarPanel(
actionButton("goButton", "Launch!"),
p("Click to start the analysis.")),
mainPanel(
h5(textOutput("progress.1", container = span)))),
## ask for input (analysis type)
column(4,
selectInput("workflow", h3("Select Analysis"),
choices = list("Basecalling"),
selected = 1))
)
# /***** end of UI *****/
# /***** Define server for app *****/
server <- function(input, output) {
## Set Main directory path
shinyDirChoose(input, "nanopath", roots = c(home = '~'), filetypes = c('', 'txt')) # show only *.txt files
nanopath <- reactive(input$nanopath) ## Get the path
output$nanopath <- renderText({ ## Display the path
parseDirPath(c(home = '~'), nanopath())
})
## Set the working directory
observeEvent(ignoreNULL = TRUE,
eventExpr = {
input$nanopath
},
handlerExpr = {
home <- normalizePath("~")
nanodir <<- file.path(home, paste(unlist(nanopath()$path), collapse = .Platform$file.sep))
setwd(nanodir)
}
)
## Set the Fast5dir path -- original code --
shinyDirChoose(input, 'rawFast5Dir', roots = c(home = '~'), filetypes = c('', 'txt'))
rawFast5Dir <- reactive(input$rawFast5Dir) ## Get the path
output$rawFast5Dir <- renderText({ ## Display the path
parseDirPath(c(home = '~'), rawFast5Dir())
})
## Set the fast5 and basecalled directories
observeEvent(ignoreNULL = TRUE,
eventExpr = {
input$rawFast5Dir
},
handlerExpr = {
home <- normalizePath("~")
fast5path <<- file.path(home, paste(unlist(rawFast5Dir()$path[-1]), collapse = .Platform$file.sep))
basecalledDir <<- paste(nanodir, "/basecalled",sep='') # gsub('(.*)/\\w+', '\\1'
}
)
## clicking button. The outcome will depend of the chosen options
observeEvent(input$goButton, {
if(input$workflow == 'Basecalling'){
withProgress(message = 'Basecalling', value = 0, {
# Number of times we'll go through the loop
n <- as.numeric(system(paste('ls -d ', fast5path, '/*/ | wc -l', sep=""), intern = TRUE))
system(paste('mkdir -p ', basecalledDir, sep=''))
fast5folders <- system(paste('ls -d ', fast5path, '/*/ ', sep=""), intern = TRUE)
fast5folders<- substr(fast5folders, 1, nchar(fast5folders)-1)
for(i in fast5folders){
incProgress(1/n, detail = paste("Processing folder ", basename(i)))
system(paste('echo ',i, ' >> ', basecalledDir, '/toto.txt', sep='' ))
}
})
output$progress.1 <- renderText({
paste("Basecalling finished at ", Sys.time(), ". Basecalled fast5 files were saved to: ", basecalledDir, sep="")
})
}
})
}
# /***** end of server *****/
# /***** run app *****/
shinyApp(ui = ui, server = server)
Ce code fonctionne sous R 3.4.3 et shiny 1.0.5
Mais sour R 3.5.1 et shiny 1.2, je ne peux choisir aucun répertoire et j'ai ce message erreur :
Code : Tout sélectionner
Warning: Error in $: $ operator is invalid for atomic vectors
79: unlist
72: observeEventHandler [/Users/2018eb005/Documents/work/byPeople/Emmanuelle/app-NanoFlow-EB/app.R#84]
Après plusieurs recherches sur google, j'ai lu qu'avec shiny1.2, il fallait préciser le type de la valeur dans handleExp comme cela :
Code : Tout sélectionner
handlerExpr = {
req(is.list(nanopath)) ## new v.1.2
home <- normalizePath("~")
nanodir <<- file.path(home, paste(unlist(nanopath()$path), collapse = .Platform$file.sep))
setwd(nanodir)
}
et
Code : Tout sélectionner
handlerExpr = {
req(is.list(rawFast5Dir)) ## new v.1.2
home <- normalizePath("~")
fast5path <<- file.path(home, paste(unlist(rawFast5Dir()$path[-1]), collapse = .Platform$file.sep))
basecalledDir <<- paste(nanodir, "/basecalled",sep='') # gsub('(.*)/\\w+', '\\1'
}
Mais j'obtiens alors un autre message erreur :
Code : Tout sélectionner
Warning: Error in eval: objet 'fast5path' introuvable
81: eval
80: eval
78: standardGeneric
77: paste
72: observeEventHandler [/Users/2018eb005/Documents/work/byPeople/Emmanuelle/app-NanoFlow-EB/app.R#112]
Au cours de mes différents test, j'ai aussi eu un message du genre
Code : Tout sélectionner
setwd() : could'nt change the working directory
Est-ce lié au problème précédent?
Et ce n'est que le début du pipeline.... :-/
Je continue à débugger mais c'est à tâton, alors quelqu'un pourrait-il m'aider, s'il vous plaît? Merci!!
Emmanuelle