Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #11

Merged
merged 3 commits into from
Aug 25, 2022
Merged

Dev #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get update && apt-get install -y \
libssl-dev \
libxml2-dev

RUN install2.r shiny pkgload remotes devtools bio3d bs4Dash config data.table DT golem NGLVieweR RcppTOML readr rjson shinyalert shinyjs blogdown colourpicker shinyfullscreen shinycssloaders
RUN install2.r shiny pkgload remotes devtools bio3d bs4Dash config data.table DT golem NGLVieweR RcppTOML readr rjson shinyjs blogdown colourpicker shinyfullscreen shinycssloaders
#RUN R -e 'devtools::install_github("https://github.com/LBC-LNBio/KVshiny-docker")'

# copy the app directory into the image
Expand Down
5 changes: 3 additions & 2 deletions KVshiny/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ Imports:
rjson,
rlang,
shiny (>= 1.7.1),
shinyalert,
shinycssloaders,
shinyjs
shinyfullscreen,
shinyjs,
shinyWidgets
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
4 changes: 1 addition & 3 deletions KVshiny/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export(kv_help)
export(kv_params)
export(pdb_process)
export(process_fetch)
export(process_fetch_ligmode)
export(process_upload)
export(process_upload_ligmode)
export(report_nonstand)
export(run_app)
export(select_cav)
Expand All @@ -43,7 +41,7 @@ import(readr)
import(rjson)
import(rlang)
import(shiny)
import(shinyalert)
import(shinyWidgets)
import(shinycssloaders)
import(shinyfullscreen)
import(shinyjs)
Expand Down
15 changes: 8 additions & 7 deletions KVshiny/R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ app_server <- function( input, output, session ) {
get_nonstand_check <- report_nonstand(pdb_input = input$pdb_id)
removeModal()
if (is.na(get_nonstand_check)){
shinyWidgets::sendSweetAlert(title = "Oops!", text = "Please insert a valid PDB ID.", type = "error")
#shinyalert("Oops!", "Please insert a valid PDB ID.", type = "error")
shinyWidgets::sendSweetAlert(session = session,title = "Oops!", text = "Please insert a valid PDB ID.", type = "error")
} else{
print("PDB ID ok")
process_fetch(input = input, output = output)
}
#run process_fetch of mod_server_fetch module to create boxes and buttons of run mode
process_fetch(input = input, output = output)
#process_fetch(input = input, output = output)
})

#----------------------------------------------------
Expand All @@ -91,7 +91,8 @@ app_server <- function( input, output, session ) {
current_run_id <<- submit_job(input = input,
output = output,
pdb_name_click_load = pdb_name_click_load,
url_address = url_address)
url_address = url_address,
session = session)
removeModal()
# If result_pdb object is not null, i.e. the Check button was clicked previously,
# all the buttons generated by Check results (next block of code), will be hidden every time we click on submit button.
Expand Down Expand Up @@ -175,7 +176,7 @@ app_server <- function( input, output, session ) {
#Check results in the main Run KVFinder page
observeEvent(input$go_to_check_results, {
# Get and output the results
result_pdb <<- check_results(input = input, output = output, run_id = current_run_id, is_pg2 = FALSE, url_address = url_address)
result_pdb <<- check_results(input = input, output = output, run_id = current_run_id, is_pg2 = FALSE, url_address = url_address, session = session)
# If result_pdb object is not null, i.e. the Check button was clicked in another previous run,
# the function showElement below is executed to show the output status that was hidden by the submission button.
if(!is.null(result_pdb)){
Expand All @@ -190,7 +191,7 @@ app_server <- function( input, output, session ) {
}
# Create a 'observe' to monitor the results by checking and automatically updating the status each 5s when in queued or running
observe({
result_pdb <<- check_results(input = input, output = output, run_id = current_run_id, is_pg2 = FALSE, url_address = url_address)
result_pdb <<- check_results(input = input, output = output, run_id = current_run_id, is_pg2 = FALSE, url_address = url_address, session = session)
if(result_pdb %in% c("queued", "running")){
invalidateLater(5000) #means 5 seconds
} else{ #in case of status completed or error, the check_results will not be updated each 5s
Expand All @@ -212,7 +213,7 @@ app_server <- function( input, output, session ) {
#Check results in the secondary page ("get latest results" page)
observeEvent(input$check_loc_pg2, {
#output[["structure_p2"]] <<- NULL
result_pdb <<- check_results(input = input, output = output, run_id = input$insert_ID, is_pg2 = TRUE, url_address = url_address)
result_pdb <<- check_results(input = input, output = output, run_id = input$insert_ID, is_pg2 = TRUE, url_address = url_address, session = session)
# When check results button in page 2 is clicked, the structure visualization and all buttons related to NGL viewer will be hidden
# to allow an update if the check button is used multiple times
output[["structure_pg2"]] <- renderNGLVieweR({})
Expand Down
8 changes: 5 additions & 3 deletions KVshiny/R/mod_server_checkResults.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
#' @param output shiny output
#' @param run_id current run id
#' @param is_pg2 logical TRUE/FALSE. If TRUE, we calling to create result in page 2 (get latest results page).
#' @url_address url address to conexion
#' @param url_address url address to conexion
#' @param session
#'
#' @import shiny
#' @import RcppTOML
#' @import data.table
#' @import DT
#' @import blogdown
#' @import shinyWidgets
#' @export
#'

check_results <- function(input, output, run_id, is_pg2, url_address){
check_results <- function(input, output, run_id, is_pg2, url_address, session){
#check which page to output the results (main page or get latest results page - pg2)
#this block was created to allow the use of this function in the main or secondary page
if(is_pg2 == TRUE){ #get latest results page
Expand Down Expand Up @@ -74,7 +76,7 @@ check_results <- function(input, output, run_id, is_pg2, url_address){
result_toml <- parseTOML(input = content_get_output$output$report,fromFile = FALSE,escape = TRUE)$RESULTS
#check if the at least one cavity was found
if(length(result_toml$AREA) == 0){
shinyalert("Oops!", "No cavity found. Please check the input parameters and try again.", type = "warning")
shinyWidgets::sendSweetAlert(session = session,title = "Oops!", text = "No cavity found. Please check the input parameters and try again.", type = "warning")
} else{ #if cavities were found
#create result table
output[[results_table]] <- renderUI({
Expand Down
1 change: 0 additions & 1 deletion KVshiny/R/mod_server_fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#' @param output shiny output
#'
#' @import shiny
#' @import shinyalert
#'
#' @export
#'
Expand Down
15 changes: 8 additions & 7 deletions KVshiny/R/mod_server_pdbProcess.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#' @param output shiny output
#' @param get_nonstand vector of non-standard residues from the input PDB
#' @param mode select between "upload" or "fetch" modes
#' @param session
#'
#' @import shiny
#' @import shinyalert
#' @import shinyWidgets
#'
#' @export
#'
pdb_process <- function(input, output, get_nonstand, mode){
pdb_process <- function(input, output, get_nonstand, mode, session){
#if the PDB was uploaded
if(mode == "upload"){
#path of the pdb input
Expand All @@ -25,19 +26,19 @@ pdb_process <- function(input, output, get_nonstand, mode){
}
#create a processed PDB for each run mode: default, customized, ligand or box mode
if(input$run_mode == "mode_def"){
pdb_processed <- deal_sele_nonstand(pdb_input = pdb_input,nonstand_list = get_nonstand, include_list = include_list)
pdb_processed <- deal_sele_nonstand(pdb_input = pdb_input,nonstand_list = get_nonstand, include_list = include_list, session = session)
pdb_processed <- list(pdb_processed = pdb_processed)
} else if(input$run_mode == "mode_cust"){
pdb_processed <- deal_sele_nonstand(pdb_input = pdb_input,nonstand_list = get_nonstand, include_list = include_list)
pdb_processed <- deal_sele_nonstand(pdb_input = pdb_input,nonstand_list = get_nonstand, include_list = include_list, session = session)
pdb_processed <- list(pdb_processed = pdb_processed)
} else if(input$run_mode == "box_mode"){
#in the case of running the box mode, we have to check if the target residues are correctly in the PDB input
check_residues = check_residues_name(pdb_input = pdb_input, target_residues = input$box_residues)
if(check_residues == FALSE){
shinyalert("Oops!", "Please insert a valid list of residues for box mode run.", type = "error")
shinyWidgets::sendSweetAlert(session = session,title = "Oops!", text = "Please insert a valid list of residues for box mode run.", type = "error")
pdb_processed <- "wrong_target_res"
} else{
pdb_processed <- deal_sele_nonstand(pdb_input = pdb_input,nonstand_list = get_nonstand, include_list = include_list)
pdb_processed <- deal_sele_nonstand(pdb_input = pdb_input,nonstand_list = get_nonstand, include_list = include_list, session = session)
pdb_processed <- list(pdb_processed = pdb_processed)
}
} else { #enter in the ligand mode
Expand All @@ -46,7 +47,7 @@ pdb_process <- function(input, output, get_nonstand, mode){
#update nonstandard residues list to exclude the ligand
get_nonstand_noLig <- setdiff(get_nonstand,input$lig_name) #get all non-standand but the ligand
#by default remove all non standards residues and the ligand
pdb_processed <- deal_sele_nonstand(pdb_input = pdb_input,nonstand_list = c(get_nonstand,input$lig_name), include_list = include_list)
pdb_processed <- deal_sele_nonstand(pdb_input = pdb_input,nonstand_list = c(get_nonstand,input$lig_name), include_list = include_list, session = session)
pdb_processed <- list(pdb_processed = pdb_processed, pdb_lig_processed = pdb_ligand_processed)
}
return(pdb_processed)
Expand Down
22 changes: 12 additions & 10 deletions KVshiny/R/mod_server_submitJob.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
#' @param input shiny input
#' @param output shiny output
#' @param pdb_name_click_load variable of the number of clicks on load button
#' @url_address url address to conexion
#' @param url_address url address to conexion
#' @param session
#'
#' @import shiny
#' @import rjson
#' @import jsonlite
#' @import rlang
#' @import httr
#' @import shinyWidgets
#'
#' @export
#'

submit_job <- function(input, output, pdb_name_click_load, url_address){
submit_job <- function(input, output, pdb_name_click_load, url_address, session){
#-------------------------------------------------------------------
#Get KVFinder parameters from the user interface
probein_input <- input[[paste(input$run_mode, "Pin_input", sep = "_")]]
Expand All @@ -28,24 +30,24 @@ submit_job <- function(input, output, pdb_name_click_load, url_address){

#check if probe in is smaller than probe out
if(probein_input > probeout_input){
shinyalert("Oops!", "Probe In must be smaller than Probe Out.", type = "error")
shinyWidgets::sendSweetAlert(session = session,title = "Oops!", text = "Probe In must be smaller than Probe Out.", type = "error")
# check if user uploaded a PDB or fetched a PDB ID before to submit
} else if(is.null(input$input_pdb) & input$pdb_id == ""){
shinyalert("Oops!", "Please load from PDB or upload a PDB file before to submit.", type = "error")
shinyWidgets::sendSweetAlert(session = session,title = "Oops!", text = "Please load from PDB or upload a PDB file before to submit.", type = "error")
#Check if the user that is using the fetch mode clicked on the Load button before to submit
} else if(pdb_name_click_load != "init" & pdb_name_click_load != input$pdb_id){ #
shinyalert("Oops!", "Please after input PDB ID in Choose input section, be sure you loaded the PDB by clicking on the Load button.", type = "error")
shinyWidgets::sendSweetAlert(session = session,title = "Oops!", text = "Please after input PDB ID in Choose input section, be sure you loaded the PDB by clicking on the Load button.", type = "error")
# Just another check if user uploaded a PDB or fetched a PDB ID before to submit
} else if(length(input$pdb_id) > 0 & input$send_pdb_id == 0){
shinyalert("Oops!", "Please load from PDB or upload a PDB file before to submit.", type = "error")
shinyWidgets::sendSweetAlert(session = session,title = "Oops!", text = "Please load from PDB or upload a PDB file before to submit.", type = "error")
} else {
#if pass through the above checks...
#get pdb_processed from upload mode
if(input$input_type == 'pdb_from_file'){
pdb_processed <- pdb_process(input = input, output = output, get_nonstand = get_nonstand, mode = "upload")
pdb_processed <- pdb_process(input = input, output = output, get_nonstand = get_nonstand, mode = "upload", session = session)
#get pdb_processed from fetch mode
} else{
pdb_processed <- pdb_process(input = input, output = output, get_nonstand = get_nonstand, mode = "fetch")
pdb_processed <- pdb_process(input = input, output = output, get_nonstand = get_nonstand, mode = "fetch", session = session)
}
#check if the list of residues in "target residues" field is appropriated. The function pdb_process (in mod_server_pdbProcess.R) returns "wrong_target_res" if the input is not in the required format
if(pdb_processed != "wrong_target_res"){
Expand All @@ -57,7 +59,7 @@ submit_job <- function(input, output, pdb_name_click_load, url_address){
}
#check if user inserted a valid PDB before do submit
if(length(pdb_path) == 0){
shinyalert("Oops!", "Please insert a valid PDB before to submit.", type = "error")
shinyWidgets::sendSweetAlert(session = session,title = "Oops!", text ="Please insert a valid PDB before to submit.", type = "error")
} else {
#Create a KVFinder input file based on the specific target mode to be submitted to the server using submit_prepare function
#Whole protein (default parameters)
Expand Down Expand Up @@ -93,7 +95,7 @@ submit_job <- function(input, output, pdb_name_click_load, url_address){
#return the job id
return(get_run_id)
} else{ # if the submission status is other than 200
shinyalert("Oops!", "An error occurred when submitting your job. Perhaps the input file is larger than what our server allows or the input parameters are outside the allowed limits. Please read our Help page and if the problem persist please contact us", type = "error")
shinyWidgets::sendSweetAlert(session = session,title = "Oops!", text ="An error occurred when submitting your job. Perhaps the input file is larger than what our server allows or the input parameters are outside the allowed limits. Please read our Help page and if the problem persist please contact us.", type = "error")
}
}
}
Expand Down
1 change: 0 additions & 1 deletion KVshiny/R/mod_server_upload.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#' @param output shiny output
#'
#' @import shiny
#' @import shinyalert
#'
#' @export
#'
Expand Down
60 changes: 33 additions & 27 deletions KVshiny/R/utils_pdbProcess_.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#' @export

report_nonstand <- function(pdb_input) {

pdb <- tryCatch({read.pdb(pdb_input)},
error = function(err) {
return(NA)
})

if(!is.na(pdb)) {
#get protein
indx_p <- atom.select(pdb, string = "protein", inverse= TRUE)
Expand All @@ -43,40 +43,46 @@ report_nonstand <- function(pdb_input) {
#' @param pdb_input Pdb path
#' @param nonstand_list List of non-standard residues
#' @param include_list List of non-standard residues that must be maintained in the PDB
#' @param session
#'
#' @import bio3d
#' @import shinyWidgets
#'
#' @examples
#'
#' @export
#'

deal_sele_nonstand <- function(pdb_input, nonstand_list, include_list){
pdb <- read.pdb(pdb_input)

if(is.null(include_list)){
#get nonstandard selected
indx_s <- atom.select(pdb, resid = nonstand_list, inverse = TRUE)
#subset pdb
clean_pdb <- trim.pdb(pdb, indx_s)
#create random number to name file
rand <- sample(x = 1:100000,size = 1)
outfile = file.path(tempdir(), paste(rand,".pdb",sep = ""))
#write tmp
write.pdb(pdb = clean_pdb, file = outfile)
return(outfile)
} else {
indx_s <- atom.select(pdb, resid = nonstand_list, inverse = TRUE)
indx_i <- atom.select(pdb, resid = include_list)
indx <- combine.select(indx_s, indx_i, operator= "OR")
clean_pdb <- trim.pdb(pdb, indx)
#create random number to name file
rand <- sample(x = 1:100000,size = 1)
outfile = file.path(tempdir(), paste(rand,".pdb",sep = ""))
#write tmp
write.pdb(pdb = clean_pdb, file = outfile)
return(outfile)
deal_sele_nonstand <- function(pdb_input, nonstand_list, include_list, session = session){
tryCatch({ #test if the pdb_input is an appropriated PDB ID and if the read,pdb function can download successfully this pdb
pdb <- read.pdb(pdb_input)
if(is.null(include_list)){
#get nonstandard selected
indx_s <- atom.select(pdb, resid = nonstand_list, inverse = TRUE)
#subset pdb
clean_pdb <- trim.pdb(pdb, indx_s)
#create random number to name file
rand <- sample(x = 1:100000,size = 1)
outfile = file.path(tempdir(), paste(rand,".pdb",sep = ""))
#write tmp
write.pdb(pdb = clean_pdb, file = outfile)
return(outfile)
} else {
indx_s <- atom.select(pdb, resid = nonstand_list, inverse = TRUE)
indx_i <- atom.select(pdb, resid = include_list)
indx <- combine.select(indx_s, indx_i, operator= "OR")
clean_pdb <- trim.pdb(pdb, indx)
#create random number to name file
rand <- sample(x = 1:100000,size = 1)
outfile = file.path(tempdir(), paste(rand,".pdb",sep = ""))
#write tmp
write.pdb(pdb = clean_pdb, file = outfile)
return(outfile)
}
}, error = function(e){
shinyWidgets::sendSweetAlert(session = session,title = "Oops!", text = "Please insert a valid PDB ID.", type = "error")
}
)
}


Expand Down
6 changes: 5 additions & 1 deletion KVshiny/man/check_results.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion KVshiny/man/deal_sele_nonstand.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading