added shiny app and turned stability bp to function

This commit is contained in:
Tanushree Tunstall 2021-06-09 17:05:02 +01:00
parent 3f58a5c64c
commit 225360fb93
4 changed files with 386 additions and 4 deletions

View file

@ -0,0 +1,150 @@
## This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
##
###################################
# load libraries and function
#source("Header_TT.R")
library(shiny)
library(ggplot2)
library(data.table)
library(dplyr)
#require("getopt", quietly = TRUE) # cmd parse arguments
# load functions
source("../plotting_globals.R")
source("../plotting_data.R")
source("my_stability_bp.R")
###################################
# command line args :
# INSERT HERE
# hardcoded vars
infile = "/home/tanu/git/Data/streptomycin/output/gid_comb_stab_struc_params.csv"
drug = "streptomycin"
gene = "gid"
###################################
# call functions with relevant args
#------------------------------------------
# import_dirs()
# should return the follwoing variables:
# datadir
# indir
# outdir
# plotdir
# dr_muts_col
# other_muts_col
# resistance_col
#--------------------------------------------
import_dirs(drug, gene)
#---------------------------------------------
# plotting_data()
# should return the following dfs:
# my_df
# my_df_u
# my_df_u_lig
# dup_muts
#----------------------------------------------
#if (!exists("infile") && exists("gene")){
if (!is.character(infile) && exists("gene")){
#in_filename_params = paste0(tolower(gene), "_all_params.csv")
in_filename_params = paste0(tolower(gene), "_comb_stab_struc_params.csv") # part combined for gid
infile = paste0(outdir, "/", in_filename_params)
cat("\nInput file not specified, assuming filename: ", infile, "\n")
}
# Get the DFs out of plotting_data()
pd_df = plotting_data(infile)
my_df = pd_df[[1]]
my_df_u = pd_df[[2]]
my_df_u_lig = pd_df[[3]]
dup_muts = pd_df[[4]]
#########################################################
cat(paste0("Directories imported:"
, "\ndatadir:", datadir
, "\nindir:", indir
, "\noutdir:", outdir
, "\nplotdir:", plotdir))
cat(paste0("Variables imported:"
, "\ndrug:", drug
, "\ngene:", gene))
#==========================================================
#================
# Data for plots
#================
# REASSIGNMENT as necessary
#df = my_df_u
# sanity checks
str(df)
#===========================================================
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Mtb target: gid"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(radioButtons("rb", "Biophysical effect"
, choiceNames = list(
"mCSM"
, "FoldX"
, "mCSM-lig")
, choiceValues = list(
"mCSM"
, "FoldX"
, "mCSM-lig")
))
# Show a plot of the generated distribution
, mainPanel(plotOutput("distPlot")
, textOutput("txt"))))
# Define server logic required to draw a histogram
server <- function(input, output) {output$distPlot <- renderPlot({
axisType = input$rb
my_title = paste0("Barplots for biophyiscal effects ", axisType)
if (axisType == "mCSM") {
data_plot = my_df_u
stability_colname = "duet_outcome"
leg_name = "DUET outcome"
p_title = ""}
if (axisType == "FoldX") {
data_plot = my_df_u
stability_colname = "foldx_outcome"
leg_name = "FoldX outcome"
p_title = ""}
if (axisType == "mCSM-lig") {
data_plot = my_df_u_lig
stability_colname = "ligand_outcome"
leg_name = "Ligand affinity outcome"
p_title = "Sites < 10 Ang of ligand"}
# plot the basic barplots
my_stability_count(plotdf = data_plot
, df_colname = stability_colname,
, leg_title = leg_name
, bp_plot_title = p_title)
})
#output$txt <- renderText({
# paste("You chose", input$rb)})
}
stabiliyPlot <- function(input, output) {
}
# Run the application
shinyApp(ui = ui, server = server)