refactoring logo plots to add flame bar
This commit is contained in:
parent
f0a9eb4eec
commit
c968089cd2
4 changed files with 194 additions and 196 deletions
|
@ -33,7 +33,7 @@
|
|||
LogoPlotSnps <- function(plot_df
|
||||
, x_axis_colname = "position"
|
||||
, symbol_mut_colname = "mutant_type"
|
||||
, symbol_wt_colname = "mutant_type"
|
||||
, symbol_wt_colname = "wild_type"
|
||||
, omit_snp_count = c(0) # can be 1, 2, etc.
|
||||
, my_logo_col = "chemistry"
|
||||
, x_lab = "Position"
|
||||
|
@ -66,11 +66,18 @@ LogoPlotSnps <- function(plot_df
|
|||
|
||||
# Generate "ligand distance" colour map
|
||||
plot_df = generate_distance_colour_map(plot_df, debug=TRUE)
|
||||
unique_colour_map = unique(plot_df[,c("position","ligD_colours")])
|
||||
unique_colour_map = unique_colour_map[order(unique_colour_map$position), ]
|
||||
rownames(unique_colour_map) = unique_colour_map$position
|
||||
unique_colour_map2 = unique_colour_map
|
||||
unique_colour_map2$position=as.factor(unique_colour_map2$position)
|
||||
unique_colour_map2$ligD_colours = as.factor(unique_colour_map2$ligD_colours)
|
||||
#
|
||||
|
||||
setDT(plot_df)[, mut_pos_occurrence := .N, by = .(eval(parse(text=x_axis_colname)))]
|
||||
if (debug) {
|
||||
table(plot_df[[x_axis_colname]])
|
||||
table(plot_df$mut_pos_occurrence)
|
||||
table(plot_df[[x_axis_colname]])
|
||||
table(plot_df$mut_pos_occurrence)
|
||||
}
|
||||
max_mut = max(table(plot_df[[x_axis_colname]]))
|
||||
|
||||
|
@ -200,7 +207,7 @@ LogoPlotSnps <- function(plot_df
|
|||
xtt_col = "black"
|
||||
ytt_col = "black"
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
# Generating logo plots for nsSNPs
|
||||
#####################################
|
||||
|
@ -212,11 +219,7 @@ LogoPlotSnps <- function(plot_df
|
|||
, method = 'custom'
|
||||
, col_scheme = my_logo_col
|
||||
, seq_type = 'aa') +
|
||||
|
||||
theme(text=element_text(family="FreeSans"))+
|
||||
theme(axis.text.x = element_blank()) +
|
||||
theme_logo()+
|
||||
|
||||
|
||||
scale_x_continuous(breaks = 1:ncol(tab_mt)
|
||||
, expand = c(0.01,0)
|
||||
, labels = colnames(tab_mt))+
|
||||
|
@ -224,16 +227,9 @@ LogoPlotSnps <- function(plot_df
|
|||
scale_y_continuous(breaks = 0:(max_mult_mut-1)
|
||||
, labels = c(1:max_mult_mut)
|
||||
, limits = c(0, max_mult_mut)) +
|
||||
# FIXME: currently broken, possibly due to ggseqlogo() not working in the
|
||||
# way standard ggplot2() does
|
||||
geom_tile(aes(plot_df$position, tpos0 # heat-mapped distance tiles along the bottom.
|
||||
, width = tW0
|
||||
, height = tH0)
|
||||
, fill = plot_df$ligD_colours
|
||||
, colour = plot_df$ligD_colours
|
||||
, linetype = "blank") +
|
||||
ylab(y_lab) +
|
||||
theme(legend.position = leg_pos
|
||||
theme(text=element_text(family="FreeSans")
|
||||
, legend.position = leg_pos
|
||||
, legend.direction = leg_dir
|
||||
, legend.title = element_text(size = leg_tts
|
||||
, colour = ytt_col)
|
||||
|
@ -260,40 +256,58 @@ LogoPlotSnps <- function(plot_df
|
|||
, method = 'custom'
|
||||
, col_scheme = my_logo_col
|
||||
, seq_type = 'aa') +
|
||||
|
||||
theme(text = element_text(family="FreeSans"))+
|
||||
theme(axis.text.x = element_blank()
|
||||
, axis.text.y = element_blank()) +
|
||||
theme_logo()+
|
||||
|
||||
scale_x_continuous(breaks = 1:ncol(tab_wt)
|
||||
, expand = c(0.01,0)
|
||||
, labels = colnames(tab_wt))+
|
||||
|
||||
xlab(x_lab) +
|
||||
|
||||
theme(legend.position = "none"
|
||||
, legend.direction = leg_dir
|
||||
#, legend.title = element_blank()
|
||||
, legend.title = element_text(size = y_tts
|
||||
, colour = ytt_col)
|
||||
, legend.text = element_text(size = leg_ts)
|
||||
, axis.text.x = element_text(size = x_ats
|
||||
, angle = x_tangle
|
||||
, hjust = 1
|
||||
, vjust = 0.4
|
||||
, colour = xfont_bgc)
|
||||
theme(text = element_text(family="FreeSans")
|
||||
, legend.position = "none"
|
||||
, axis.text.x = element_blank()
|
||||
, axis.text.y = element_blank()
|
||||
, axis.title.x = element_blank()
|
||||
, axis.title.y = element_blank()
|
||||
, plot.background = element_rect(fill = theme_bgc)
|
||||
) +
|
||||
labs(x=NULL, y=NULL)
|
||||
,
|
||||
ggplot(data=unique_colour_map2, aes(
|
||||
x=factor(position), 0 # heat-mapped distance tiles along the bot
|
||||
, fill = position
|
||||
, colour = position
|
||||
, linetype = "blank"
|
||||
)
|
||||
) +
|
||||
geom_tile() +
|
||||
theme(axis.text.x = element_text(size = x_ats
|
||||
, angle = x_tangle
|
||||
, hjust = 1
|
||||
, vjust = 0.4
|
||||
, colour = xfont_bgc)
|
||||
, axis.text.y = element_blank()
|
||||
, axis.ticks.y = element_blank()
|
||||
, 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)
|
||||
)
|
||||
, nrow = 2
|
||||
, plot.margin = margin(t=0)
|
||||
, panel.grid=element_blank()
|
||||
, panel.background = element_rect(fill = theme_bgc)
|
||||
) +
|
||||
scale_x_discrete(x_lab, labels=factor(unique_colour_map$position)) +
|
||||
scale_color_manual(values=unique_colour_map$ligD_colours) +
|
||||
scale_fill_manual(values=unique_colour_map$ligD_colours) +
|
||||
labs(y = NULL)
|
||||
, nrow = 3
|
||||
, align = "v"
|
||||
, rel_heights = c(3/4, 1/4))
|
||||
, rel_heights = c(7/10, 2/7, 1/7))
|
||||
#------------------
|
||||
# Wild logo plot
|
||||
#------------------
|
||||
}
|
||||
#LogoPlotSnps(mutable_df3)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue