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
|
@ -124,7 +124,7 @@ install.packages("data.table")
|
|||
|
||||
if (!require("PerformanceAnalytics")){
|
||||
install.packages("PerformanceAnalytics", dependencies = T)
|
||||
library(PerformaceAnalytics)
|
||||
library(PerformanceAnalytics)
|
||||
}
|
||||
|
||||
if (!require ("GGally")){
|
||||
|
|
|
@ -134,7 +134,7 @@ if(!require("data.table")) {
|
|||
|
||||
if (!require("PerformanceAnalytics")){
|
||||
install.packages("PerformanceAnalytics", dependencies = T)
|
||||
library(PerformaceAnalytics)
|
||||
library(PerformanceAnalytics)
|
||||
}
|
||||
|
||||
if (!require ("GGally")){
|
||||
|
|
|
@ -40,35 +40,40 @@
|
|||
###########################################
|
||||
#LogoPlotMSA <- function(msaSeq_mut # chr vector
|
||||
# , msaSeq_wt # chr vector
|
||||
LogoPlotMSA <- function(unified_msa
|
||||
LogoPlotMSA <- function(# unified_msa # <- not needed any more because we have 'target' now
|
||||
target = 'embb'
|
||||
, logo_type = c("EDLogo") #"bits_pfm", "probability_pfm", "bits_raw", "probability_raw")
|
||||
, EDScore_type = c("log") # see if this relevant, or source function should have it!
|
||||
, bg_prob = NULL
|
||||
, my_logo_col = "chemistry"
|
||||
, plot_positions
|
||||
, y_breaks
|
||||
, x_lab_mut = "nsSNP position"
|
||||
, x_lab_mut = ""
|
||||
, y_lab_mut
|
||||
, x_ats = 13 # text size
|
||||
, x_ats = 10 # text size
|
||||
, x_tangle = 90 # text angle
|
||||
, x_axis_offset = 0 # dist b/w y-axis and plot start
|
||||
, x_axis_offset_filtered = 0
|
||||
, y_axis_offset = 0
|
||||
, y_axis_increment = 1
|
||||
, y_ats = 13
|
||||
, y_ats = 10
|
||||
, y_tangle = 0
|
||||
, x_tts = 13 # title size
|
||||
, y_tts = 13
|
||||
, x_tts = 10 # title size
|
||||
, y_tts = 10
|
||||
, leg_pos = "top" # can be top, left, right and bottom or c(0.8, 0.9)
|
||||
, leg_dir = "horizontal" #can be vertical or horizontal
|
||||
, leg_ts = 16 # leg text size
|
||||
, leg_tts = 16 # leg title size
|
||||
, leg_ts = 14 # leg text size
|
||||
, leg_tts = 14 # leg title size
|
||||
, ...
|
||||
)
|
||||
|
||||
{
|
||||
# FIXME: Hack!
|
||||
# msaSeq_mut=unified_msa[[1]]
|
||||
# msaSeq_wt=unified_msa[[2]]
|
||||
|
||||
unified_msa = get(paste0(target, "_unified_msa"))
|
||||
|
||||
msaSeq_mut=unified_msa[['msa_seq']]
|
||||
msaSeq_wt=unified_msa[['wt_seq']]
|
||||
|
||||
|
@ -79,6 +84,51 @@ LogoPlotMSA <- function(unified_msa
|
|||
names(data_ed)
|
||||
#"pfm_mutM" "pfm_mut_scaledM" "combED_mutM" "pfm_wtM" "pfm_wt_scaledM" "combED_wtM"
|
||||
|
||||
#merged_df3 for current target (unfortunatly i can't think of an easy way to get this from unified_msa)
|
||||
contig_df=data.frame(position=1:max(nchar(unified_msa$wt_seq)))
|
||||
plot_df = get(paste0(target, "_merged_df3"))
|
||||
|
||||
# generate the tile columns
|
||||
#plot_df=cbind(embb_merged_df3)
|
||||
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)
|
||||
|
||||
plot_df = generate_distance_colour_map(plot_df, debug=FALSE)
|
||||
|
||||
# copy only the tile columns to the contiguous DF
|
||||
|
||||
contig_df$ligand_distance = plot_df$ligand_distance[match(contig_df$position, plot_df$position)]
|
||||
contig_df_map = generate_distance_colour_map(contig_df, debug=TRUE)
|
||||
contig_df$ligD_colours = contig_df_map$ligD_colours[match(contig_df$position, contig_df_map$position)]
|
||||
|
||||
#contig_df$ligD_colours = plot_df$ligD_colours[match(contig_df$position, plot_df$position)]
|
||||
contig_df$bg_all = plot_df$bg_all[match(contig_df$position, plot_df$position)]
|
||||
contig_df$col_bg1 = plot_df$col_bg1[match(contig_df$position, plot_df$position)]
|
||||
contig_df$col_bg2 = plot_df$col_bg2[match(contig_df$position, plot_df$position)]
|
||||
contig_df$col_bg3 = plot_df$col_bg3[match(contig_df$position, plot_df$position)]
|
||||
contig_df=replace_na(
|
||||
contig_df,
|
||||
list(
|
||||
ligD_colours='transparent',
|
||||
bg_all = 'transparent',
|
||||
col_bg1 = 'transparent',
|
||||
col_bg2 = 'transparent',
|
||||
col_bg3 = 'transparent'
|
||||
)
|
||||
)
|
||||
|
||||
if (logo_type == "EDLogo"){
|
||||
msa_method = "custom"
|
||||
y_label = "Enrichment Score"
|
||||
|
@ -416,7 +466,7 @@ LogoPlotMSA <- function(unified_msa
|
|||
|
||||
) +
|
||||
scale_y_discrete(expand = c(0,0)) +
|
||||
ylab("") + xlab("Wild-type position")
|
||||
ylab("") + xlab("")
|
||||
|
||||
if (missing(plot_positions)){
|
||||
|
||||
|
@ -430,13 +480,27 @@ LogoPlotMSA <- function(unified_msa
|
|||
#labels = i_extract,
|
||||
limits = factor(i_extract)
|
||||
)
|
||||
|
||||
#plot_df=plot_df[plot_df$position %in% plot_positions,]
|
||||
contig_df=contig_df[contig_df$position %in% plot_positions,]
|
||||
anno_bar = position_annotation(
|
||||
contig_df,
|
||||
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,
|
||||
generate_colours = FALSE
|
||||
)
|
||||
|
||||
}
|
||||
cowplot::plot_grid(ed_mut_logo_P
|
||||
, ed_wt_logo_P
|
||||
, nrow = 2
|
||||
, anno_bar
|
||||
, ncol = 1
|
||||
, align = "v"
|
||||
#, axis='lr'
|
||||
, rel_heights = c(3/4, 1/4))
|
||||
, rel_heights = c(3/4, 1/4,1/10))
|
||||
|
||||
}
|
||||
#LogoPlotMSA(unified_msa)
|
||||
|
|
|
@ -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,6 +33,8 @@ 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")
|
||||
|
||||
if (generate_colours){
|
||||
plot_df$col_aa = ifelse(plot_df[["position"]]%in%active_aa_pos,
|
||||
"transparent", "transparent")
|
||||
|
||||
|
@ -55,7 +58,7 @@ position_annotation=function(plot_df,
|
|||
# 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)) +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue