diff --git a/scripts/functions/wideP_consurf.R b/scripts/functions/wideP_consurf.R index 31c7ab0..8a37cd1 100644 --- a/scripts/functions/wideP_consurf.R +++ b/scripts/functions/wideP_consurf.R @@ -17,6 +17,7 @@ wideP_consurf2 <- function(plot_df , aa_pos_lig1 = NULL , aa_pos_lig2 = NULL , aa_pos_lig3 = NULL + , active_aa_pos = NULL , xvar_colname = "position" , yvar_colname = "consurf_score" @@ -70,10 +71,9 @@ wideP_consurf2 <- function(plot_df , tH0 = 0.3 # Custom 3: x-axis: geom tiles ~ active sites and ligand - , annotate_active_sites = F + , annotate_active_sites = T , drug_aa_colour = "purple" - , active_aa_pos = NULL , active_aa_colour = "brown" , aa_colour_lig1 = "blue" @@ -86,6 +86,7 @@ wideP_consurf2 <- function(plot_df , tpos3 = 0 , default_gt_clr = "white" + , build_plot_df=FALSE , debug=FALSE ){ @@ -181,47 +182,60 @@ wideP_consurf2 <- function(plot_df # Build Data with colours # ~ on active sites #========================== + aa_colour_colname = "bg_all" + aa_colour_colname1 = "col_bg1" + aa_colour_colname2 = "col_bg2" + aa_colour_colname3 = "col_bg3" - if(annotate_active_sites) { - cat("\nAnnotation for xvar requested. Building colours for annotation...") - - aa_colour_colname = "bg_all" - aa_colour_colname1 = "col_bg1" - aa_colour_colname2 = "col_bg2" - aa_colour_colname3 = "col_bg3" - - #-------------------------------------------------- - # column colour 0: Active site + drug binding sites - #-------------------------------------------------- - plot_df[[aa_colour_colname]] = ifelse(plot_df[[xvar_colname]]%in%aa_pos_drug - , drug_aa_colour - , ifelse(plot_df[[xvar_colname]]%in%active_aa_pos - , active_aa_colour, default_gt_clr )) - plot_df[[aa_colour_colname]] - cat("\nColumn created 'bg_all':", length(plot_df[[aa_colour_colname]])) - - #------------------------------------------------ - # column colour 1: Ligand 1 + drug binding sites - #------------------------------------------------ - cat("\nAssigning colours to drug binding and ligand-1 binding residues") - plot_df[[aa_colour_colname1]] = plot_df[[aa_colour_colname]] - plot_df[[aa_colour_colname1]] = ifelse(plot_df[[xvar_colname]]%in%aa_pos_lig1 - , aa_colour_lig1, plot_df[[aa_colour_colname]]) - #------------------------------------------------ - # column colour 2: Ligand 2 - #------------------------------------------------ - plot_df[[aa_colour_colname2]] = plot_df[[aa_colour_colname1]] - plot_df[[aa_colour_colname2]] = ifelse(plot_df[[xvar_colname]]%in%aa_pos_lig2 - , aa_colour_lig2, plot_df[[aa_colour_colname1]]) - - #------------------------------------------------ - # column colour 3: Ligand 3 - #------------------------------------------------ - plot_df[[aa_colour_colname3]] = plot_df[[aa_colour_colname2]] - plot_df[[aa_colour_colname3]] = ifelse(plot_df[[xvar_colname]]%in%aa_pos_lig3 - , aa_colour_lig3, plot_df[[aa_colour_colname2]]) - - } + if (build_plot_df) { + if(annotate_active_sites) { + cat("\nAnnotation for xvar requested. Building colours for annotation...") + + + #-------------------------------------------------- + # column colour 0: Active site + drug binding sites + #-------------------------------------------------- + plot_df[[aa_colour_colname]] = ifelse(plot_df[[xvar_colname]]%in%aa_pos_drug + , drug_aa_colour + , ifelse(plot_df[[xvar_colname]]%in%active_aa_pos + , active_aa_colour, default_gt_clr )) + plot_df[[aa_colour_colname]] + cat("\nColumn created 'bg_all':", length(plot_df[[aa_colour_colname]])) + + #------------------------------------------------ + # column colour 1: Ligand 1 + drug binding sites + #------------------------------------------------ + cat("\nAssigning colours to drug binding and ligand-1 binding residues") + plot_df[[aa_colour_colname1]] = plot_df[[aa_colour_colname]] + plot_df[[aa_colour_colname1]] = ifelse(plot_df[[xvar_colname]]%in%aa_pos_lig1 + , aa_colour_lig1, plot_df[[aa_colour_colname]]) + #------------------------------------------------ + # column colour 2: Ligand 2 + #------------------------------------------------ + plot_df[[aa_colour_colname2]] = plot_df[[aa_colour_colname1]] + plot_df[[aa_colour_colname2]] = ifelse(plot_df[[xvar_colname]]%in%aa_pos_lig2 + , aa_colour_lig2, plot_df[[aa_colour_colname1]]) + + #------------------------------------------------ + # column colour 3: Ligand 3 + #------------------------------------------------ + plot_df[[aa_colour_colname3]] = plot_df[[aa_colour_colname2]] + plot_df[[aa_colour_colname3]] = ifelse(plot_df[[xvar_colname]]%in%aa_pos_lig3 + , aa_colour_lig3, plot_df[[aa_colour_colname2]]) + + } + } else { + # set these to the string "DUMMY" so that the build-up-the-tiles bit works + aa_pos_drug = "DUMMY" + aa_pos_lig1 = "DUMMY" + active_aa_pos = "DUMMY" + if (aa_colour_colname2 %in% colnames(merged_df3)) { + aa_pos_lig2 = "DUMMY" + if (aa_colour_colname3 %in% colnames(merged_df3)) { + aa_pos_lig2 = "DUMMY" + } + } + } ################### # start plot ################### @@ -456,7 +470,7 @@ wideP_consurf2 <- function(plot_df cat("\nDone Plot with 1 ligand") - } else {cat("\n3 Lig Plot condition FAIL")} + } else {cat("\n1 Lig Plot condition FAIL")} #----------------------------------- # Add2plot:NO ligands