internal_masque.R 10.1 KB
Newer Older
svolant's avatar
svolant committed
1
2
3
Project_status <- function(masque_key,curdir){

  passOK = FALSE;status = NULL;file = NULL
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
4
  json_files = list.files(paste(curdir,"www","masque",sep= .Platform$file.sep),pattern = paste("file", masque_key, ".json", sep=""),recursive = TRUE)
svolant's avatar
svolant committed
5
  allpass = gsub(gsub(json_files,pattern = ".*file",replacement = ""),pattern = ".json",replacement = "")
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
6

svolant's avatar
svolant committed
7
8
9
10
11
12
13
14
15
  if(length(allpass)>0){
    passOK = any(masque_key==allpass)
    if(passOK){
      ind = which(masque_key==allpass)[1]
      file = paste(curdir,"www","masque",json_files[ind],sep= .Platform$file.sep)
      status = gsub(json_files[ind],pattern = "/.*",replacement = "")
    }
  }
  
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
16
  # return(list(status=status,file=json_file,passOK=passOK))
svolant's avatar
svolant committed
17
18
19
20
21
22
23
  return(list(status=status,file=file,passOK=passOK))
}




Project_box_result <- function(masque_key,curdir){
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
24

svolant's avatar
svolant committed
25
26
27
  res = NULL
  PS = Project_status(masque_key,curdir)
  
svolant's avatar
svolant committed
28
29
  if(PS$passOK){
    if(PS$status=="done")
svolant's avatar
svolant committed
30
    {
svolant's avatar
svolant committed
31
32
33
      res = list()
      json_file = PS$file
      folder_name = paste('file',masque_key,sep="")
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
34
35
      json_file = paste(curdir,"www","masque","done",paste(folder_name, ".json", sep=""),sep= .Platform$file.sep)
      json_data = rjson::fromJSON(file=json_file)
svolant's avatar
svolant committed
36
      
svolant's avatar
svolant committed
37
      ### Paste file name as folder
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
38
39
      annot_process = paste(curdir,"www","masque","done",folder_name,"shaman_process_annotation.tsv",sep= .Platform$file.sep)

svolant's avatar
svolant committed
40
41
42
      ## Waiting for file creation (max 3min)
      start = Sys.time(); diff = 0
      while(!file.exists(annot_process) && diff<180){
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
43
        annot_process = paste(curdir,"www","masque","done",folder_name,"shaman_process_annotation.tsv",sep= .Platform$file.sep)
svolant's avatar
svolant committed
44
45
46
        tmp = Sys.time()
        diff = tmp-start
      }
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
47

svolant's avatar
svolant committed
48
49
50
      if(file.exists(annot_process))
      {
        ap = read.csv(annot_process,sep="\t")
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
51
52
        if(json_data$type == "16S") db_choices = c("Silva" = "silva","Greengenes" = "greengenes", "RDP"= "rdp")
        else if(json_data$type == "23S_28S" || json_data$type == "18S") db_choices = c("Silva" = "silva","RDP"= "rdp")
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
53
54
        else db_choices = c("Findley" = "findley", "Underhill"= "underhill", "Unite"= "unite", "RDP"= "rdp")
        #build_process = paste(curdir,"www","masque","done",folder_name,"shaman_process_annotation.tsv",sep= .Platform$file.sep)
svolant's avatar
svolant committed
55
        res[[1]] = fluidRow(
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
56
57
          #HTML('<center><h1><strong>Your project is done !</strong></h1> <br/> <em><h4> Hereafter is a summary of the building and annotation processes</h4> </em><br/> </center>'),
          HTML('<center><h1><strong>Your project is done !</strong></h1></center>'),
svolant's avatar
svolant committed
58
          br(),
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
59
60
          column(width=4,
                 h3("OTU building process"),
61
62
63
64
65
                 shinydashboardshaman::valueBox(ap$Count[1],shiny::tags$strong(shiny::tags$h5("Number of amplicons", style = "width: 70%;")), color = "light-blue", width = NULL, icon = uiOutput("amplicon_icon")),
                 shinydashboardshaman::valueBox(ap$Count[2],shiny::tags$strong(shiny::tags$h5("Remaining amplicons after dereplication", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("dereplication_icon")),
                 shinydashboardshaman::valueBox(ap$Count[3],shiny::tags$strong(shiny::tags$h5("Remaining amplicons after removing singletons", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("singleton_icon")),
                 shinydashboardshaman::valueBox(ap$Count[4],shiny::tags$strong(shiny::tags$h5("Remaining amplicons after removing chimera", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("chimera_icon")),
                 shinydashboardshaman::valueBox(ap$Count[5],shiny::tags$strong(shiny::tags$h5("Number of OTU", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("otu_icon"))
svolant's avatar
svolant committed
66
          ),
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
67
          #column(width=5, div(img(src = "masque.png",width = "50%",height = "20%"))),
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
68
          if(json_data$type == "16S"){
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
69
            column(width=5,
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
70
                   strong(h3("16S annotation process")),
71
72
73
                   shinydashboardshaman::valueBox(ap$Count[6],shiny::tags$strong(shiny::tags$h5("Number of OTU annotated by SILVA", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("silva_icon")),
                   shinydashboardshaman::valueBox(ap$Count[7],shiny::tags$strong(shiny::tags$h5("Number of OTU annotated by Greengenes", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("greengenes_icon")),
                   shinydashboardshaman::valueBox(ap$Count[8],shiny::tags$strong(shiny::tags$h5("Number of OTU annotated by RDP", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("rdp_icon"))
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
74
75
            )
          }
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
76
          else if(json_data$type == "18S"){
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
77
78
            column(width=5,
                   strong(h3("18S annotation process")),
79
80
                   shinydashboardshaman::valueBox(ap$Count[6],shiny::tags$strong(shiny::tags$h5("Number of OTU annotated by SILVA", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("silva_icon")),
                   shinydashboardshaman::valueBox(ap$Count[7],shiny::tags$strong(shiny::tags$h5("Number of OTU annotated by RDP", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("rdp_icon"))
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
81
82
            )
          }
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
83
          else if(json_data$type == "23S_28S"){
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
84
85
            column(width=5,
                   strong(h3("23S/28S annotation process")),
86
87
                   shinydashboardshaman::valueBox(ap$Count[6],shiny::tags$strong(shiny::tags$h5("Number of OTU annotated by SILVA", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("silva_icon")),
                   shinydashboardshaman::valueBox(ap$Count[7],shiny::tags$strong(shiny::tags$h5("Number of OTU annotated by RDP", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("rdp_icon"))
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
88
89
90
91
92
            )
          }
          else{
            column(width=5,
                   strong(h3("ITS annotation process")),
93
94
95
96
                   shinydashboardshaman::valueBox(ap$Count[6],shiny::tags$strong(shiny::tags$h5("Number of OTU annotated by Unite", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("unite_icon")),
                   shinydashboardshaman::valueBox(ap$Count[7],shiny::tags$strong(shiny::tags$h5("Number of OTU annotated by Findley", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("findley_icon")),
                   shinydashboardshaman::valueBox(ap$Count[8],shiny::tags$strong(shiny::tags$h5("Number of OTU annotated by Underhill", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("underhill_icon")),
                   shinydashboardshaman::valueBox(ap$Count[9],shiny::tags$strong(shiny::tags$h5("Number of OTU annotated by RDP", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("rdp_icon"))
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
97
98
99
100
101
102
103
104
105
            )
         },
         #offset = 4,
         column(width=3,
                strong(h3("Start statistical analysis")),
                box(title="Load the results",width = NULL, background = "light-blue",
                    selectInput("masque_db","Select the database",choices=db_choices),
                    conditionalPanel(condition="input.masque_db=='rdp'",numericInput("rdp_thres",h6(strong("Threshold:")),0.5,step=0.01,min=0.01,max=1)),
                    actionButton("LoadResMasque", "Upload the results",icon=icon('upload')),
106
                    shiny::tags$style(type='text/css', "#LoadResMasque { width:100%; }")#,
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
107
                    #receiveSweetAlert(messageId = "LoadResMasque")
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
108
                ),
109
                #shinydashboardshaman::box(title="Upload the results",width = NULL, background = "light-blue",
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
110
                #selectInput("masque_database","Select the database",choices=c("Silva" = "silva","Greengenes" = "greengenes", "MARDE"="merde")),
111
                #shiny::tags$style(type='text/css', "#masque_database { width:100%; margin-top: 5px;}"),
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
112
                #actionButton("RunResMasque",label = "Upload the results",icon=icon('upload')),
113
                #shiny::tags$style(type='text/css', "#RunResMasque { width:100%; margin-top: 15px;}")
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
114
115
116
                #),
                box(id="box-zip",title="Download .zip file",width = NULL, status = "success",
                    downloadButton('Download_masque_zip', 'Download the results'),
117
                    shiny::tags$style(type='text/css', "#Download_masque_zip { width:100%;}")
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
118
119
120
121
                )
         )
        )
      } else{res =HTML('<center><h1><strong>Your project is done !</strong></h1> <br/> <em><h4>Result can not be shown...</h4> </em> </center>')}
svolant's avatar
svolant committed
122
      
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
123
      build_process = paste(curdir,"www","masque","done",folder_name,"shaman_process_build.tsv",sep= .Platform$file.sep)
svolant's avatar
svolant committed
124
125
126
127
      if(file.exists(build_process))
      {
        ap = read.csv(build_process,sep="\t")
      
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
128
        res[[2]] = fluidRow(column(width=12,strong(h3("Detailed process table")),DT::dataTableOutput("build_process_table")))
svolant's avatar
svolant committed
129
      }
svolant's avatar
svolant committed
130
131
132
133
      
      
    }
    
svolant's avatar
svolant committed
134
135
136
137
138
    if(PS$status=="doing"){
      res = fluidRow(
        HTML('<center><h1><strong>Your project is currently running !</strong></h1> <br/> <br/> </center>'),
        inlineCSS(gaugeCSS),
        gaugeOutput("gaugeMasque_progress", width = "100%", height = "100%")
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
139
140
141
        #jscode <- "shinyjs.refresh = function() { history.go(0); }",
        #useShinyjs(),
        #extendShinyjs(text = jscode),
svolant's avatar
svolant committed
142
143
      )
    }
svolant's avatar
svolant committed
144
    
svolant's avatar
svolant committed
145
146
147
    if(PS$status=="error"){
      error_message = "Failed"
      json_file = PS$file
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
148
      error_file = paste(curdir,"www","masque","error",paste('file',masque_key,"_error.txt",sep=""),sep= .Platform$file.sep)
svolant's avatar
svolant committed
149
  
svolant's avatar
svolant committed
150
      if(file.exists(error_file)){error_message = read_lines(error_file)}
svolant's avatar
svolant committed
151
      
svolant's avatar
svolant committed
152
      res = fluidRow(
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
153
                HTML('<center><h1><strong>The workflow failed during progression</strong></h1> <br/> </center>'),
svolant's avatar
svolant committed
154
155
156
        
                column(width = 12,
                       div(style = "background-color: white; margin: 0 auto;width: 50%; text-align:center;border:1px solid red",
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
157
158
                           h4(strong("Workflow error message")),
                           hr(style = "width: 70%;text-align:left;"),
svolant's avatar
svolant committed
159
160
161
162
163
164
                           HTML(paste(error_message,collapse = " <br/> ")),
                           br()
                       )
                )
          )
    }
svolant's avatar
svolant committed
165
166
167
168
169
  }
  
  return(list(box=res,PS=PS))
  
}