# position_annotation takes a Data Frame (df) and returns a ggplot object. # # This plots position tiles for the (up to) three ligands as well as drug position_annotation=function(plot_df, bg="transparent", aa_pos_drug=1:100, active_aa_pos=1:100, aa_pos_lig1=1:100, aa_pos_lig2=1:100, aa_pos_lig3=1:100 ) { x_ats = 12 x_tangle = 90 x_tts = 20 y_tts = 23 xtt_col = "black" ytt_col = "black" leg_dir = "horizontal" leg_ts = 15 leg_tts = 16 leg_pos = "none" # plot_df=plot_df[order(plot_df$ligand_distance),] # # plot_df$position = factor(plot_df$position) #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, "green", plot_df$bg_all) plot_df$col_bg1 = plot_df$bg_all plot_df$col_bg1 = ifelse(plot_df[["position"]]%in%aa_pos_lig1, "slategrey", plot_df$col_bg1) plot_df$col_bg2 = plot_df$col_bg1 plot_df$col_bg2 = ifelse(plot_df[["position"]]%in%aa_pos_lig2, "navyblue", plot_df$col_bg2) plot_df$col_bg3 = plot_df$col_bg2 plot_df$col_bg3 = ifelse(plot_df[["position"]]%in%aa_pos_lig3 , "purple", plot_df$col_bg3) plot_df = generate_distance_colour_map(plot_df, debug=TRUE) cowplot::plot_grid( ggplot(plot_df, aes(x=factor(position), # THIS STUPID FUCKING FACTOR THING ) ) + geom_tile(aes(y=0), fill=plot_df$ligD_colours) + #scale_x_discrete("Position", labels=factor(plot_df$position)) + #theme_nothing() + theme(plot.background = element_rect(fill = "transparent", colour=NA), plot.margin = margin(t=0,b=0), axis.ticks.x = element_blank(), axis.ticks.y = element_blank(), axis.text.y = element_blank(), panel.grid = element_blank(), panel.background = element_rect(fill = "transparent", colour=NA), ) + labs(x = NULL, y = NULL), #end of distance-heat-bar #NULL, ggplot(plot_df, aes(x=factor(position), # THIS STUPID FUCKING FACTOR THING #reorder(ligand_distance) ) ) + # geom_tile(aes(y = 0, fill = col_aa, colour = col_aa) # ) + geom_tile(aes(y = 1, fill = bg_all, colour = bg_all) ) + geom_tile(aes(y = 2, fill = col_bg1, colour = col_bg1) ) + geom_tile(aes(y = 3, fill = col_bg2, colour = col_bg2) ) + geom_tile(aes(y = 4, fill = col_bg3, colour = col_bg3) ) + #scale_x_discrete("Position", labels=factor(plot_df$position)) + scale_color_manual(values = c( "brown"="brown", "green"="#00ff00", "transparent"="transparent", "slategrey"="#2f4f4f", "navyblue"="#000080", "purple"="#a020f0" ), expand=c(0,0) ) + scale_fill_manual(values = c( "brown"="brown", "green"="#00ff00", "transparent"="transparent", "slategrey"="#2f4f4f", "navyblue"="#000080", "purple"="#a020f0" ), expand=c(0,0) ) + #scale_x_continuous(expand=c(0,0)) + #scale_y_continuous(expand=c(0,0)) + theme_nothing() + theme(plot.background = element_rect(fill = bg, colour=NA), plot.margin = margin(t=0,b=0)) + labs(x = NULL, y = NULL), ncol=1, rel_heights = c(1, #-0.1, 1) ) } position_annotation(merged_df3, aa_pos_drug=aa_pos_drug, active_aa_pos=active_aa_pos, aa_pos_lig1=aa_pos_lig1, aa_pos_lig2=aa_pos_lig2, aa_pos_lig3=aa_pos_lig3 ) # # # proof that you can use this function to pass arbitrary lists of numbers :-) # position_annotation(merged_df3, # aa_pos_drug=1:1000, # active_aa_pos=1:1000, # aa_pos_lig1=1:1000, # aa_pos_lig2=1:1000, # aa_pos_lig3=1:1000 # )