From 8d9ede186c296863e8d5150b2a2676af00f42098 Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Fri, 11 Sep 2020 14:40:37 +0100 Subject: [PATCH] added delta symbol to plotting_data.R and pretty labels for dr_other_muts figure --- scripts/plotting/other_plots.R | 163 +++++++++++++++------------- scripts/plotting/other_plots_data.R | 26 +++-- scripts/plotting/plotting_data.R | 2 + 3 files changed, 108 insertions(+), 83 deletions(-) diff --git a/scripts/plotting/other_plots.R b/scripts/plotting/other_plots.R index 25e0171..1497a8b 100644 --- a/scripts/plotting/other_plots.R +++ b/scripts/plotting/other_plots.R @@ -32,12 +32,13 @@ plot_point_legend = paste0(plotdir,"/", point_legend) #my_comparisons <- list( c(dr_muts_col, other_muts_col) ) my_comparisons <- list( c("DM", "OM") ) - -my_ats = 15# axis text size +my_ats = 22# axis text size my_als = 20 # axis label size my_fls = 20 # facet label size my_pts = 22 # plot title size +########################################################################## + #=========== # Plot1: PS #=========== @@ -65,7 +66,8 @@ p1 = ggplot(df_lf_ps, aes(x = mutation_info , vjust = 0) , axis.title.x = element_text(size = my_ats) , axis.title.y = element_text(size = my_ats) - , plot.title = element_text(size = my_pts , hjust = 0.5) + , plot.title = element_text(size = my_pts , hjust = 0.5, colour = "black", face = "bold") + , strip.background = element_rect(fill = "khaki2") , strip.text.x = element_text(size = my_fls, colour = "black") , legend.title = element_text(color = "black", size = my_als) , legend.text = element_text(size = my_ats) @@ -79,17 +81,65 @@ p1 = ggplot(df_lf_ps, aes(x = mutation_info #, label = "p.format") , label = "p.signif") p1 -#=============================================================== -#=========== -# Plot 2: LIG -#=========== + +########################################################################## +#================= +# Plot 2: Foldx +#================= +my_stat_foldx = compare_means(param_value~mutation_info, group.by = "param_type" + , data = df_lf_foldx, paired = FALSE, p.adjust.method = "BH") + +y_value = "param_value" + +p2 = ggplot(df_lf_foldx, aes(x = mutation_info + , y = eval(parse(text=y_value)) )) + + facet_wrap(~ param_type + , nrow = 1 + , scales = "free_y") + + geom_boxplot(fill = "white", outlier.colour = NA + #, position = position_dodge(width = 0.2) + , width = 0.5) + + geom_point(position = position_jitterdodge(dodge.width=0.01) + , alpha = 0.5 + , show.legend = FALSE + , aes(colour = factor(foldx_outcome))) + + theme(axis.text.x = element_text(size = my_ats) + , axis.text.y = element_text(size = my_ats + , angle = 0 + , hjust = 1 + , vjust = 0) + , axis.title.x = element_text(size = my_ats) + , axis.title.y = element_text(size = my_ats) + , plot.title = element_text(size = my_pts , hjust = 0.5, colour = "black", face = "bold") + , strip.background = element_rect(fill = "palegreen1") + , strip.text.x = element_text(size = my_fls, colour = "black") + , legend.title = element_text(color = "black", size = my_als) + , legend.text = element_text(size = my_ats) + #, legend.title = element_blank() + , legend.direction = "vertical") + + labs(title = "Foldx" + , x = "" + , y = "") + + stat_compare_means(comparisons = my_comparisons + , method = "wilcox.test" + , paired = FALSE + #, label = "p.format") + , label = "p.signif") + +p2 + + +########################################################################## +#============== +# Plot 3: LIG +#============== my_stat_lig = compare_means(param_value~mutation_info, group.by = "param_type" , data = df_lf_lig, paired = FALSE, p.adjust.method = "BH") y_value = "param_value" -p2 = ggplot(df_lf_lig, aes(x = mutation_info +p3 = ggplot(df_lf_lig, aes(x = mutation_info , y = eval(parse(text=y_value)) )) + facet_wrap(~ param_type , nrow = 1 @@ -108,7 +158,8 @@ p2 = ggplot(df_lf_lig, aes(x = mutation_info , vjust = 0) , axis.title.x = element_text(size = my_ats) , axis.title.y = element_text(size = my_ats) - , plot.title = element_text(size = my_pts , hjust = 0.5) + , plot.title = element_text(size = my_pts , hjust = 0.5, colour = "black", face = "bold") + , strip.background = element_rect(fill = "thistle3") , strip.text.x = element_text(size = my_fls, colour = "black") , legend.title = element_text(color = "black", size = my_als) , legend.text = element_text(size = my_ats) @@ -122,58 +173,12 @@ p2 = ggplot(df_lf_lig, aes(x = mutation_info #, label = "p.format") , label = "p.signif") -p2 +p3 -#==================================================================== -#=========== -# Plot 3: Foldx -#=========== -my_stat_foldx = compare_means(param_value~mutation_info, group.by = "param_type" - , data = df_lf_foldx, paired = FALSE, p.adjust.method = "BH") - -y_value = "param_value" - -p3 = ggplot(df_lf_foldx, aes(x = mutation_info - , y = eval(parse(text=y_value)) )) + - facet_wrap(~ param_type - , nrow = 1 - , scales = "free_y") + - geom_boxplot(fill = "white", outlier.colour = NA - #, position = position_dodge(width = 0.2) - , width = 0.5) + - geom_point(position = position_jitterdodge(dodge.width=0.01) - , alpha = 0.5 - , show.legend = FALSE - , aes(colour = factor(foldx_outcome))) + - theme(axis.text.x = element_text(size = my_ats) - , axis.text.y = element_text(size = my_ats - , angle = 0 - , hjust = 1 - , vjust = 0) - , axis.title.x = element_text(size = my_ats) - , axis.title.y = element_text(size = my_ats) - , plot.title = element_text(size = my_pts , hjust = 0.5) - , strip.text.x = element_text(size = my_fls, colour = "black") - #, legend.title = element_text(color = "black", size = my_als) - , legend.text = element_text(size = my_ats) - , legend.direction = "vertical" - , legend.title = element_blank()) + - labs(title = "" - , x = "" - , y = "") + - stat_compare_means(comparisons = my_comparisons - , method = "wilcox.test" - , paired = FALSE - #, label = "p.format") - , label = "p.signif") - -p3 - -#==================================================================== +########################################################################## #=========== # legend #=========== - legend = ggplot(df_lf_foldx, aes(x = mutation_info , y = eval(parse(text=y_value)) )) + facet_wrap(~ param_type @@ -186,12 +191,15 @@ legend = ggplot(df_lf_foldx, aes(x = mutation_info , aes(colour = factor(foldx_outcome))) + theme(legend.text = element_text(size = 25) , legend.direction = "vertical" - , legend.title = element_blank())+ - + , legend.title = element_blank() + #, axis.text.y = element_text(size = 30, colour = "black", angle = 90) + #, axis.text.x = element_text(size = 30, colour = "black", angle = 0) + #, strip.background = element_rect(fill="orange") + ) + guides(color = guide_legend(override.aes = list(size = 6))) legend - +########################################################################## #=========================== # combine #=========================== @@ -202,24 +210,19 @@ cat("Output plot:",plot_dr_other_combined) svg(plot_dr_other_combined, width = 24, height = 12) #theme_set(theme_gray()) # to preserve default theme -OutPlot = cowplot::plot_grid(p1, p2 - , nrow = 2 - , align = "hv" - , axis = "b" - , labels = c("", "", "") - , label_size = my_als) + + +# first combine fold and lig plots (2 and 3) +c1 = cowplot::plot_grid(p2, p3 + , nrow = 1 + , rel_widths = c(1/6, 5/6)) +c1 + +OutPlot = cowplot::plot_grid(p1, c1 + , nrow = 2) print(OutPlot) dev.off() - -#--------- -# plot 2 -#--------- -svg(plot_dr_other_foldx , width = 6, height = 7) -OutPlot2 = p3 -print(OutPlot2) -dev.off() - #--------- # plot 3: legend #--------- @@ -227,3 +230,13 @@ svg(plot_point_legend, width = 6, height = 7) OutPlot3 = legend print(OutPlot3) dev.off() + + + + + + + + + + diff --git a/scripts/plotting/other_plots_data.R b/scripts/plotting/other_plots_data.R index 9c79e37..60844aa 100644 --- a/scripts/plotting/other_plots_data.R +++ b/scripts/plotting/other_plots_data.R @@ -110,14 +110,12 @@ df_lig = merged_df3_lig # name tidying df_lig$mutation_info = as.factor(df_lig$mutation_info) df_lig$duet_outcome = as.factor(df_lig$duet_outcome) -df_lig$ligand_outcome = as.factor(df_lig$ligand_outcome) +#df_lig$ligand_outcome = as.factor(df_lig$ligand_outcome) # check table(df_lig$mutation_info) #======================================================================== - - #=========== # Data: ps #=========== @@ -155,8 +153,16 @@ str(df_lf_ps) # assign pretty labels: param_type levels(df_lf_ps$param_type); table(df_lf_ps$param_type) -levels(df_lf_ps$param_type)[levels(df_lf_ps$param_type)=="duet_scaled"] <- "DUET" -levels(df_lf_ps$param_type)[levels(df_lf_ps$param_type)=="ligand_distance"] <- "Ligand Distance" +ligand_dist_colname = paste0("Distance to ligand (", angstroms_symbol, ")") +ligand_dist_colname + +duet_stability_name = paste0(delta_symbol, delta_symbol, "G") +duet_stability_name + +#levels(df_lf_ps$param_type)[levels(df_lf_ps$param_type)=="duet_scaled"] <- "Stability" +levels(df_lf_ps$param_type)[levels(df_lf_ps$param_type)=="duet_scaled"] <- duet_stability_name +#levels(df_lf_ps$param_type)[levels(df_lf_ps$param_type)=="ligand_distance"] <- "Ligand Distance" +levels(df_lf_ps$param_type)[levels(df_lf_ps$param_type)=="ligand_distance"] <- ligand_dist_colname levels(df_lf_ps$param_type)[levels(df_lf_ps$param_type)=="asa"] <- "ASA" levels(df_lf_ps$param_type)[levels(df_lf_ps$param_type)=="rsa"] <- "RSA" levels(df_lf_ps$param_type)[levels(df_lf_ps$param_type)=="rd_values"] <- "RD" @@ -183,7 +189,7 @@ cols_to_select_lig = c("mutationinformation", "mutation", "position", "mutation_ , "ligand_outcome" , "affinity_scaled" - , "ligand_distance" + #, "ligand_distance" , "asa" , "rsa" , "rd_values" @@ -210,7 +216,7 @@ if (nrow(df_lf_lig) == expected_rows_lf_lig){ levels(df_lf_lig$param_type); table(df_lf_lig$param_type) levels(df_lf_lig$param_type)[levels(df_lf_lig$param_type)=="affinity_scaled"] <- "Ligand Affinity" -levels(df_lf_lig$param_type)[levels(df_lf_lig$param_type)=="ligand_distance"] <- "Ligand Distance" +#levels(df_lf_lig$param_type)[levels(df_lf_lig$param_type)=="ligand_distance"] <- "Ligand Distance" levels(df_lf_lig$param_type)[levels(df_lf_lig$param_type)=="asa"] <- "ASA" levels(df_lf_lig$param_type)[levels(df_lf_lig$param_type)=="rsa"] <- "RSA" levels(df_lf_lig$param_type)[levels(df_lf_lig$param_type)=="rd_values"] <- "RD" @@ -260,10 +266,14 @@ if (nrow(df_lf_foldx) == expected_rows_lf_foldx){ exit() } +foldx_stability_name = paste0(delta_symbol, delta_symbol, "G") +foldx_stability_name + # assign pretty labels: param type levels(df_lf_foldx$param_type); table(df_lf_foldx$param_type) -levels(df_lf_foldx$param_type)[levels(df_lf_foldx$param_type)=="foldx_scaled"] <- "Foldx" +#levels(df_lf_foldx$param_type)[levels(df_lf_foldx$param_type)=="foldx_scaled"] <- "Stability" +levels(df_lf_foldx$param_type)[levels(df_lf_foldx$param_type)=="foldx_scaled"] <- foldx_stability_name #levels(df_lf_foldx$param_type)[levels(df_lf_foldx$param_type)=="ligand_distance"] <- "Ligand Distance" #levels(df_lf_foldx$param_type)[levels(df_lf_foldx$param_type)=="asa"] <- "ASA" #levels(df_lf_foldx$param_type)[levels(df_lf_foldx$param_type)=="rsa"] <- "RSA" diff --git a/scripts/plotting/plotting_data.R b/scripts/plotting/plotting_data.R index 6d907f1..9ecc2a7 100755 --- a/scripts/plotting/plotting_data.R +++ b/scripts/plotting/plotting_data.R @@ -97,6 +97,8 @@ my_df_u_lig = my_df_u[my_df_u$ligand_distance <10,] angstroms_symbol = "\u212b" cat(paste0("There are ", nrow(my_df_u_lig), " sites lying within 10", angstroms_symbol, " of the ligand\n")) +delta_symbol = "\u0394"; delta_symbol + ######################################################################## # end of data extraction and cleaning for plots # ########################################################################