diff --git a/scripts/plotting/basic_barplots_LIG.R b/scripts/plotting/basic_barplots_LIG.R index 9b15944..5b4ae4a 100755 --- a/scripts/plotting/basic_barplots_LIG.R +++ b/scripts/plotting/basic_barplots_LIG.R @@ -99,9 +99,10 @@ cat(paste0("Directories imported:" , "\noutdir:", outdir , "\nplotdir:", plotdir)) - cat(paste0("Variables imported:" + cat(paste0("\nVariables imported:" , "\ndrug:", drug - , "\ngene:", gene)) + , "\ngene:", gene + , "\n")) #, "\ngene_match:", gene_match #, "\nLength of upos:", length(upos) #, "\nAngstrom symbol:", angstroms_symbol)) @@ -130,46 +131,19 @@ str(df) #**************** # Plot 1: Count of stabilising and destabilsing muts #**************** - #svg("basic_barplots_LIG.svg") svg(plot_basic_bp_ligand) print(paste0("plot1 filename:", basic_bp_ligand)) -my_ats = 25 # axis text size -my_als = 22 # axis label size - -theme_set(theme_grey()) - #-------------- -# start plot 1 +# start plot 1: call function #-------------- -g = ggplot(df, aes(x = ligand_outcome)) -OutPlot_lig_count = g + geom_bar(aes(fill = ligand_outcome) - , 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="ligand_outcome" - ) + - scale_fill_discrete(name = "Ligand Outcome" - , labels = c("Destabilising", "Stabilising")) - -print(OutPlot_lig_count) +stability_count_bp(plotdf = my_df_u_lig + , df_colname = "ligand_outcome" + , leg_title = "Ligand outcome") dev.off() -table(df$ligand_outcome) +table(my_df_u_lig$ligand_outcome) #======================================================================= #**************** # Plot 2: frequency of positions @@ -255,4 +229,4 @@ print(OutPlot_lig_pos_count) dev.off() ######################################################################## # end of LIG barplots -######################################################################## \ No newline at end of file +######################################################################## diff --git a/scripts/plotting/basic_barplots_PS.R b/scripts/plotting/basic_barplots_PS.R index 23644e0..fd41ca4 100755 --- a/scripts/plotting/basic_barplots_PS.R +++ b/scripts/plotting/basic_barplots_PS.R @@ -23,6 +23,7 @@ require("getopt", quietly = TRUE) # cmd parse arguments # load functions source("plotting_globals.R") source("plotting_data.R") +source("functions/stability_count_bp.R") ######################################################### # command line args #******************** @@ -98,9 +99,10 @@ cat(paste0("Directories imported:" , "\noutdir:", outdir , "\nplotdir:", plotdir)) - cat(paste0("Variables imported:" + cat(paste0("\nVariables imported:" , "\ndrug:", drug - , "\ngene:", gene)) + , "\ngene:", gene + , "\n)) #, "\ngene_match:", gene_match #, "\nLength of upos:", length(upos) #, "\nAngstrom symbol:", angstroms_symbol)) @@ -129,45 +131,18 @@ str(df) #**************** # Plot 1: Count of stabilising and destabilsing muts #**************** - svg(plot_basic_bp_duet) print(paste0("plot1 filename:", basic_bp_duet)) -my_ats = 25 # axis text size -my_als = 22 # axis label size - -theme_set(theme_grey()) - #-------------- -# start plot 1 +# start plot 1: call function #-------------- -g = ggplot(df, aes(x = duet_outcome)) -OutPlot_count = g + geom_bar(aes(fill = duet_outcome) - , 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 = "DUET Outcome" - , labels = c("Destabilising", "Stabilising")) - -print(OutPlot_count) +stability_count_bp(plotdf = my_df_u + , df_colname = "duet_outcome" + , leg_title = "DUET outcome") dev.off() -table(df$duet_outcome) +table(my_df_u$duet_outcome) #======================================================================= #**************** # Plot 2: frequency of positions @@ -252,4 +227,4 @@ print(OutPlot_pos_count) dev.off() ######################################################################## # end of PS barplots -######################################################################## \ No newline at end of file +######################################################################## diff --git a/scripts/plotting/basic_barplots_foldx.R b/scripts/plotting/basic_barplots_foldx.R index 0200cce..e78840d 100755 --- a/scripts/plotting/basic_barplots_foldx.R +++ b/scripts/plotting/basic_barplots_foldx.R @@ -23,6 +23,7 @@ require("getopt", quietly = TRUE) # cmd parse arguments # load functions source("plotting_globals.R") source("plotting_data.R") +source("functions/stability_count_bp.R") ######################################################### # command line args #******************** @@ -99,9 +100,10 @@ cat(paste0("Directories imported:" , "\noutdir:", outdir , "\nplotdir:", plotdir)) - cat(paste0("Variables imported:" + cat(paste0("\nVariables imported:" , "\ndrug:", drug - , "\ngene:", gene)) + , "\ngene:", gene + , "\n")) #, "\ngene_match:", gene_match #, "\nLength of upos:", length(upos) #, "\nAngstrom symbol:", angstroms_symbol)) @@ -125,45 +127,18 @@ str(df) #**************** # Plot 1: Count of stabilising and destabilsing muts #**************** - svg(plot_basic_bp_foldx) print(paste0("plot1 filename:", plot_basic_bp_foldx)) -my_ats = 25 # axis text size -my_als = 22 # axis label size - -theme_set(theme_grey()) - #-------------- -# start plot 1 +# start plot 1: call function #-------------- -g = ggplot(df, aes(x = foldx_outcome)) -foldx_outcome_count = g + geom_bar(aes(fill = foldx_outcome) - , 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="FoldX Outcome" - ) + - scale_fill_discrete(name = "FoldX Outcome" - , labels = c("Destabilising", "Stabilising")) - -print(foldx_outcome_count) +stability_count_bp(plotdf = my_df_u + , df_colname = "foldx_outcome" + , leg_title = "FoldX outcome") dev.off() -table(df$foldx_outcome) +table(my_df_u$foldx_outcome) ######################################################################## # end of foldx barplot -######################################################################## \ No newline at end of file +######################################################################## diff --git a/scripts/plotting/functions/stability_count_bp.R b/scripts/plotting/functions/stability_count_bp.R new file mode 100644 index 0000000..78adf30 --- /dev/null +++ b/scripts/plotting/functions/stability_count_bp.R @@ -0,0 +1,50 @@ +#!/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 +#========================================================== +stability_count_bp <- 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 +############################################################# \ No newline at end of file diff --git a/scripts/plotting/functions/test_functions.R b/scripts/plotting/functions/test_functions.R new file mode 100644 index 0000000..a056ebb --- /dev/null +++ b/scripts/plotting/functions/test_functions.R @@ -0,0 +1,27 @@ +#================= +# 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 +#------------------------------ +#stability_count_bp(plotdf = my_df +# , df_colname = "duet_outcome" +# , leg_title = "DUET outcome") + +#------------------------------ +# barplot for ligand affinity +#------------------------------ +#stability_count_bp(plotdf = my_df_u +# , df_colname = "ligand_outcome" +# , leg_title = "Ligand outcome" +# , bp_plot_title = "Sites < 10 Ang of ligand" +#) + diff --git a/scripts/plotting/myshiny/bp_app.R b/scripts/plotting/myshiny/bp_app.R index e60b792..5f1f36b 100644 --- a/scripts/plotting/myshiny/bp_app.R +++ b/scripts/plotting/myshiny/bp_app.R @@ -17,7 +17,7 @@ library(dplyr) # load functions source("../plotting_globals.R") source("../plotting_data.R") -source("my_stability_bp.R") +source("../functions/stability_count_bp.R") ################################### # command line args : @@ -133,7 +133,7 @@ server <- function(input, output) {output$distPlot <- renderPlot({ p_title = "Sites < 10 Ang of ligand"} # plot the basic barplots - my_stability_count(plotdf = data_plot + stability_count_bp(plotdf = data_plot , df_colname = stability_colname, , leg_title = leg_name , bp_plot_title = p_title)