diff --git a/Dockerfile b/Dockerfile index 4437be5..fa4c57e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \ libxml2-dev # Install R depedencies -RUN install2.r shiny pkgload remotes devtools bio3d bs4Dash config data.table DT golem NGLVieweR RcppTOML readr rjson shinyjs blogdown colourpicker shinyfullscreen shinycssloaders shinyWidgets +RUN install2.r shiny pkgload remotes devtools bio3d bs4Dash config data.table DT golem NGLVieweR RcppTOML readr rjson shinyjs blogdown colourpicker shinyfullscreen shinycssloaders shinyWidgets ggplot2 ggpubr # Copy the app directory into the image COPY ./kvfinder-web-portal/ /srv/shiny-server/kvfinder-web-portal/ diff --git a/kvfinder-web-portal/DESCRIPTION b/kvfinder-web-portal/DESCRIPTION index 12177ae..96ddaef 100644 --- a/kvfinder-web-portal/DESCRIPTION +++ b/kvfinder-web-portal/DESCRIPTION @@ -47,7 +47,9 @@ Imports: shinycssloaders, shinyfullscreen, shinyjs, - shinyWidgets + shinyWidgets, + ggplot2, + ggpubr Encoding: UTF-8 LazyData: true RoxygenNote: 7.1.2 diff --git a/kvfinder-web-portal/NAMESPACE b/kvfinder-web-portal/NAMESPACE index dfa1b29..79e89b9 100644 --- a/kvfinder-web-portal/NAMESPACE +++ b/kvfinder-web-portal/NAMESPACE @@ -38,6 +38,7 @@ import(blogdown) import(bs4Dash) import(colourpicker) import(data.table) +import(ggplot2) import(golem) import(httr) import(jsonlite) diff --git a/kvfinder-web-portal/R/app_server.R b/kvfinder-web-portal/R/app_server.R index 3b4f7d8..6b61436 100644 --- a/kvfinder-web-portal/R/app_server.R +++ b/kvfinder-web-portal/R/app_server.R @@ -4,6 +4,8 @@ #' DO NOT REMOVE. #' @import shiny #' @import shinyjs +#' @import ggplot2 +#' #' #' @noRd #' @@ -174,6 +176,10 @@ app_server <- function(input, output, session) { id = "download2", time = 0 ) + hideElement( + id = "table_footer", + time = 0 + ) hideElement( id = "view_str", time = 0 @@ -247,6 +253,14 @@ app_server <- function(input, output, session) { id = "cavity_hyd", time = 0 ) + hideElement( + id = "scale_plot_deep", + time = 0 + ) + hideElement( + id = "scale_plot", + time = 0 + ) } }) #---------------------------------------------------- @@ -288,6 +302,10 @@ app_server <- function(input, output, session) { id = "download2", time = 0 ) + showElement( + id = "table_footer", + time = 0 + ) } }) # disable check button button to force the users to resubmit job and to avoid inconsistencies in the interface @@ -361,6 +379,14 @@ app_server <- function(input, output, session) { id = "cavity_hyd_pg2", time = 0 ) + hideElement( + id = "scale_plot_deep", + time = 0 + ) + hideElement( + id = "scale_plot", + time = 0 + ) }) #---------------------------------------------------- @@ -439,6 +465,14 @@ app_server <- function(input, output, session) { id = "cavity_hyd", time = 0 ) + showElement( + id = "scale_plot_deep", + time = 0 + ) + showElement( + id = "scale_plot", + time = 0 + ) # disable view button to avoid user to click on it multiple times disable("view_str") }, @@ -486,12 +520,10 @@ app_server <- function(input, output, session) { # Select cavity to be visualized from clicking on cavity selector button observeEvent(input$select_cavity, { - print('exeuting select') select_cav(input = input, output = output, result_pdb_list = result_pdb, is_pg2 = FALSE) }) observeEvent(input$interface_res, { - print('exeuting select') interface_cav(input = input, output = output, result_pdb_list = result_pdb, is_pg2 = FALSE) }) @@ -528,17 +560,50 @@ app_server <- function(input, output, session) { }) observeEvent(input$input_cavity_deep, { + if(input$input_cavity_deep == TRUE){ + updateCheckboxInput(session, "input_cavity_hyd", value = FALSE) + } + color_cavity_deepth(input = input, output = output, is_pg2 = FALSE, cav_rep_list=cav_rep_list,result_pdb_list=result_pdb ) - }) + + output$scale_plot_deep <- renderPlot({ + depth_scale = c(0,result_pdb$list_depth, max(unlist(result_pdb$result_toml$MAX_DEPTH))) + df <- data.frame(x = seq(1,length(depth_scale)), y = depth_scale) + p <- ggplot2::ggplot(data = df, aes(x = x, y = y, colour = y)) + + geom_point() + + #scale_colour_gradient2(name = "Deepth (A)", low = "yellow", mid = "white", high = "blue", midpoint = 0.59,breaks = seq(-1,2.5,0.5))+ + scale_color_gradientn(name = "Deepth (A)", colours = rev(rainbow(5)))+ + theme(plot.title = element_text(hjust = 0.5), + legend.position = "bottom", + legend.key.width= unit(0.2, 'npc'), + #legend.spacing = unit(0.25,"cm"), + legend.title = element_text(hjust = 0.5), + legend.justification = "center", + panel.background = element_rect(fill='transparent'), + plot.background = element_rect(fill='transparent'), + legend.background = element_rect(fill='transparent'), + legend.box.background = element_rect(fill='transparent'))+ + guides(colour = guide_colourbar(title.position="top", title.hjust = 0.5), + size = guide_legend(title.position="top", title.hjust = 0.5)) + + # ggpubr does this for you + leg <- ggpubr::get_legend(p) + ggpubr::as_ggplot(leg) + + }, bg="transparent") #, height =50, width = '100%' +}) observeEvent(input$input_cavity_hyd, { + if(input$input_cavity_hyd == TRUE){ + updateCheckboxInput(session, "input_cavity_deep", value = FALSE) + } color_cavity_hyd(input = input, output = output, is_pg2 = FALSE, cav_rep_list=cav_rep_list,result_pdb_list=result_pdb ) output$scale_plot <- renderPlot({ EisenbergWeiss_scale = c(-0.64, 2.6,0.8,0.92,-0.3,0.87,0.76, -0.49,0.41,-1.42,-1.09,1.54,-0.66,-1.22, -0.12,0.18,0.05, -0.83, -0.27, -1.11) df <- data.frame(x = seq(1,length(EisenbergWeiss_scale)), y = EisenbergWeiss_scale) - p <- ggplot(data = df, aes(x = x, y = y, colour = y)) + + p <- ggplot2::ggplot(data = df, aes(x = x, y = y, colour = y)) + geom_point() + scale_colour_gradient2(name = "Hydropathy", low = "yellow", mid = "white", high = "blue", midpoint = 0.59,breaks = seq(-1,2.5,0.5))+ theme(plot.title = element_text(hjust = 0.5), @@ -546,17 +611,23 @@ app_server <- function(input, output, session) { legend.key.width= unit(0.2, 'npc'), #legend.spacing = unit(0.25,"cm"), legend.title = element_text(hjust = 0.5), - legend.justification = "center") + + legend.justification = "center", + panel.background = element_rect(fill='transparent'), + plot.background = element_rect(fill='transparent'), + legend.background = element_rect(fill='transparent'), + legend.box.background = element_rect(fill='transparent'))+ guides(colour = guide_colourbar(title.position="top", title.hjust = 0.5), size = guide_legend(title.position="top", title.hjust = 0.5)) # ggpubr does this for you - leg <- get_legend(p) - as_ggplot(leg) + leg <- ggpubr::get_legend(p) + ggpubr::as_ggplot(leg) - }) #, height =50, width = '100%' + }, bg="transparent") #, height =50, width = '100%' }) + + ##### View in Get latest results page (pg2) # Click view in the secondary page to initialize the result visualization with the NGL engine @@ -633,6 +704,14 @@ app_server <- function(input, output, session) { id = "cavity_hyd_pg2", time = 0 ) + showElement( + id = "scale_plot_deep_pg2", + time = 0 + ) + showElement( + id = "scale_plot_pg2", + time = 0 + ) disable("view_str_pg2") }) @@ -711,12 +790,81 @@ app_server <- function(input, output, session) { take_snapshot(input = input, output = output, is_pg2 = TRUE) }) + observeEvent(input$interface_res_pg2, { + interface_cav(input = input, output = output, result_pdb_list = result_pdb, is_pg2 = TRUE) + }) + observeEvent(input$input_cavity_deep_pg2, { + if(input$input_cavity_deep_pg2 == TRUE){ + updateCheckboxInput(session, "input_cavity_hyd_pg2", value = FALSE) + } + color_cavity_deepth(input = input, output = output, is_pg2 = TRUE, cav_rep_list=cav_rep_list,result_pdb_list=result_pdb ) + + output$scale_plot_deep_pg2 <- renderPlot({ + depth_scale = c(0,result_pdb$list_depth, max(unlist(result_pdb$result_toml$MAX_DEPTH))) + df <- data.frame(x = seq(1,length(depth_scale)), y = depth_scale) + p <- ggplot2::ggplot(data = df, aes(x = x, y = y, colour = y)) + + geom_point() + + #scale_colour_gradient2(name = "Deepth (A)", low = "yellow", mid = "white", high = "blue", midpoint = 0.59,breaks = seq(-1,2.5,0.5))+ + scale_color_gradientn(name = "Deepth (A)", colours = rev(rainbow(5)))+ + theme(plot.title = element_text(hjust = 0.5), + legend.position = "bottom", + legend.key.width= unit(0.2, 'npc'), + #legend.spacing = unit(0.25,"cm"), + legend.title = element_text(hjust = 0.5), + legend.justification = "center", + panel.background = element_rect(fill='transparent'), + plot.background = element_rect(fill='transparent'), + legend.background = element_rect(fill='transparent'), + legend.box.background = element_rect(fill='transparent'))+ + guides(colour = guide_colourbar(title.position="top", title.hjust = 0.5), + size = guide_legend(title.position="top", title.hjust = 0.5)) + + # ggpubr does this for you + leg <- ggpubr::get_legend(p) + ggpubr::as_ggplot(leg) + + }, bg="transparent") #, height =50, width = '100%' + + + }) observeEvent(input$input_cavity_hyd_pg2, { + if(input$input_cavity_hyd_pg2 == TRUE){ + updateCheckboxInput(session, "input_cavity_deep_pg2", value = FALSE) + } + color_cavity_hyd(input = input, output = output, is_pg2 = TRUE, cav_rep_list=cav_rep_list,result_pdb_list=result_pdb ) + + output$scale_plot_pg2 <- renderPlot({ + EisenbergWeiss_scale = c(-0.64, 2.6,0.8,0.92,-0.3,0.87,0.76, + -0.49,0.41,-1.42,-1.09,1.54,-0.66,-1.22, + -0.12,0.18,0.05, -0.83, -0.27, -1.11) + df <- data.frame(x = seq(1,length(EisenbergWeiss_scale)), y = EisenbergWeiss_scale) + p <- ggplot2::ggplot(data = df, aes(x = x, y = y, colour = y)) + + geom_point() + + scale_colour_gradient2(name = "Hydropathy", low = "yellow", mid = "white", high = "blue", midpoint = 0.59,breaks = seq(-1,2.5,0.5))+ + theme(plot.title = element_text(hjust = 0.5), + legend.position = "bottom", + legend.key.width= unit(0.2, 'npc'), + #legend.spacing = unit(0.25,"cm"), + legend.title = element_text(hjust = 0.5), + legend.justification = "center", + panel.background = element_rect(fill='transparent'), + plot.background = element_rect(fill='transparent'), + legend.background = element_rect(fill='transparent'), + legend.box.background = element_rect(fill='transparent'))+ + guides(colour = guide_colourbar(title.position="top", title.hjust = 0.5), + size = guide_legend(title.position="top", title.hjust = 0.5)) + + # ggpubr does this for you + leg <- ggpubr::get_legend(p) + ggpubr::as_ggplot(leg) + + }, bg="transparent") #, height =50, width = '100%' + }) #---------------------------------------------------- diff --git a/kvfinder-web-portal/R/app_ui.R b/kvfinder-web-portal/R/app_ui.R index 67c011b..c7b25f8 100644 --- a/kvfinder-web-portal/R/app_ui.R +++ b/kvfinder-web-portal/R/app_ui.R @@ -162,6 +162,13 @@ app_ui <- function(request) { plotOutput("scale_plot", height = '50', width = '50%')) ) ), + conditionalPanel( + condition="input.input_cavity_deep==1", + fluidRow( + column(12, align='center', + plotOutput("scale_plot_deep", height = '50', width = '50%')) + ) + ), fluidRow( column(2, uiOutput("selection_pdb")), column(2, uiOutput("cavity_rep")), @@ -247,6 +254,20 @@ app_ui <- function(request) { fluidRow( NGLVieweROutput("structure_pg2", width = "100%", height = "600px") ), + conditionalPanel( + condition="input.input_cavity_hyd_pg2==1", + fluidRow( + column(12, align='center', + plotOutput("scale_plot_pg2", height = '50', width = '50%')) + ) + ), + conditionalPanel( + condition="input.input_cavity_deep_pg2==1", + fluidRow( + column(12, align='center', + plotOutput("scale_plot_deep_pg2", height = '50', width = '50%')) + ) + ), fluidRow( column(2, uiOutput("selection_pdb_pg2")), column(2, uiOutput("cavity_rep_pg2")), diff --git a/kvfinder-web-portal/R/mod_server_changeCAVcolor.R b/kvfinder-web-portal/R/mod_server_changeCAVcolor.R index ceb30f3..9995e15 100644 --- a/kvfinder-web-portal/R/mod_server_changeCAVcolor.R +++ b/kvfinder-web-portal/R/mod_server_changeCAVcolor.R @@ -19,17 +19,14 @@ change_cav_color <- function(input, output, is_pg2, cav_rep_list) { input_cavity_color <- "input_cavity_color" structure <- "structure" } - print('inside cav color') - print(cav_rep_list) - # if(length(cav_rep_list) > 1){ - # NGLVieweR_proxy(structure) %>% - # updateColor("point", input[[input_cavity_color]]) - # } else{ - # NGLVieweR_proxy(structure) %>% - # updateColor("sel3", input[[input_cavity_color]]) - # } - # print(cav_rep_list) - # print(tail(cav_rep_list,n=1)) - NGLVieweR_proxy(structure) %>% + + if(!is.null(cav_rep_list)){ #this is to make sure that this will work on the second time loaded page + NGLVieweR_proxy(structure) %>% updateColor(tail(cav_rep_list,n=1), input[[input_cavity_color]]) + } else { + NGLVieweR_proxy(structure) %>% + updateColor("point", input[[input_cavity_color]]) + } + + } diff --git a/kvfinder-web-portal/R/mod_server_checkResults.R b/kvfinder-web-portal/R/mod_server_checkResults.R index ca60680..d51d968 100644 --- a/kvfinder-web-portal/R/mod_server_checkResults.R +++ b/kvfinder-web-portal/R/mod_server_checkResults.R @@ -84,21 +84,23 @@ check_results <- function(input, output, run_id, is_pg2, url_address, session) { output[[results_table]] <- renderUI({ DT::dataTableOutput(table_out) }) + #print(result_toml$AVG_HYDROPATHY) output[[table_out]] <- DT::renderDataTable( data.table( `ID` = names(result_toml$AREA), `Area (A²)` = unlist(result_toml$AREA), `Vol. (A³)` = unlist(result_toml$VOLUME), - `Dep. (A)` = unlist(result_toml$AVG_DEPTH), - `Hyd.` = unlist(result_toml$AVG_HYDROPATHY) + `Avg Dep. (A)` = unlist(result_toml$AVG_DEPTH), + `Max Dep. (A)` = unlist(result_toml$MAX_DEPTH), + `Avg Hyd.` = unlist(result_toml$AVG_HYDROPATHY[names(result_toml$AVG_HYDROPATHY) != 'EisenbergWeiss']) ), filter = c("none"), style = "auto", options = list(dom = "lBfrtip", buttons = c("excel", "pdf"), - autoWidth = TRUE, + #autoWidth = TRUE, scrollX = TRUE, - columnDefs = list(list(targets=c(5), visible=TRUE, width='60')) + columnDefs = list(list(targets=c(1), visible=TRUE, width='10%')) ), extensions = "Buttons" ) @@ -138,15 +140,22 @@ check_results <- function(input, output, run_id, is_pg2, url_address, session) { output$table_footer <- renderText({ paste( - p("ID: Cavity ID, Area: Cavity area, Vol: Cavity volume, Dep: Cavity average depth, Hyd: Cavity average hydropathy.") + p(strong("ID: "), "Cavity ID, ", strong("Area: "), "Cavity area, ", strong("Vol: "), "Cavity volume, ", strong("Avg Dep: "), "Cavity average depth ,", strong("Max Dep: "), "Cavity maximum depth, ", strong("Avg Hyd: "), "Cavity average hydropathy.") ) }) + + #get values of depth for each atom + str_cav = strsplit(result_pdb_cav, "\n")[[1]] + get_atoms = str_cav[sapply(str_cav, function(x) startsWith(x, 'ATOM'))] + #print(get_atoms[1:10]) + list_depth = as.numeric(sapply(get_atoms, function(x) strsplit(x, '\\s+')[[1]][10])) # create list to store results result_list <- list( retrieve_input_pdb = retrieve_input_pdb, result_pdb_cav = result_pdb_cav, result_cav_names = cav_out_names, - result_toml = result_toml + result_toml = result_toml, + list_depth = list_depth ) return(result_list) } diff --git a/kvfinder-web-portal/R/mod_server_createWORKscene.R b/kvfinder-web-portal/R/mod_server_createWORKscene.R index 35ccf51..29c1ff9 100644 --- a/kvfinder-web-portal/R/mod_server_createWORKscene.R +++ b/kvfinder-web-portal/R/mod_server_createWORKscene.R @@ -63,7 +63,6 @@ create_work_scene <- function(input, output, protein_rep_list, protein_col_list, } if(prot_or_cav == 'cav' & length(cav_rep_list) >1) { #cav mode - print("inside cavity mode") NGLVieweR_proxy(structure) %>% removeSelection(name = tail(cav_rep_list, n = 2)[1]) # After the initial structure is invisible, we can add a new representation to the current scene diff --git a/kvfinder-web-portal/R/mod_server_selectCAV.R b/kvfinder-web-portal/R/mod_server_selectCAV.R index ab6251b..5808547 100644 --- a/kvfinder-web-portal/R/mod_server_selectCAV.R +++ b/kvfinder-web-portal/R/mod_server_selectCAV.R @@ -27,8 +27,22 @@ select_cav <- function(input, output, result_pdb_list, is_pg2) { NGLVieweR_proxy(structure) %>% updateSelection("point", sele = paste(result_pdb_list$result_cav_names, collapse = " or ")) } else { # show one cavity to show and zoom it - NGLVieweR_proxy(structure) %>% - updateSelection("point", sele = input[[select_cavity]]) %>% - updateZoomMove(input[[select_cavity]], input[[select_cavity]], 2000, -20) + print(input$input_cavity_deep) + if(isTRUE(input$input_cavity_deep) | isTRUE(input$input_cavity_deep_pg2)){ + NGLVieweR_proxy(structure) %>% + updateSelection("point", sele = "not all") %>% + updateSelection("deepth", sele = input[[select_cavity]]) %>% + updateZoomMove(input[[select_cavity]], input[[select_cavity]], 2000, -20) + } else if(isTRUE(input$input_cavity_hyd) | isTRUE(input$input_cavity_hyd_pg2)){ + NGLVieweR_proxy(structure) %>% + updateSelection("point", sele = "not all") %>% + updateSelection("hyd", sele = input[[select_cavity]]) %>% + updateZoomMove(input[[select_cavity]], input[[select_cavity]], 2000, -20) + } else{ + NGLVieweR_proxy(structure) %>% + updateSelection("point", sele = input[[select_cavity]]) %>% + updateZoomMove(input[[select_cavity]], input[[select_cavity]], 2000, -20) + } + } }