fix many plot functions to stop them using the "g=ggplot()" pattern,
which annoyingly throws away lots of useful data that RShiny needs for clickable plots. Also split the "flame bar" for ligand distance out into separate functions in generate_distance_colour_map.R. This can now be easily incorporated into any "wide" graph showing all positions.
This commit is contained in:
parent
e498d46f8b
commit
bdbc97c40a
8 changed files with 1323 additions and 725 deletions
|
@ -1,5 +1,5 @@
|
|||
# Input:
|
||||
# Data:
|
||||
# Data:
|
||||
# plot_df: merged_df3 containing the OR column to use as y-axis or any other relevant column
|
||||
|
||||
# x_axis_colname = "position"
|
||||
|
@ -7,19 +7,19 @@
|
|||
# symbol_colname = "mutant_type"
|
||||
# y_axis_log = F
|
||||
# log_value = log10
|
||||
# if used, y-axis label has "Log" appended to it
|
||||
# if used, y-axis label has "Log" appended to it
|
||||
|
||||
# my_logo_col = c("chemistry", "hydrophobicity", "clustalx", "taylor")
|
||||
# --> if clustalx and taylor, set variable to black bg + white font
|
||||
# --> if chemistry and hydrophobicity, then grey bg + black font
|
||||
# --> if clustalx and taylor, set variable to black bg + white font
|
||||
# --> if chemistry and hydrophobicity, then grey bg + black font
|
||||
|
||||
# rm_empty_y = F
|
||||
# option to remove empty positions i.e positions with no assocaited y-val
|
||||
# option to remove empty positions i.e positions with no assocaited y-val
|
||||
|
||||
# y_axis_log = F
|
||||
# option to use log scale
|
||||
# FIXME Minor bug: if used with rm_empty_y, sometimes the labels are too small to render(!?)
|
||||
# so positions appear empty despite having y-vals
|
||||
# option to use log scale
|
||||
# FIXME Minor bug: if used with rm_empty_y, sometimes the labels are too small to render(!?)
|
||||
# so positions appear empty despite having y-vals
|
||||
|
||||
# ...other params
|
||||
|
||||
|
@ -39,48 +39,52 @@
|
|||
# logo data: OR
|
||||
#==================
|
||||
LogoPlotCustomH <- function(plot_df
|
||||
, x_axis_colname = "position"
|
||||
, y_axis_colname = "or_mychisq"
|
||||
, symbol_colname = "mutant_type"
|
||||
, my_logo_col = "chemistry"
|
||||
, rm_empty_y = F
|
||||
, y_axis_log = F
|
||||
, log_value = log10
|
||||
, y_axis_increment = 5
|
||||
, 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
|
||||
)
|
||||
, x_axis_colname = "position"
|
||||
, y_axis_colname = "or_mychisq"
|
||||
, symbol_colname = "mutant_type"
|
||||
, my_logo_col = "chemistry"
|
||||
, rm_empty_y = F
|
||||
, y_axis_log = F
|
||||
, log_value = log10
|
||||
, y_axis_increment = 5
|
||||
, 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
|
||||
, tpos0 = 0 # 0 is a magic number that does my sensible default
|
||||
, tW0 = 1
|
||||
, tH0 = 0.3
|
||||
)
|
||||
|
||||
{
|
||||
#################################
|
||||
# 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){
|
||||
#################################
|
||||
# Data processing for logo plot
|
||||
#################################
|
||||
plot_df = generate_distance_colour_map(plot_df, yvar_colname = y_axis_colname, debug=TRUE)
|
||||
|
||||
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])
|
||||
|
@ -95,8 +99,8 @@ LogoPlotCustomH <- function(plot_df
|
|||
|
||||
#y_lim = round_any(y_max, y_axis_increment, f = ceiling)
|
||||
|
||||
} else {
|
||||
|
||||
} else {
|
||||
|
||||
#-------------------
|
||||
# logo data: OR
|
||||
#-------------------
|
||||
|
@ -105,7 +109,7 @@ LogoPlotCustomH <- function(plot_df
|
|||
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]
|
||||
|
@ -116,7 +120,7 @@ LogoPlotCustomH <- function(plot_df
|
|||
|
||||
colnames(logo_dfP_wf)
|
||||
position_or = as.numeric(colnames(logo_dfP_wf))
|
||||
|
||||
|
||||
######################################
|
||||
# Generating plots with given y_axis
|
||||
#####################################
|
||||
|
@ -130,7 +134,7 @@ LogoPlotCustomH <- function(plot_df
|
|||
xtt_col = "white"
|
||||
ytt_col = "white"
|
||||
}
|
||||
|
||||
|
||||
if (my_logo_col %in% c('chemistry', 'hydrophobicity')) {
|
||||
cat('\nSelected colour scheme:', my_logo_col
|
||||
, "\nUsing grey theme")
|
||||
|
@ -141,57 +145,60 @@ LogoPlotCustomH <- function(plot_df
|
|||
xtt_col = "black"
|
||||
ytt_col = "black"
|
||||
}
|
||||
|
||||
p0 = ggseqlogo(logo_dfP_wf
|
||||
, method = "custom"
|
||||
, col_scheme = my_logo_col
|
||||
, seq_type = "aa") +
|
||||
|
||||
if (y_axis_log){
|
||||
|
||||
if (grepl("Log", y_lab)){
|
||||
y_lab = y_lab
|
||||
|
||||
}else{
|
||||
y_lab = paste("Log", y_lab)
|
||||
}
|
||||
}
|
||||
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
|
||||
, 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
|
||||
, axis.title.y = element_text(size = y_tts
|
||||
, colour = ytt_col)
|
||||
, legend.title = element_text(size = leg_tts
|
||||
, legend.title = element_text(size = leg_tts
|
||||
, colour = ytt_col)
|
||||
, legend.text = element_text(size = leg_ts)
|
||||
, legend.text = element_text(size = leg_ts)
|
||||
|
||||
, legend.position = leg_pos
|
||||
, legend.direction = leg_dir
|
||||
, plot.background = element_rect(fill = theme_bgc))+
|
||||
, 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
|
||||
, limits = factor(1:length(position_or))) +
|
||||
|
||||
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)
|
||||
, limits = c(0, y_lim)) +
|
||||
ylab(y_lab) +
|
||||
geom_tile(aes(plot_df$position, tpos0 # heat-mapped distance tiles along the bot
|
||||
, width = tW0
|
||||
, height = tH0)
|
||||
, fill = plot_df$ligD_colours
|
||||
, colour = plot_df$ligD_colours
|
||||
, linetype = "blank")
|
||||
#LogoPlot = p0 + ylab(y_lab)
|
||||
#return(LogoPlot)
|
||||
|
||||
}
|
||||
|
||||
|
||||
return(LogoPlot)
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue