From f27b536157d00a4373f92df6596a501bca3952bb Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Fri, 14 Jan 2022 11:07:16 +0000 Subject: [PATCH] added option to remove empty positions from logo plot --- scripts/functions/logo_plots_func.R | 33 +++++++++++-------- .../functions/tests/test_logo_plots_func.R | 3 +- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/scripts/functions/logo_plots_func.R b/scripts/functions/logo_plots_func.R index 3146db4..f28d434 100644 --- a/scripts/functions/logo_plots_func.R +++ b/scripts/functions/logo_plots_func.R @@ -49,6 +49,7 @@ LogoPlotCustomH <- function(plot_df , symbol_colname = "mutant_type" , y_axis_log = F , log_value = log10 + , rm_empty_pos = F , my_logo_col = "chemistry" , x_lab = "Position" , y_lab = "Odds Ratio" @@ -70,14 +71,20 @@ LogoPlotCustomH <- function(plot_df ) { - ################################# - # Data processing for logo plot - ################################# - if (y_axis_log){ - - #===================== + ################################# + # Data processing for logo plot + ################################# + if (rm_empty_pos){ + plot_df = plot_df[!is.na(plot_df[y_axis_colname]),] + cat("\nRemoving empty positions...\n") + }else{ + plot_df = plot_df + } + #------------------- # logo data: LogOR - #===================== + #------------------- + if (y_axis_log){ + log_colname = paste0("log_", y_axis_colname) plot_df[log_colname] = log_value(plot_df[y_axis_colname]) logo_df = plot_df[, c(x_axis_colname, symbol_colname, log_colname)] @@ -86,9 +93,9 @@ LogoPlotCustomH <- function(plot_df } else { - #===================== + #------------------- # logo data: OR - #===================== + #------------------- logo_df = plot_df[, c(x_axis_colname, symbol_colname, y_axis_colname)] logo_df_plot = logo_df[, c(x_axis_colname, symbol_colname, y_axis_colname)] logo_dfP_wf = as.matrix(logo_df_plot %>% spread(x_axis_colname, y_axis_colname, fill = 0.0)) @@ -109,11 +116,10 @@ LogoPlotCustomH <- function(plot_df ###################################### # Generating plots with given y_axis ##################################### - #if (my_logo_col == 'clustalx || taylor'){ - if (my_logo_col %in% c('clustalx','taylor')) { cat("\nSelected colour scheme:", my_logo_col , "\nUsing black theme\n") + theme_bgc = "black" xfont_bgc = "white" yfont_bgc = "white" @@ -124,6 +130,7 @@ LogoPlotCustomH <- function(plot_df if (my_logo_col %in% c('chemistry', 'hydrophobicity')) { cat('\nSelected colour scheme:', my_logo_col , "\nUsing grey theme") + theme_bgc = "grey" xfont_bgc = "black" yfont_bgc = "black" @@ -162,6 +169,4 @@ LogoPlotCustomH <- function(plot_df return(LogoPlot) -} - - +} \ No newline at end of file diff --git a/scripts/functions/tests/test_logo_plots_func.R b/scripts/functions/tests/test_logo_plots_func.R index 391b5e2..b75ca9e 100644 --- a/scripts/functions/tests/test_logo_plots_func.R +++ b/scripts/functions/tests/test_logo_plots_func.R @@ -9,7 +9,8 @@ LogoPlotCustomH (plot_df = merged_df3 , symbol_colname = "mutant_type" , y_axis_log = F , log_value = log10 - , my_logo_col = 'taylor' + , rm_empty_pos = F + , my_logo_col = 'hydrophobicity' , x_lab = "Position" , y_lab = "Odds Ratio" , x_ats = 12 # text size