From dad8f526a21402ca7d573c1fa846bf3ec1cb67ef Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Tue, 9 Nov 2021 13:55:21 +0000 Subject: [PATCH] added TESTING_plots.R --- scripts/plotting/TESTING_PLOTS.R | 112 +++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 scripts/plotting/TESTING_PLOTS.R diff --git a/scripts/plotting/TESTING_PLOTS.R b/scripts/plotting/TESTING_PLOTS.R new file mode 100755 index 0000000..b761415 --- /dev/null +++ b/scripts/plotting/TESTING_PLOTS.R @@ -0,0 +1,112 @@ +#!/usr/bin/env Rscript +getwd() +setwd("~/git/LSHTM_analysis/scripts/plotting") +getwd() +source("Header_TT.R") + +drug = 'streptomycin' +gene = 'gid' + +spec = matrix(c( + "drug" , "d", 1, "character", + "gene" , "g", 1, "character", + "data_file1" , "fa", 2, "character", + "data_file2" , "fb", 2, "character" +), byrow = TRUE, ncol = 4) + +opt = getopt(spec) + +drug = opt$drug +gene = opt$gene +infile_params = opt$data_file1 +infile_metadata = opt$data_file2 + +if(is.null(drug)|is.null(gene)) { + stop("Missing arguments: --drug and --gene must both be specified (case-sensitive)") +} + +#=========== +# Input +#=========== +source("get_plotting_dfs.R") + +#=========== +# output +#=========== +# PS +bp_subcols_duet = "barplot_coloured_PS.svg" +plot_bp_subcols_duet = paste0(plotdir, "/", bp_subcols_duet) + +############################################################################## +# add frequency of positions (from lib data.table) + +setDT(subcols_df_ps)[, pos_count := .N, by = .(position)] + + +foo = data.frame(subcols_df_ps$mutationinformation + , subcols_df_ps$position + , subcols_df_ps$pos_count) + +#snpsBYpos_df <- subcols_df_ps %>% +# group_by(position) %>% +# summarize(snpsBYpos = mean(pos_count)) + + +#******************** +# generate plot: PS +# NO axis colours +#******************** +g = ggplot(subcols_df_ps + , aes(x = factor(position, ordered = T))) +g2 = g + geom_bar() + +g2 + +foo = g2 + geom_text(stat='count', aes(label = ..count..)) +foo + +###### +bp_subcols_duet = "TEST_PS.svg" +plot_bp_subcols_duet = paste0(plotdir, "/", bp_subcols_duet) +print(paste0("plot name:", plot_bp_subcols_duet)) +svg(plot_bp_subcols_duet, width = 26, height = 4) + +g1 = ggplot(subcols_df_ps, aes(x = factor(position, ordered = T) + , y = pos_count)) + + geom_bar(stat = "summary" + , aes(fill = group), colour = "grey") + + + + + + +################################### + +g = ggplot(subcols_df_ps + , aes(x = factor(position, ordered = T))) +outPlot_bp_ps = g + + geom_bar(aes(fill = group), colour = "grey") + + scale_fill_manual( values = subcols_ps + , guide = "none") + + theme( axis.text.x = element_text(size = my_xaxls + , angle = 90 + , hjust = 1 + , vjust = 0.4) + , axis.text.y = element_text(size = my_yaxls + , angle = 0 + , hjust = 1 + , vjust = 0) + , axis.title.x = element_text(size = my_xaxts) + , axis.title.y = element_text(size = my_yaxts ) ) + + labs(title = "" + #title = my_title + , x = "Position" + , y = "Frequency") + +print(outPlot_bp_ps) +#dev.off() + +######################################################################= +# End of script +######################################################################= +