From c0f59bc9c9aeffd49ae0ff4034a87d139b72b5fd Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Fri, 5 Aug 2022 12:45:16 +0100 Subject: [PATCH] breakage --- scripts/functions/bp_lineage_diversity.R | 40 ++++++++++++++----- scripts/functions/combining_dfs_plotting.R | 23 +++++++++++ scripts/functions/dm_om_data.R | 15 +++++++ scripts/plotting/get_plotting_dfs.R | 1 + .../lineage_barplots_combined.R | 7 +++- 5 files changed, 74 insertions(+), 12 deletions(-) diff --git a/scripts/functions/bp_lineage_diversity.R b/scripts/functions/bp_lineage_diversity.R index cfa1fb6..68617f2 100644 --- a/scripts/functions/bp_lineage_diversity.R +++ b/scripts/functions/bp_lineage_diversity.R @@ -23,14 +23,19 @@ lin_count_bp_diversity <- function( lf_data = lin_wf , my_xals = 22 # x axis label size , my_yals = 22 # y axis label size , my_lls = 22 # legend label size - , bar_col_labels = c("Mutations", "Total Samples") - , bar_col_values = c("grey50", "gray75") + , bar_col_labels = "" #c("Mutations", "Total Samples") + , bar_col_values = c("gray50", "gray75") , bar_leg_name = "" , leg_location = "top" , y_log10 = FALSE , y_scale_percent = FALSE #, y_label = c("Count", "SNP diversity") , y_label = c("SNP diversity") + , bp_plot_title = "" + , title_colour = "chocolate4" + , subtitle_text = NULL + , sts = 20 + , subtitle_colour = "#350E20FF" #brown ) { if(!all_lineages){ lf_data = lf_data[lf_data[[x_categ]]%in%use_lineages,] @@ -58,7 +63,13 @@ lin_count_bp_diversity <- function( lf_data = lin_wf , axis.title.y = element_text(size = my_yals , colour = "black") , legend.position = leg_location - , legend.text = element_text(size = my_lls)) + + , legend.text = element_text(size = my_lls) + , plot.title = element_text(size = my_lls + , colour = title_colour + , hjust = 0.5) + , plot.subtitle = element_text(size = sts + , hjust = 0.5 + , colour = subtitle_colour)) + geom_label(aes(label = eval(parse(text = display_label_col))) , size = d_lab_size @@ -72,10 +83,16 @@ lin_count_bp_diversity <- function( lf_data = lin_wf scale_fill_manual(values = bar_col_values , name = bar_leg_name , labels = bar_col_labels) + - labs(title = "" - , x = "" - , y = y_label - , colour = "black") + # labs(title = "" + # , x = "" + # , y = y_label + # , colour = "black") + # + labs(title = bp_plot_title + , subtitle = subtitle_text + , x = "" + , y = y_label + , colour = "black") if (y_log10){ @@ -90,10 +107,11 @@ lin_count_bp_diversity <- function( lf_data = lin_wf scale_y_continuous(labels = scales::percent_format(accuracy = 1)) + #scale_y_continuous(labels = scales::percent) + - labs(title = "" - , x = "" - , y = y_label - , colour = "black") + labs(title = bp_plot_title + , subtitle = subtitle_text + , x = "" + , y = y_label + , colour = "black") } return(OutPlot) diff --git a/scripts/functions/combining_dfs_plotting.R b/scripts/functions/combining_dfs_plotting.R index 749a7ff..7354bba 100644 --- a/scripts/functions/combining_dfs_plotting.R +++ b/scripts/functions/combining_dfs_plotting.R @@ -343,6 +343,29 @@ combining_dfs_plotting <- function( my_df_u , "\nNo. of rows merged_df3: ", nrow(merged_df3)) quit() } + #--------------------------------------------- + # add columns that are needed to generate plots with revised colnames and strings + #---------------------------------------------- + merged_df3['sensitivity'] = ifelse(merged_df3['dst_mode'] == 1, "R", "S") + merged_df3['mutation_info_labels'] = ifelse(merged_df3['mutation_info_labels'] == "DM", "R", "S") + + merged_df2['sensitivity'] = ifelse(merged_df2['dst_mode'] == 1, "R", "S") + merged_df2['mutation_info_labels'] = ifelse(merged_df2['mutation_info_labels'] == "DM", "R", "S") + + #check1 = all(table(merged_df3["mutation_info_labels"]) == table(merged_df3['sensitivity'])) + #check2 = all(table(merged_df2["mutation_info_labels"]) == table(merged_df2['sensitivity'])) + + check1 = all(merged_df3["mutation_info_labels"] == merged_df3['sensitivity']) + check2 = all(merged_df2["mutation_info_labels"] == merged_df2['sensitivity']) + + if(check1 && check2){ + cat("PASS: merged_df3 and merged_df2 have mutation info labels as R and S" + , "\nIt also has sensitivity column" + , "\nThese are identical") + }else{ + stop("Abort: merged_df3 or merged_df2 can't be created because of lable mismatch") + } + return(list( merged_df2 , merged_df3 )) diff --git a/scripts/functions/dm_om_data.R b/scripts/functions/dm_om_data.R index 7f4a119..96537bf 100644 --- a/scripts/functions/dm_om_data.R +++ b/scripts/functions/dm_om_data.R @@ -37,6 +37,11 @@ #1) df to choose (merged_df3 or merged_df2) #2) ################################################################## +DistCutOff = 10 +LigDist_colname # = "ligand_distance" # from globals +ppi2Dist_colname = "interface_dist" +naDist_colname = "TBC" + dm_om_wf_lf_data <- function(df , gene_name = gene # from globals , colnames_to_extract @@ -51,6 +56,15 @@ dm_om_wf_lf_data <- function(df , dr_other_muts_labels = c("DM", "OM") # only used if ^^ = "" , categ_cols_to_factor){ + df = as.data.frame(df) + + df['sensitivity'] = ifelse(df['dst_mode'] == 1, "R", "S") + table(df['sensitivity']) + + df[[mut_info_label_colname]] = ifelse(df[[mut_info_label_colname]] == "DM", "R", "S") + table(df[[mut_info_label_colname]]) + + # Initialise the required dfs based on gene name geneL_normal = c("pnca") #geneL_na_dy = c("gid") @@ -124,6 +138,7 @@ dm_om_wf_lf_data <- function(df , mut_colname, mut_info_colname, mut_info_label_colname , aa_pos_colname , LigDist_colname + , ppi2Dist_colname, naDist_colname , "duet_stability_change" , "duet_scaled" , "duet_outcome" , "ligand_affinity_change", "affinity_scaled" , "ligand_outcome" , "ddg_foldx" , "foldx_scaled" , "foldx_outcome" diff --git a/scripts/plotting/get_plotting_dfs.R b/scripts/plotting/get_plotting_dfs.R index e546753..de43c74 100644 --- a/scripts/plotting/get_plotting_dfs.R +++ b/scripts/plotting/get_plotting_dfs.R @@ -144,6 +144,7 @@ cat(s3) # location: scripts/functions/corr_plot_data.R #################################################################### # make sure the above script works because merged_df2_combined is needed +merged_df3 = as.data.frame(merged_df3) corr_df_m3_f = corr_data_extract(merged_df3, extract_scaled_cols = F) head(corr_df_m3_f) diff --git a/scripts/plotting/plotting_thesis/lineage_barplots_combined.R b/scripts/plotting/plotting_thesis/lineage_barplots_combined.R index c9defaf..9914f47 100644 --- a/scripts/plotting/plotting_thesis/lineage_barplots_combined.R +++ b/scripts/plotting/plotting_thesis/lineage_barplots_combined.R @@ -48,7 +48,12 @@ lin_diversityP = lin_count_bp_diversity(lf_data = lineage_dfL[['lin_wf']] , y_log10 = F , y_scale_percent = F , leg_location = "top" - , y_label = "SNP diversity") + , y_label = "Percent" #"SNP diversity" + , bp_plot_title = "SNP diversity" + , title_colour = "black" #"chocolate4" + , subtitle_text = NULL + , sts = 20 + , subtitle_colour = "#350E20FF") #============================================= # Output plots: Lineage count and Diversity