#logo plots # create functions # one with OR # --> select/drop down option to remove empty positions # --> easy peasy, just select the merged_df3_comp # --> select/drop down option for colour # --> if clustalx and taylor, set variable to black bg + white font # --> if chemistry and hydrophobicity, then grey bg + black font # --> select/drop down option for log scale # --> should include WT # one for multiple muts # --> select/drop down option to filter count of nsSNPs # --> select/drop down option for colour # --> should include WT # Data used #wide_df_or # or logo plot #wide_df_or_mult # > 1 sites #wide_df_logor_m #make it as a scale option. REDUNDANT #tab_mt # mutant logo plot #tab_wt # wt logo plot # Make it hover over position and then get the corresponding data table! #%%====================================================================== #================== # logo data: OR #================== # NOTE: my_logo_col # Can be one of these: 'chemistry', 'hydrophobicity', 'clustalx', 'taylor' # if 'chemistry' or 'hydrophobicity' --> then bg is grey with black font (x, y and labels) # if 'clustalx'or 'taylor' --> then bg is black with white font (x, y and labels) #, theme_bgc = #, xfont_bgc = #, yfont_bgc = #, xtt_col = #, ytt_col = # ADD legend for hydrophobicity: done # ADD option to remove empty positions LogoPlotCustomH <- function(plot_df , x_axis_colname = "position" , y_axis_colname = "or_mychisq" , symbol_colname = "mutant_type" , y_axis_log = F , log_value = log10 , y_axis_increment = 5 , rm_empty_y = F , my_logo_col = "chemistry" , x_lab = "Position" , y_lab = "Odds Ratio" , x_ats = 12 # text size , x_tangle = 90 # text angle , y_ats = 22 , y_tangle = 0 , x_tts = 20 # title size , y_tts = 23 , leg_pos = "none" # can be top, left, right and bottom or c(0.8, 0.9) , leg_dir = "horizontal" #can be vertical or horizontal , leg_ts = 15 # leg text size , leg_tts = 16 # leg title size ) { ################################# # Data processing for logo plot ################################# if (rm_empty_y){ plot_df = plot_df[!is.na(plot_df[y_axis_colname]),] cat("\nRemoving empty positions...\n") }else{ plot_df = plot_df } y_max = max(plot_df['or_mychisq'], na.rm = T) cat("\nRemoving y scale incremenet:", y_axis_increment) y_lim = round_any(y_max, y_axis_increment, f = ceiling) #------------------- # 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)] logo_df_plot = logo_df[, c(x_axis_colname, symbol_colname, log_colname)] logo_dfP_wf = as.matrix(logo_df_plot %>% spread(x_axis_colname, log_colname, fill = 0.0)) #!!! For consideration: to add y_axis 'breaks' and 'limits' !!! #y_max = max(plot_df[[log_colname]], na.rm = T) #y_axis_increment = #cat("\nRemoving y scale incremenet:", y_axis_increment) #y_lim = round_any(y_max, y_axis_increment, f = ceiling) } 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)) } class(logo_dfP_wf) rownames(logo_dfP_wf) = logo_dfP_wf[,1] dim(logo_dfP_wf) logo_dfP_wf = logo_dfP_wf[,-1] str(logo_dfP_wf) colnames(logo_dfP_wf) position_or = as.numeric(colnames(logo_dfP_wf)) ###################################### # Generating plots with given y_axis ##################################### 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" xtt_col = "white" ytt_col = "white" } 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" xtt_col = "black" ytt_col = "black" } p0 = ggseqlogo(logo_dfP_wf , method = "custom" , col_scheme = my_logo_col , seq_type = "aa") + #ylab("my custom height") + theme(axis.text.x = element_text(size = x_ats , angle = x_tangle , hjust = 1 , vjust = 0.4 , colour = xfont_bgc) , axis.text.y = element_text(size = y_ats , angle = y_tangle , hjust = 1 , vjust = 0 , colour = yfont_bgc) , axis.title.x = element_text(size = x_tts , colour = xtt_col) , axis.title.y = element_text(size = y_tts , colour = ytt_col) , legend.title = element_text(size = leg_tts , colour = ytt_col) , legend.text = element_text(size = leg_ts) , legend.position = leg_pos , legend.direction = leg_dir , plot.background = element_rect(fill = theme_bgc))+ scale_x_discrete(x_lab #, breaks , labels = position_or , limits = factor(1:length(position_or))) LogoPlot = p0 + scale_y_continuous(y_lab , breaks = seq(0, (y_lim), by = y_axis_increment) #, labels = seq(0, (y_lim), by = y_axis_increment) , limits = c(0, y_lim)) if (y_axis_log){ if (grepl("Log", y_lab)){ y_lab = y_lab }else{ y_lab = paste("Log", y_lab) } LogoPlot = p0 + ylab(y_lab) } return(LogoPlot) }