internal_masque.R 9.84 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
61
62
63
64
65
          column(width=4,
                 h3("OTU building process"),
                 shinydashboard::valueBox(ap$Count[1],tags$strong(tags$h5("Number of amplicons", style = "width: 70%;")), color = "light-blue", width = NULL, icon = uiOutput("amplicon_icon")),
                 shinydashboard::valueBox(ap$Count[2],tags$strong(tags$h5("Remaining amplicons after dereplication", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("dereplication_icon")),
                 shinydashboard::valueBox(ap$Count[3],tags$strong(tags$h5("Remaining amplicons after removing singletons", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("singleton_icon")),
                 shinydashboard::valueBox(ap$Count[4],tags$strong(tags$h5("Remaining amplicons after removing chimera", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("chimera_icon")),
                 shinydashboard::valueBox(ap$Count[5],tags$strong(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")),
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
71
72
73
                   shinydashboard::valueBox(ap$Count[6],tags$strong(tags$h5("Number of OTU annotated by SILVA", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("silva_icon")),
                   shinydashboard::valueBox(ap$Count[7],tags$strong(tags$h5("Number of OTU annotated by Greengenes", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("greengenes_icon")),
                   shinydashboard::valueBox(ap$Count[8],tags$strong(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
79
80
            column(width=5,
                   strong(h3("18S annotation process")),
                   shinydashboard::valueBox(ap$Count[6],tags$strong(tags$h5("Number of OTU annotated by SILVA", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("silva_icon")),
                   shinydashboard::valueBox(ap$Count[8],tags$strong(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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
            column(width=5,
                   strong(h3("23S/28S annotation process")),
                   shinydashboard::valueBox(ap$Count[6],tags$strong(tags$h5("Number of OTU annotated by SILVA", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("silva_icon")),
                   shinydashboard::valueBox(ap$Count[7],tags$strong(tags$h5("Number of OTU annotated by RDP", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("rdp_icon"))
            )
          }
          else{
            column(width=5,
                   strong(h3("ITS annotation process")),
                   shinydashboard::valueBox(ap$Count[6],tags$strong(tags$h5("Number of OTU annotated by Unite", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("unite_icon")),
                   shinydashboard::valueBox(ap$Count[7],tags$strong(tags$h5("Number of OTU annotated by Findley", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("findley_icon")),
                   shinydashboard::valueBox(ap$Count[8],tags$strong(tags$h5("Number of OTU annotated by Underhill", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("underhill_icon")),
                   shinydashboard::valueBox(ap$Count[9],tags$strong(tags$h5("Number of OTU annotated by RDP", style = "width: 70%;")), color = "light-blue", width = NULL,icon = uiOutput("rdp_icon"))
            )
         },
         #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')),
                    tags$style(type='text/css', "#LoadResMasque { width:100%; }"),
                    receiveSweetAlert(messageId = "LoadResMasque")
                ),
                #shinydashboard::box(title="Upload the results",width = NULL, background = "light-blue",
                #selectInput("masque_database","Select the database",choices=c("Silva" = "silva","Greengenes" = "greengenes", "MARDE"="merde")),
                #tags$style(type='text/css', "#masque_database { width:100%; margin-top: 5px;}"),
                #actionButton("RunResMasque",label = "Upload the results",icon=icon('upload')),
                #tags$style(type='text/css', "#RunResMasque { width:100%; margin-top: 15px;}")
                #),
                #receiveSweetAlert(messageId = "WTF2"),
                box(id="box-zip",title="Download .zip file",width = NULL, status = "success",
                    downloadButton('Download_masque_zip', 'Download the results'),
                    tags$style(type='text/css', "#Download_masque_zip { width:100%;}")
                )
         )
        )
      } 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
123
      
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
124
      build_process = paste(curdir,"www","masque","done",folder_name,"shaman_process_build.tsv",sep= .Platform$file.sep)
svolant's avatar
svolant committed
125
126
127
128
      if(file.exists(build_process))
      {
        ap = read.csv(build_process,sep="\t")
      
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
129
        res[[2]] = fluidRow(column(width=12,strong(h3("Detailed process table")),DT::dataTableOutput("build_process_table")))
svolant's avatar
svolant committed
130
      }
svolant's avatar
svolant committed
131
132
133
134
      
      
    }
    
svolant's avatar
svolant committed
135
136
137
138
139
    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
140
141
142
        #jscode <- "shinyjs.refresh = function() { history.go(0); }",
        #useShinyjs(),
        #extendShinyjs(text = jscode),
svolant's avatar
svolant committed
143
144
      )
    }
svolant's avatar
svolant committed
145
    
svolant's avatar
svolant committed
146
147
148
    if(PS$status=="error"){
      error_message = "Failed"
      json_file = PS$file
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
149
      error_file = paste(curdir,"www","masque","error",paste('file',masque_key,"_error.txt",sep=""),sep= .Platform$file.sep)
svolant's avatar
svolant committed
150
  
svolant's avatar
svolant committed
151
      if(file.exists(error_file)){error_message = read_lines(error_file)}
svolant's avatar
svolant committed
152
      
svolant's avatar
svolant committed
153
      res = fluidRow(
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
154
                HTML('<center><h1><strong>The workflow failed during progression</strong></h1> <br/> </center>'),
svolant's avatar
svolant committed
155
156
157
        
                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
158
159
                           h4(strong("Workflow error message")),
                           hr(style = "width: 70%;text-align:left;"),
svolant's avatar
svolant committed
160
161
162
163
164
165
                           HTML(paste(error_message,collapse = " <br/> ")),
                           br()
                       )
                )
          )
    }
svolant's avatar
svolant committed
166
167
168
169
170
  }
  
  return(list(box=res,PS=PS))
  
}