From 7c40e13771b17d520191ea72f03707b1aa361f26 Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Sun, 14 Aug 2022 22:56:08 +0100 Subject: [PATCH] dadded v2 of barplot layput --- scripts/functions/position_count_bp.R | 24 +- scripts/functions/stability_count_bp.R | 16 +- .../plotting/plotting_thesis/basic_barplots.R | 115 ++++--- .../plotting_thesis/basic_barplots2.R | 292 ++++++++++++++++++ .../basic_barplots_layout_v2.R | 237 ++++++++++++++ scripts/plotting/plotting_thesis/bp_PE.R | 182 +++++++++++ .../plotting_thesis/prominent_effects.R | 13 +- 7 files changed, 800 insertions(+), 79 deletions(-) create mode 100644 scripts/plotting/plotting_thesis/basic_barplots2.R create mode 100644 scripts/plotting/plotting_thesis/basic_barplots_layout_v2.R create mode 100644 scripts/plotting/plotting_thesis/bp_PE.R diff --git a/scripts/functions/position_count_bp.R b/scripts/functions/position_count_bp.R index 26a19e1..1fcdba3 100755 --- a/scripts/functions/position_count_bp.R +++ b/scripts/functions/position_count_bp.R @@ -26,14 +26,15 @@ site_snp_count_bp <- function (plotdf , df_colname = "position" #, bp_plot_title = "" #, leg_title = "Legend title" - , leg_text_size = 20 - , axis_text_size = 25 - , axis_label_size = 22 + , leg_text_size = 10#20 + , axis_text_size = 10#25 + , axis_label_size = 10#22 + , subtitle_size = 10#20 + , geom_ls = 10 , xaxis_title = "Number of nsSNPs" , yaxis_title = "Number of Sites" , title_colour = "chocolate4" , subtitle_text = NULL - , subtitle_size = 20 , subtitle_colour = "pink") { @@ -131,7 +132,7 @@ site_snp_count_bp <- function (plotdf scale_x_continuous(breaks = unique(snpsBYpos_df$snpsBYpos)) + geom_label(stat = "count", aes(label = ..count..) , color = "black" - , size = 10) + + , size = geom_ls) + theme(axis.text.x = element_text(size = axis_text_size , angle = 0) , axis.text.y = element_text(size = axis_text_size @@ -148,10 +149,15 @@ site_snp_count_bp <- function (plotdf , plot.subtitle = element_text(size = subtitle_size , hjust = 0.5 , colour = subtitle_colour)) + - labs(title = bp_plot_title - , subtitle = subtitle_text - , x = xaxis_title - , y = yaxis_title) + # labs(title = bp_plot_title + # , subtitle = subtitle_text + # , x = xaxis_title + # , y = yaxis_title) + + labs(title = "" + , subtitle = bp_plot_title + , x = xaxis_title + , y = yaxis_title) } ######################################################################## diff --git a/scripts/functions/stability_count_bp.R b/scripts/functions/stability_count_bp.R index 76858c7..f0b735b 100644 --- a/scripts/functions/stability_count_bp.R +++ b/scripts/functions/stability_count_bp.R @@ -17,17 +17,17 @@ theme_set(theme_grey()) stability_count_bp <- function(plotdf , df_colname = "" , leg_title = "" - , ats = 25 # axis text size - , als = 22 # axis label size - , lts = 20 # legend text size - , ltis = 22 # label title size + , ats = 12#25 # axis text size + , als = 11#22 # axis label size + , lts = 10#20 # legend text size + , ltis = 11#22 # label title size , geom_ls = 10 # geom_label size , yaxis_title = "Number of nsSNPs" , bp_plot_title = "" , label_categories #= c("LEVEL1", "LEVEL2") , title_colour = "chocolate4" , subtitle_text = NULL - , sts = 20 + , sts = 10#20 , subtitle_colour = "#350E20FF" #brown #, leg_position = c(0.73,0.8) # within plot area , leg_position = "top" @@ -45,7 +45,10 @@ stability_count_bp <- function(plotdf , aes(label = ..count..) , color = "black" , show.legend = FALSE - , size = geom_ls) + + , size = geom_ls + #, nudge_x = 0 + #, nudge_y = -1 + , label.size = 0.25 ) + theme(axis.text.x = element_blank() , axis.title.x = element_blank() , axis.title.y = element_text(size = als) @@ -53,6 +56,7 @@ stability_count_bp <- function(plotdf , legend.position = leg_position , legend.text = element_text(size = lts) , legend.title = element_text(size = ltis) + , legend.key.size = unit(lts,"pt") , plot.title = element_text(size = als , colour = title_colour , hjust = 0.5) diff --git a/scripts/plotting/plotting_thesis/basic_barplots.R b/scripts/plotting/plotting_thesis/basic_barplots.R index 0d75ae3..f3af7ff 100755 --- a/scripts/plotting/plotting_thesis/basic_barplots.R +++ b/scripts/plotting/plotting_thesis/basic_barplots.R @@ -39,12 +39,12 @@ class(merged_df3) merged_df3 = as.data.frame(merged_df3) class(df3) -head(df3$pos_count) +head(merged_df3$pos_count) nc_pc_CHANGE = which(colnames(merged_df3)== "pos_count") colnames(merged_df3)[nc_pc_CHANGE] = "df2_pos_count_all" head(merged_df3$pos_count) -head(merged_df3$pos_count_all) +head(merged_df3$df2_pos_count_all) # DROP pos_count column # merged_df3$pos_count <-NULL @@ -247,11 +247,6 @@ snap2P = stability_count_bp(plotdf = df3 # # dev.off() - - - - - ########################################################### #========================= # Affinity outcome @@ -285,7 +280,7 @@ mLigP = stability_count_bp(plotdf = df3_lig , bar_fill_values = c("#F8766D", "#00BFC4") , sts = sts , subtitle_colour= subtitle_colour - , bp_plot_title = paste(common_bp_title, "ligand") + #, bp_plot_title = paste(common_bp_title, "ligand") ) #------------------------------ @@ -304,7 +299,7 @@ mmLigP = stability_count_bp(plotdf = df3_lig , bar_fill_values = c("#F8766D", "#00BFC4") , sts = sts , subtitle_colour= subtitle_colour - , bp_plot_title = paste(common_bp_title, "ligand") + #, bp_plot_title = paste(common_bp_title, "ligand") ) #------------------------------ @@ -485,46 +480,43 @@ dev.off() ##################################################################### # test - -setDT(df3)[, pos_count2 := .N, by = .(eval(parse(text = "position")))] -foo = df3[, c("mutationinformation", "position")] -df4 = foo[, c("mutationinformation", "position")] - - -var_pos = "position" -df4 = - df4 %>% - dplyr::add_count(eval(parse(text = var_pos))) - -class(df4) -df4 = as.data.frame(df4) -class(df4) -nc_change = which(colnames(df4) == "n") -colnames(df4)[nc_change] <- "pos_count" -class(df4) - -setDT(df4)[, pos_count2 := .N, by = .(eval(parse(text = "position")))] -class(df4) - -all(df4$pos_count==df4$pos_count2) - -# %>% - #group_by(pos_count = position) - +# +# setDT(df3)[, pos_count2 := .N, by = .(eval(parse(text = "position")))] +# foo = df3[, c("mutationinformation", "position")] +# df4 = foo[, c("mutationinformation", "position")] +# +# +# var_pos = "position" # df4 = # df4 %>% -# dplyr::group_by(position) %>% -# count(position) - - -foo2 = df4[, c("mutationinformation", "position", "pos_count")] +# dplyr::add_count(eval(parse(text = var_pos))) +# +# class(df4) +# df4 = as.data.frame(df4) +# class(df4) +# nc_change = which(colnames(df4) == "n") +# colnames(df4)[nc_change] <- "pos_count" +# class(df4) +# +# setDT(df4)[, pos_count2 := .N, by = .(eval(parse(text = "position")))] +# class(df4) +# +# all(df4$pos_count==df4$pos_count2) +# +# # %>% +# #group_by(pos_count = position) +# +# # df4 = +# # df4 %>% +# # dplyr::group_by(position) %>% +# # count(position) +#foo2 = df4[, c("mutationinformation", "position", "pos_count")] ##################################################################### # ------------------------------ # bp site site count: ALL # <10 Ang ligand # ------------------------------ - posC_all = site_snp_count_bp(plotdf = df3 , df_colname = "position" , xaxis_title = "Number of nsSNPs" @@ -541,9 +533,10 @@ posC_lig = site_snp_count_bp(plotdf = df3_lig , df_colname = "position" , xaxis_title = "Number of nsSNPs" , yaxis_title = "Number of Sites"#+ annotate("text", x = 1.5, y = 2.2, label = "Text No. 1") - , subtitle_text = paste0(common_bp_title, " ligand") - , subtitle_size = 20 + #, subtitle_text = paste0(common_bp_title, " ligand") + , subtitle_size = 8 , subtitle_colour = subtitle_colour) +posC_lig # ------------------------------ # bp site site count: ppi2 # < 10 Ang interface @@ -556,7 +549,7 @@ posC_ppi2 = site_snp_count_bp(plotdf = df3_ppi2 , subtitle_text = paste0(common_bp_title, " interface") , subtitle_size = 20 , subtitle_colour = subtitle_colour) - +posC_ppi2 # ------------------------------ #FIXME: bp site site count: na # < 10 Ang TBC @@ -571,23 +564,23 @@ posC_ppi2 = site_snp_count_bp(plotdf = df3_ppi2 # output: SITE SNP count: # all + affinity #========================== -my_label_size = 25 -pos_count_combined_CLP = paste0(outdir_images - ,tolower(gene) - ,"_pos_count_PS_AFF.svg") - - -svg(pos_count_combined_CLP, width = 20, height = 5.5) -print(paste0("plot filename:", pos_count_combined_CLP)) - -cowplot::plot_grid(posC_all, posC_lig, posC_ppi2 - #, posC_na - , nrow = 1 - , ncol = 3 - , labels = "AUTO" - , label_size = my_label_size) - -dev.off() +# my_label_size = 25 +# pos_count_combined_CLP = paste0(outdir_images +# ,tolower(gene) +# ,"_pos_count_PS_AFF.svg") +# +# +# svg(pos_count_combined_CLP, width = 20, height = 5.5) +# print(paste0("plot filename:", pos_count_combined_CLP)) +# +# cowplot::plot_grid(posC_all, posC_lig, posC_ppi2 +# #, posC_na +# , nrow = 1 +# , ncol = 3 +# , labels = "AUTO" +# , label_size = my_label_size) +# +# dev.off() #=============================================================== diff --git a/scripts/plotting/plotting_thesis/basic_barplots2.R b/scripts/plotting/plotting_thesis/basic_barplots2.R new file mode 100644 index 0000000..12b2b16 --- /dev/null +++ b/scripts/plotting/plotting_thesis/basic_barplots2.R @@ -0,0 +1,292 @@ +#!/usr/bin/env Rscript +######################################################### +# TASK: Barplots for mCSM DUET, ligand affinity, and foldX +# basic barplots with count of mutations +# basic barplots with frequency of count of mutations + +# , df_colname = "" +# , leg_title = "" +# , ats = 25 # axis text size +# , als = 22 # axis label size +# , lts = 20 # legend text size +# , ltis = 22 # label title size +# , geom_ls = 10 # geom_label size +# , yaxis_title = "Number of nsSNPs" +# , bp_plot_title = "" +# , label_categories = c("Destabilising", "Stabilising") +# , title_colour = "chocolate4" +# , subtitle_text = NULL +# , sts = 20 +# , subtitle_colour = "pink" +# #, leg_position = c(0.73,0.8) # within plot area +# , leg_position = "top" +# , bar_fill_values = c("#F8766D", "#00BFC4") +######################################################### +#============= +# Data: Input +#============== +#source("~/git/LSHTM_analysis/config/alr.R") +source("~/git/LSHTM_analysis/config/embb.R") +#source("~/git/LSHTM_analysis/config/katg.R") +#source("~/git/LSHTM_analysis/config/gid.R") +#source("~/git/LSHTM_analysis/config/pnca.R") +#source("~/git/LSHTM_analysis/config/rpob.R") + +source("~/git/LSHTM_analysis/scripts/plotting/get_plotting_dfs.R") +source("~/git/LSHTM_analysis/scripts/plotting/plotting_colnames.R") + +class(merged_df3) +merged_df3 = as.data.frame(merged_df3) + +class(df3) +head(merged_df3$pos_count) + +nc_pc_CHANGE = which(colnames(merged_df3)== "pos_count"); nc_pc_CHANGE +colnames(merged_df3)[nc_pc_CHANGE] = "df2_pos_count_all" +head(merged_df3$pos_count) +head(merged_df3$df2_pos_count_all) + +# DROP pos_count column +# merged_df3$pos_count <-NULL +merged_df3 = merged_df3[, !colnames(merged_df3)%in%c("pos_count")] +head(merged_df3$pos_count) + +df3 = merged_df3[, colnames(merged_df3)%in%plotting_cols] + + +#======= +# output +#======= +outdir_images = paste0("~/git/Writing/thesis/images/results/", tolower(gene), "/") +cat("plots will output to:", outdir_images) + +########################################################### +#------------------------------ +# plot default sizes +#------------------------------ +#========================= +# Affinity outcome +# check this var: outcome_cols_affinity +# get from preformatting or put in globals +#========================== +DistCutOff +LigDist_colname # = "ligand_distance" # from globals +ppi2Dist_colname +naDist_colname + +########################################################### +# get plotting data within the distance +df3_lig = df3[df3[[LigDist_colname]]