167 lines
5.7 KiB
R
167 lines
5.7 KiB
R
#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
|
|
, my_logo_col = "chemistry"
|
|
, x_lab = "Position"
|
|
, y_lab = "Odds Ratio"
|
|
, x_ats = 12 # text size
|
|
, x_tangle = 90 # text angle
|
|
#, theme_bgc
|
|
#, xfont_bgc
|
|
#, yfont_bgc
|
|
, y_ats = 22
|
|
, y_tangle = 0
|
|
, x_tts = 20 # title size
|
|
, y_tts = 23
|
|
#, xtt_col =
|
|
#, ytt_col =
|
|
, 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 (y_axis_log){
|
|
|
|
#=====================
|
|
# logo data: LogOR
|
|
#=====================
|
|
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))
|
|
|
|
} 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 == '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"
|
|
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"
|
|
}
|
|
|
|
LogoPlot = 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.position = leg_pos
|
|
, legend.direction = leg_dir
|
|
, plot.background = element_rect(fill = theme_bgc))+
|
|
#, legend.text = element_text(size = leg_ts)
|
|
#, legend.title = element_text(size = leg_tts))+
|
|
scale_x_discrete(x_lab
|
|
#, breaks
|
|
, labels = position_or
|
|
, limits = factor(1:length(position_or))) +
|
|
ylab(y_lab)
|
|
|
|
return(LogoPlot)
|
|
|
|
}
|
|
|
|
|