moved bp function script to function/
This commit is contained in:
parent
225360fb93
commit
786eaabe1a
3 changed files with 28 additions and 261 deletions
|
@ -17,6 +17,7 @@ library(dplyr)
|
||||||
# load functions
|
# load functions
|
||||||
source("../plotting_globals.R")
|
source("../plotting_globals.R")
|
||||||
source("../plotting_data.R")
|
source("../plotting_data.R")
|
||||||
|
source("my_stability_bp.R")
|
||||||
###################################
|
###################################
|
||||||
# command line args :
|
# command line args :
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ cat(paste0("Variables imported:"
|
||||||
# Data for plots
|
# Data for plots
|
||||||
#================
|
#================
|
||||||
# REASSIGNMENT as necessary
|
# REASSIGNMENT as necessary
|
||||||
df = my_df_u
|
#df = my_df_u
|
||||||
|
|
||||||
# sanity checks
|
# sanity checks
|
||||||
str(df)
|
str(df)
|
||||||
|
@ -94,56 +95,49 @@ ui <- fluidPage(
|
||||||
|
|
||||||
# Sidebar with a slider input for number of bins
|
# Sidebar with a slider input for number of bins
|
||||||
sidebarLayout(
|
sidebarLayout(
|
||||||
sidebarPanel(radioButtons("rb", "biophysical effect"
|
sidebarPanel(radioButtons("rb", "Biophysical effect"
|
||||||
, choiceNames = list(
|
, choiceNames = list(
|
||||||
"mCSM"
|
"mCSM"
|
||||||
, "FoldX")
|
, "FoldX"
|
||||||
|
, "mCSM-lig")
|
||||||
, choiceValues = list(
|
, choiceValues = list(
|
||||||
"mCSM"
|
"mCSM"
|
||||||
, "FoldX")
|
, "FoldX"
|
||||||
|
, "mCSM-lig")
|
||||||
))
|
))
|
||||||
# Show a plot of the generated distribution
|
# Show a plot of the generated distribution
|
||||||
, mainPanel(plotOutput("distPlot")
|
, mainPanel(plotOutput("distPlot")
|
||||||
, textOutput("txt"))))
|
, textOutput("txt"))))
|
||||||
|
|
||||||
# Define server logic required to draw a histogram
|
# 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({
|
server <- function(input, output) {output$distPlot <- renderPlot({
|
||||||
axisType = input$rb
|
axisType = input$rb
|
||||||
my_title = paste0("Barplots for biophyiscal effects ", axisType)
|
my_title = paste0("Barplots for biophyiscal effects ", axisType)
|
||||||
|
|
||||||
if (axisType == "mCSM") {
|
if (axisType == "mCSM") {
|
||||||
y_value = "duet_outcome"
|
data_plot = my_df_u
|
||||||
leg_name = "DUET outcome"}
|
stability_colname = "duet_outcome"
|
||||||
|
leg_name = "DUET outcome"
|
||||||
|
p_title = ""}
|
||||||
|
|
||||||
if (axisType == "FoldX") {
|
if (axisType == "FoldX") {
|
||||||
y_value = "foldx_outcome"
|
data_plot = my_df_u
|
||||||
leg_name = "FoldX outcome"}
|
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)
|
||||||
|
|
||||||
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({
|
#output$txt <- renderText({
|
||||||
# paste("You chose", input$rb)})
|
# paste("You chose", input$rb)})
|
||||||
|
|
|
@ -1,150 +0,0 @@
|
||||||
## 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)
|
|
|
@ -1,77 +0,0 @@
|
||||||
#!/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"
|
|
||||||
)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue