various usability tweaks to LogoPlotMSA and position_annotation
This commit is contained in:
parent
f949592dd8
commit
1241ad0b22
4 changed files with 197 additions and 130 deletions
|
@ -4,6 +4,7 @@
|
|||
position_annotation=function(plot_df,
|
||||
bg="transparent",
|
||||
reorder_position = FALSE, # enable to reorder according to plot_df$pos_count
|
||||
generate_colours = TRUE, #set FALSE if you want to generate all the colour columns elsewhere
|
||||
aa_pos_drug=1:100,
|
||||
active_aa_pos=1:100,
|
||||
aa_pos_lig1=1:100,
|
||||
|
@ -32,36 +33,38 @@ position_annotation=function(plot_df,
|
|||
#plot_df = generate_distance_colour_map(plot_df, debug=TRUE)
|
||||
# plot_df$col_aa = ifelse(plot_df[["position"]]%in%active_aa_pos,
|
||||
# "brown", "transparent")
|
||||
plot_df$col_aa = ifelse(plot_df[["position"]]%in%active_aa_pos,
|
||||
"transparent", "transparent")
|
||||
|
||||
plot_df$bg_all = plot_df$col_aa
|
||||
plot_df$bg_all = ifelse(plot_df[["position"]]%in%aa_pos_drug,
|
||||
"drug", plot_df$bg_all)
|
||||
|
||||
plot_df$col_bg1 = plot_df$bg_all
|
||||
plot_df$col_bg1 = ifelse(plot_df[["position"]]%in%aa_pos_lig1,
|
||||
"lig1", plot_df$col_bg1)
|
||||
|
||||
plot_df$col_bg2 = plot_df$col_bg1
|
||||
plot_df$col_bg2 = ifelse(plot_df[["position"]]%in%aa_pos_lig2,
|
||||
"lig2", plot_df$col_bg2)
|
||||
|
||||
|
||||
plot_df$col_bg3 = plot_df$col_bg2
|
||||
plot_df$col_bg3 = ifelse(plot_df[["position"]]%in%aa_pos_lig3
|
||||
, "lig3", plot_df$col_bg3)
|
||||
|
||||
# the call to generate_distance_colour_map should probably be
|
||||
# wherever the outer DF is built, and not here.
|
||||
plot_df = generate_distance_colour_map(plot_df, debug=TRUE)
|
||||
|
||||
if (generate_colours){
|
||||
plot_df$col_aa = ifelse(plot_df[["position"]]%in%active_aa_pos,
|
||||
"transparent", "transparent")
|
||||
|
||||
plot_df$bg_all = plot_df$col_aa
|
||||
plot_df$bg_all = ifelse(plot_df[["position"]]%in%aa_pos_drug,
|
||||
"drug", plot_df$bg_all)
|
||||
|
||||
plot_df$col_bg1 = plot_df$bg_all
|
||||
plot_df$col_bg1 = ifelse(plot_df[["position"]]%in%aa_pos_lig1,
|
||||
"lig1", plot_df$col_bg1)
|
||||
|
||||
plot_df$col_bg2 = plot_df$col_bg1
|
||||
plot_df$col_bg2 = ifelse(plot_df[["position"]]%in%aa_pos_lig2,
|
||||
"lig2", plot_df$col_bg2)
|
||||
|
||||
|
||||
plot_df$col_bg3 = plot_df$col_bg2
|
||||
plot_df$col_bg3 = ifelse(plot_df[["position"]]%in%aa_pos_lig3
|
||||
, "lig3", plot_df$col_bg3)
|
||||
|
||||
# the call to generate_distance_colour_map should probably be
|
||||
# wherever the outer DF is built, and not here.
|
||||
plot_df = generate_distance_colour_map(plot_df, debug=TRUE)
|
||||
}
|
||||
heat_bar = ggplot(plot_df) + # THIS STUPID FUCKING FACTOR THING
|
||||
|
||||
# scale_x_discrete("Position", labels=factor(plot_df$position)) +
|
||||
theme_nothing() +
|
||||
theme(#axis.text.x = element_text(angle = 90, size = 6),
|
||||
title = element_blank()
|
||||
title = element_blank()
|
||||
) + # enable for alignment debug
|
||||
labs(x = NULL, y = NULL) +
|
||||
|
||||
|
@ -77,87 +80,87 @@ position_annotation=function(plot_df,
|
|||
}
|
||||
#end of distance-heat-bar
|
||||
#NULL,
|
||||
if(reorder_position) {
|
||||
pos_tiles = ggplot(plot_df) +
|
||||
#scale_x_discrete("Position", labels=factor(plot_df$position)) +
|
||||
scale_color_manual(values = c(
|
||||
"brown"="brown",
|
||||
"drug"=drug_colour,
|
||||
"transparent"="transparent",
|
||||
"lig1"=lig1_colour,
|
||||
"lig2"=lig2_colour,
|
||||
"lig3"=lig3_colour
|
||||
),
|
||||
#expand=c(0,0)
|
||||
) +
|
||||
scale_fill_manual(values = c(
|
||||
"brown"="brown",
|
||||
"drug"=drug_colour,
|
||||
"transparent"="transparent",
|
||||
"lig1"=lig1_colour,
|
||||
"lig2"=lig2_colour,
|
||||
"lig3"=lig3_colour
|
||||
),
|
||||
#expand=c(0,0)
|
||||
) +
|
||||
theme_nothing() +
|
||||
theme(plot.background = element_rect(fill = bg, colour=NA),
|
||||
#plot.margin = margin(t=0,b=0),
|
||||
panel.background = element_rect(fill = bg, colour=NA),
|
||||
legend.position = "none"
|
||||
) +
|
||||
labs(x = NULL, y= NULL) +
|
||||
if(reorder_position) {
|
||||
pos_tiles = ggplot(plot_df) +
|
||||
#scale_x_discrete("Position", labels=factor(plot_df$position)) +
|
||||
scale_color_manual(values = c(
|
||||
"brown"="brown",
|
||||
"drug"=drug_colour,
|
||||
"transparent"="transparent",
|
||||
"lig1"=lig1_colour,
|
||||
"lig2"=lig2_colour,
|
||||
"lig3"=lig3_colour
|
||||
),
|
||||
#expand=c(0,0)
|
||||
) +
|
||||
scale_fill_manual(values = c(
|
||||
"brown"="brown",
|
||||
"drug"=drug_colour,
|
||||
"transparent"="transparent",
|
||||
"lig1"=lig1_colour,
|
||||
"lig2"=lig2_colour,
|
||||
"lig3"=lig3_colour
|
||||
),
|
||||
#expand=c(0,0)
|
||||
) +
|
||||
theme_nothing() +
|
||||
theme(plot.background = element_rect(fill = bg, colour=NA),
|
||||
#plot.margin = margin(t=0,b=0),
|
||||
panel.background = element_rect(fill = bg, colour=NA),
|
||||
legend.position = "none"
|
||||
) +
|
||||
labs(x = NULL, y= NULL) +
|
||||
geom_tile(aes(y = 1,x=reorder(position,-pos_count), fill = bg_all, colour = bg_all)
|
||||
) +
|
||||
geom_tile(aes(y = 2, x=reorder(position,-pos_count), fill = col_bg1, colour = col_bg1)
|
||||
) +
|
||||
geom_tile(aes(y = 3, x=reorder(position,-pos_count), fill = col_bg2, colour = col_bg2)
|
||||
) +
|
||||
geom_tile(aes(y = 4, x=reorder(position,-pos_count), fill = col_bg3, colour = col_bg3)
|
||||
)
|
||||
|
||||
} else {
|
||||
pos_tiles = ggplot(plot_df) +
|
||||
#scale_x_discrete("Position", labels=factor(plot_df$position)) +
|
||||
scale_color_manual(values = c(
|
||||
"brown"="brown",
|
||||
"drug"=drug_colour,
|
||||
"transparent"="transparent",
|
||||
"lig1"=lig1_colour,
|
||||
"lig2"=lig2_colour,
|
||||
"lig3"=lig3_colour
|
||||
),
|
||||
#expand=c(0,0)
|
||||
) +
|
||||
scale_fill_manual(values = c(
|
||||
"brown"="brown",
|
||||
"drug"=drug_colour,
|
||||
"transparent"="transparent",
|
||||
"lig1"=lig1_colour,
|
||||
"lig2"=lig2_colour,
|
||||
"lig3"=lig3_colour
|
||||
),
|
||||
#expand=c(0,0)
|
||||
) +
|
||||
theme_nothing() +
|
||||
theme(plot.background = element_rect(fill = bg, colour=NA),
|
||||
#plot.margin = margin(t=0,b=0),
|
||||
panel.background = element_rect(fill = bg, colour=NA),
|
||||
legend.position = "none"
|
||||
) +
|
||||
labs(x = NULL, y= NULL) +
|
||||
geom_tile(aes(y = 2, x=reorder(position,-pos_count), fill = col_bg1, colour = col_bg1)
|
||||
) +
|
||||
geom_tile(aes(y = 3, x=reorder(position,-pos_count), fill = col_bg2, colour = col_bg2)
|
||||
) +
|
||||
geom_tile(aes(y = 4, x=reorder(position,-pos_count), fill = col_bg3, colour = col_bg3)
|
||||
)
|
||||
|
||||
} else {
|
||||
pos_tiles = ggplot(plot_df) +
|
||||
#scale_x_discrete("Position", labels=factor(plot_df$position)) +
|
||||
scale_color_manual(values = c(
|
||||
"brown"="brown",
|
||||
"drug"=drug_colour,
|
||||
"transparent"="transparent",
|
||||
"lig1"=lig1_colour,
|
||||
"lig2"=lig2_colour,
|
||||
"lig3"=lig3_colour
|
||||
),
|
||||
#expand=c(0,0)
|
||||
) +
|
||||
scale_fill_manual(values = c(
|
||||
"brown"="brown",
|
||||
"drug"=drug_colour,
|
||||
"transparent"="transparent",
|
||||
"lig1"=lig1_colour,
|
||||
"lig2"=lig2_colour,
|
||||
"lig3"=lig3_colour
|
||||
),
|
||||
#expand=c(0,0)
|
||||
) +
|
||||
theme_nothing() +
|
||||
theme(plot.background = element_rect(fill = bg, colour=NA),
|
||||
#plot.margin = margin(t=0,b=0),
|
||||
panel.background = element_rect(fill = bg, colour=NA),
|
||||
legend.position = "none"
|
||||
) +
|
||||
labs(x = NULL, y= NULL) +
|
||||
geom_tile(aes(y = 1, x=factor(position), fill = bg_all, colour = bg_all)
|
||||
) +
|
||||
geom_tile(aes(y = 2, x=factor(position), fill = col_bg1, colour = col_bg1)
|
||||
) +
|
||||
geom_tile(aes(y = 3, x=factor(position), fill = col_bg2, colour = col_bg2)
|
||||
) +
|
||||
geom_tile(aes(y = 4, x=factor(position), fill = col_bg3, colour = col_bg3)
|
||||
)
|
||||
}
|
||||
# tile thingies end
|
||||
|
||||
heat_legend=get_legend(heat_bar)
|
||||
geom_tile(aes(y = 2, x=factor(position), fill = col_bg1, colour = col_bg1)
|
||||
) +
|
||||
geom_tile(aes(y = 3, x=factor(position), fill = col_bg2, colour = col_bg2)
|
||||
) +
|
||||
geom_tile(aes(y = 4, x=factor(position), fill = col_bg3, colour = col_bg3)
|
||||
)
|
||||
}
|
||||
# tile thingies end
|
||||
|
||||
heat_legend=get_legend(heat_bar)
|
||||
out_plot=cowplot::plot_grid(
|
||||
heat_bar,
|
||||
NULL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue