Skip to content

Commit

Permalink
Merge branch 'bfabric10_c' of github.com:fgcz/bfabricShiny into bfabr…
Browse files Browse the repository at this point in the history
…ic10_c
  • Loading branch information
cpanse committed Apr 1, 2021
2 parents 8fb4c26 + 005151e commit d7991fa
Showing 1 changed file with 71 additions and 61 deletions.
132 changes: 71 additions & 61 deletions inst/shiny/bfabricProgenesisQI/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ shinyServer(function(input, output, session) {
inputresouceid = NULL,
wuid = NULL,
notpressed = TRUE)

bf <- callModule(bfabric, "bfabric8", applicationid = c(226), resoucepattern = 'zip$')

# cpanse@fgcz-r-021:~ > unzip -p /srv/www/htdocs/Data2San/p1000/Metabolomics/Analysis/ProgenesisQI/cpanse_20171109_test/p1896_o3296_BPs_HILIC_pH9_SOP_G2_filter08.zip *measurements*csv|wc -l
#2800
#cpanse@fgcz-r-021:~ > unzip -vl /srv/www/htdocs/Data2San/p1000/Metabolomics/Analysis/ProgenesisQI/cpanse_20171109_test/p1896_o3296_BPs_HILIC_pH9_SOP_G2_filter08.zip
#cpanse@fgcz-r-021:~ > unzip -vl /srv/www/htdocs/Data2San/p1000/Metabolomics/Analysis/ProgenesisQI/cpanse_20171109_test/p1896_o3296_BPs_HILIC_pH9_SOP_G2_filter08.zip
#Archive: /srv/www/htdocs/Data2San/p1000/Metabolomics/Analysis/ProgenesisQI/cpanse_20171109_test/p1896_o3296_BPs_HILIC_pH9_SOP_G2_filter08.zip
#Length Method Size Cmpr Date Time CRC-32 Name
#-------- ------ ------- ---- ---------- ----- -------- ----
Expand All @@ -25,59 +25,59 @@ shinyServer(function(input, output, session) {
# 3518838 755689 79% 2 files
#cpanse@fgcz-r-021:~ > unzip -p /srv/www/htdocs/Data2San/p1000/Metabolomics/Analysis/ProgenesisQI/cpanse_20171109_test/p1896_o3296_BPs_HILIC_pH9_SOP_G2_filter08.zip *identifications*csv|wc -l
#8968

zip_filename <- eventReactive(input$load, {
resources <- bf$resources()
paste("/srv/www/htdocs/", input$relativepath, sep='')
})

get_identifications <- reactive({
progress <- shiny::Progress$new(session = session, min = 0, max = 1)
progress$set(message = "fetching identifications ...")
on.exit(progress$close())

cmd <- paste("unzip -p", zip_filename(), "*identifications*csv")

if (!file.exists(zip_filename())){
cmd <- paste("ssh fgcz-r-021 '", cmd, "'", sep='')
}
message(cmd)
p389Devel::preprocessQIIdent(p389Devel::readIdentFile(pipe(cmd), sep=';'))

preprocessQIIdent(readIdentFile(pipe(cmd), sep=';'))
})

get_measurements <- reactive({
progress <- shiny::Progress$new(session = session, min = 0, max = 1)
progress$set(message = "fetching measurements ...")
on.exit(progress$close())

cmd <- paste("unzip -p", zip_filename(), "*measurements*csv")

if (!file.exists(zip_filename())){
cmd <- paste("ssh fgcz-r-021 '", cmd, "'", sep='')
}

message(cmd)

# rv <- read.csv(pipe(cmd), sep=input$sep, stringsAsFactors = FALSE, header = TRUE, skip = 2)
p389Devel::ProgenesisRead(pipe(cmd), sep=';')
})

output$measurements <- DT::renderDataTable({
get_measurements()
})

output$identifications<- DT::renderDataTable({
get_identifications()
})



output$distPlot <- renderPlot({
plot(0,0, main='no data yet')
})


output$generateReportButton <- renderUI({
if(nrow(get_identifications()) > 1 && values$notpressed){
list(actionButton("generateReport", "Generate PDF Report" ))
Expand All @@ -87,63 +87,63 @@ shinyServer(function(input, output, session) {
NULL
}
})

generateReport <- observeEvent(input$generateReport, {
#here will processing happen!
if(!is.null(get_identifications())){

if (!values$notpressed){return}

values$notpressed <- FALSE
message("generating report ... ")

progress <- shiny::Progress$new(session = session, min = 0, max = 1)
progress$set(message = "generating report")
on.exit(progress$close())

progress$set(message = "render document", detail= "using rmarkdown", value = 0.1)

QI_Data <- list(
Identification = get_identifications(),
Intensities = get_measurements(),
resourceid = bf$resources()$resourceid[bf$resources()$relativepath == input$relativepath]
)

# TODO(cp): TESTING
QI_Data <- prepareQIDATA(QI_Data)
QI_Data_prepared <- p389Devel::prepareQIDATA(QI_Data)

# for debugging
(values$pdf <- file.path(tempdir(), "made4-BGA1.pdf"))

message("XXXXXXXXXXXXXXXXXXXXXXX",tempdir())

# for download
# QI_Data$Int_ID
###
progress$set(message = "write quantitative data to bfabric ... ", detail= "using rmarkdown", value = 0.2)

(fn <- tempfile(pattern = "file-", tmpdir = tempdir(), fileext = ".csv"))
write.table(QI_Data$Int_ID,
write.table(QI_Data_prepared$Int_ID,
file = fn,
sep='\t',
row.names = FALSE,
append = TRUE,
quote = FALSE, eol='\r\n')

file_txt_content <- base64encode(readBin(fn, "raw", file.info(fn)[1, "size"]), 'csv')

description <- ""
if(length(unique(QI_Data$Annotation$Condition)) <= 1){
if(length(unique(QI_Data_prepared$Annotation$Condition)) <= 1){
description <- "No valid group information to conduct a report."
progress$set(message = description, detail= "using rmarkdown", value = 0.1)
}

###
progress$set(message = "register workunit", detail= "in bfabric", value = 0.95)
wuid <- bfabric_upload_file(login = bf$login(),
webservicepassword = bf$webservicepassword(),
projectid = bf$projectid(),
file_content = file_txt_content,
file_content = file_txt_content,
inputresource = values$inputresouceid,
description = description,
workunitname = input$experimentID,
Expand All @@ -152,51 +152,61 @@ shinyServer(function(input, output, session) {
status = 'available',
applicationid = 227)
values$wuid <- wuid
if(length(unique(QI_Data$Annotation$Condition)) > 1){

if(length(unique(QI_Data_prepared$Annotation$Condition)) > 1){
progress$set(message = "render PDF document", detail= "using rmarkdown", value = 0.5)
markdownFile <- RMD_p389_BGA(workdir = tempdir())

message("XXXXXXXXXXXXXXX",markdownFile)
message(file.path(tempdir(),markdownFile))
message(dir(tempdir()))

rmarkdown::render(file.path(tempdir(),markdownFile),
output_file = values$pdf,
output_format = "pdf_document", params=list(QI_Data = QI_Data), envir = new.env())


message("XXXXXXXXXXXXXXX :",markdownFile)
message("File path ", file.path(tempdir(),markdownFile))
message("Whats in tempdir ",dir(tempdir()))
message("dim QI_Data_prepared$Int_ID", dim(QI_Data_prepared$Int_ID))
message("", QI_Data_prepared$Annotation$Condition)

bga_res_id <- p389Devel::runBGA(QI_Data_prepared$Int_ID, QI_Data_prepared$Annotation )
bga_res_all <- p389Devel::runBGA(QI_Data_prepared$Int_ID_All, QI_Data_prepared$Annotation )


rmarkdown::render(file.path(tempdir(),markdownFile),
output_file = values$pdf,
output_format = "pdf_document",
params=list(bga_res_id = bga_res_id,
bga_res_all = bga_res_all,
resourceid = QI_Data$resourceid),
envir = new.env())

message(values$pdf)
file_pdf_content <- base64encode(readBin(values$pdf, "raw",
file.info(values$pdf)[1, "size"]),
"pdf")
file_pdf_content <- base64encode(readBin(values$pdf, "raw",
file.info(values$pdf)[1, "size"]),
"pdf")

progress$set(message = "saving PDF to bfabric ...", detail= "using rmarkdown", value = 0.8)
bfabricShiny:::saveResource(login = bf$login(),
webservicepassword = bf$webservicepassword(),
workunitid = wuid,
content = file_pdf_content,
name = paste("made4-report_", bf$workunitid(), ".pdf", sep='')
)

}else{
message("no valid group information.")
}

progress$set(message = paste("set workunit", wuid, "available."), detail= "status to 'available'", value = 0.95)
rv <- bfabric_save(bf$login(), bf$webservicepassword(), endpoint = 'workunit',

rv <- bfabric_save(bf$login(), bf$webservicepassword(), endpoint = 'workunit',
query = list(status = 'available', id=wuid));

message(paste("generate report DONE. the report was written to workunit ID", wuid, "in bfabric."))
}
})


output$wuid <- renderUI({
if (!is.null(values$wuid)){
actionButton("download",
paste("bfabric download workunit", values$wuid),
onclick = paste("window.open('https://fgcz-bfabric.uzh.ch/bfabric/userlab/show-workunit.html?id=",
onclick = paste("window.open('https://fgcz-bfabric.uzh.ch/bfabric/userlab/show-workunit.html?id=",
values$wuid, "', '_blank')", sep=''))
}
})
Expand Down

0 comments on commit d7991fa

Please sign in to comment.