added shiny app and turned stability bp to function
This commit is contained in:
parent
3f58a5c64c
commit
225360fb93
4 changed files with 386 additions and 4 deletions
156
scripts/plotting/myshiny/bp_app.R
Normal file
156
scripts/plotting/myshiny/bp_app.R
Normal file
|
@ -0,0 +1,156 @@
|
|||
## 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")
|
||||
###################################
|
||||
# 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")
|
||||
, choiceValues = list(
|
||||
"mCSM"
|
||||
, "FoldX")
|
||||
))
|
||||
# Show a plot of the generated distribution
|
||||
, mainPanel(plotOutput("distPlot")
|
||||
, textOutput("txt"))))
|
||||
|
||||
# Define server logic required to draw a histogram
|
||||
my_ats = 25 # axis text size
|
||||
my_als = 22 # axis label size
|
||||
|
||||
theme_set(theme_grey())
|
||||
|
||||
server <- function(input, output) {output$distPlot <- renderPlot({
|
||||
axisType = input$rb
|
||||
my_title = paste0("Barplots for biophyiscal effects ", axisType)
|
||||
if (axisType == "mCSM") {
|
||||
y_value = "duet_outcome"
|
||||
leg_name = "DUET outcome"}
|
||||
|
||||
if (axisType == "FoldX") {
|
||||
y_value = "foldx_outcome"
|
||||
leg_name = "FoldX outcome"}
|
||||
|
||||
ggplot(df, aes(x = eval(parse(text = y_value)))) +
|
||||
geom_bar(aes(fill = eval(parse(text = y_value))), show.legend = TRUE) +
|
||||
geom_label(stat = "count"
|
||||
, aes(label = ..count..)
|
||||
, color = "black"
|
||||
, show.legend = FALSE
|
||||
, size = 10) +
|
||||
theme(axis.text.x = element_blank()
|
||||
, axis.title.x = element_blank()
|
||||
, axis.title.y = element_text(size=my_als)
|
||||
, axis.text.y = element_text(size = my_ats)
|
||||
, legend.position = c(0.73,0.8)
|
||||
, legend.text = element_text(size=my_als-2)
|
||||
, legend.title = element_text(size=my_als)
|
||||
, plot.title = element_blank()) +
|
||||
labs(title = ""
|
||||
, y = "Number of nsSNPs"
|
||||
#, fill="DUET Outcome"
|
||||
) +
|
||||
scale_fill_discrete(name = leg_name
|
||||
, labels = c("Destabilising", "Stabilising"))
|
||||
})
|
||||
#output$txt <- renderText({
|
||||
# paste("You chose", input$rb)})
|
||||
|
||||
}
|
||||
|
||||
stabiliyPlot <- function(input, output) {
|
||||
}
|
||||
# Run the application
|
||||
shinyApp(ui = ui, server = server)
|
150
scripts/plotting/myshiny/bp_app_test.R
Normal file
150
scripts/plotting/myshiny/bp_app_test.R
Normal 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)
|
77
scripts/plotting/myshiny/my_stability_bp.R
Normal file
77
scripts/plotting/myshiny/my_stability_bp.R
Normal file
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env Rscript
|
||||
# load libraries
|
||||
#########################################################
|
||||
# TASK: function for basic barplot returning stability counts
|
||||
#########################################################
|
||||
# load libraries and functions
|
||||
library(ggplot2)
|
||||
theme_set(theme_grey())
|
||||
#==========================================================
|
||||
# my_stability_count(): basic barplots for stability counts
|
||||
# input args
|
||||
## df containing data to plot
|
||||
## df column name containing stability outcome
|
||||
## legend title
|
||||
## ...opt args
|
||||
#==========================================================
|
||||
my_stability_count <- function(plotdf
|
||||
, df_colname
|
||||
, leg_title
|
||||
, axis_text_size = 25
|
||||
, axis_label_size = 22
|
||||
, leg_text_size = 20
|
||||
, yaxis_title = "Number of nsSNPs"
|
||||
, bp_plot_title = ""){
|
||||
|
||||
OutPlot_count = ggplot(plotdf, aes(x = eval(parse(text = df_colname)))) +
|
||||
geom_bar(aes(fill = eval(parse(text = df_colname))), show.legend = TRUE) +
|
||||
geom_label(stat = "count"
|
||||
, aes(label = ..count..)
|
||||
, color = "black"
|
||||
, show.legend = FALSE
|
||||
, size = 10) +
|
||||
theme(axis.text.x = element_blank()
|
||||
, axis.title.x = element_blank()
|
||||
, axis.title.y = element_text(size = axis_label_size)
|
||||
, axis.text.y = element_text(size = axis_text_size)
|
||||
, legend.position = c(0.73,0.8)
|
||||
, legend.text = element_text(size = leg_text_size)
|
||||
, legend.title = element_text(size = axis_label_size)
|
||||
, plot.title = element_text(size = axis_label_size)) +
|
||||
labs(title = bp_plot_title
|
||||
, y = yaxis_title) +
|
||||
scale_fill_discrete(name = leg_title
|
||||
, labels = c("Destabilising", "Stabilising"))
|
||||
|
||||
return(OutPlot_count)
|
||||
}
|
||||
#############################################################
|
||||
# end of function
|
||||
#############################################################
|
||||
#=================
|
||||
# Test function
|
||||
#==================
|
||||
source("../plotting_data.R")
|
||||
infile = "/home/tanu/git/Data/streptomycin/output/gid_comb_stab_struc_params.csv"
|
||||
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]]
|
||||
|
||||
#------------------------------
|
||||
# barplot for mscm stability
|
||||
#------------------------------
|
||||
#my_stability_count(plotdf = my_df,
|
||||
# , df_colname = "duet_outcome",
|
||||
# , leg_title = "DUET outcome")
|
||||
|
||||
#------------------------------
|
||||
# barplot for ligand affinity
|
||||
#------------------------------
|
||||
my_stability_count(plotdf = my_df_u,
|
||||
, df_colname = "ligand_outcome",
|
||||
, leg_title = "Ligand outcome"
|
||||
, bp_plot_title = "Sites < 10 Ang of ligand"
|
||||
)
|
||||
|
|
@ -5,8 +5,7 @@
|
|||
# load libraries and functions
|
||||
library(data.table)
|
||||
library(dplyr)
|
||||
#########################################################
|
||||
|
||||
#========================================================
|
||||
# plotting_data(): formatting data for plots
|
||||
# input args:
|
||||
## input csv file
|
||||
|
@ -16,7 +15,7 @@ library(dplyr)
|
|||
## my_df_u
|
||||
## my_df_u_lig
|
||||
## dup_muts
|
||||
|
||||
#========================================================
|
||||
plotting_data <- function(infile_params, mcsm_lig_cutoff = 10) {
|
||||
my_df = data.frame()
|
||||
my_df_u = data.frame()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue