updated and tested logoP_snp.R. All done nicely
This commit is contained in:
parent
0334188801
commit
9546355241
4 changed files with 155 additions and 99 deletions
|
@ -143,10 +143,10 @@ LogoPlotSnps <- function(plot_df
|
|||
, "\nColnames of mutant matrix:", colnames(tab_wt))
|
||||
}
|
||||
|
||||
|
||||
######################################
|
||||
# Generating plots with given y_axis
|
||||
# Generating plots for muts and wt
|
||||
#####################################
|
||||
LogoPlotL <- list()
|
||||
|
||||
if (my_logo_col %in% c('clustalx','taylor')) {
|
||||
cat("\nSelected colour scheme:", my_logo_col
|
||||
|
@ -169,76 +169,132 @@ LogoPlotSnps <- function(plot_df
|
|||
xtt_col = "black"
|
||||
ytt_col = "black"
|
||||
}
|
||||
#LogoSnps_P
|
||||
mut_logo_p = ggseqlogo(tab_mt
|
||||
, method = "custom"
|
||||
, col_scheme = my_logo_col) +
|
||||
|
||||
theme(
|
||||
# panel.grid = element_blank(),
|
||||
#####################################
|
||||
# Generating logo plots for nsSNPs
|
||||
#####################################
|
||||
|
||||
# axis.text.x = element_text(size = x_ats
|
||||
# , angle = x_tangle
|
||||
# , hjust = 1
|
||||
# , vjust = 0.4
|
||||
# , colour = xfont_bgc)
|
||||
#-------------------
|
||||
# Mutant logo plot
|
||||
#-------------------
|
||||
p0 = ggseqlogo(tab_mt
|
||||
, method = 'custom'
|
||||
, col_scheme = my_logo_col
|
||||
, seq_type = 'aa') +
|
||||
|
||||
# , axis.text.y = element_text(size = y_ats
|
||||
# , angle = y_tangle
|
||||
# , hjust = 1
|
||||
# , vjust = 0
|
||||
# , colour = yfont_bgc)
|
||||
theme(text=element_text(family="FreeSans"))+
|
||||
theme(axis.text.x = element_blank()) +
|
||||
theme_logo()+
|
||||
|
||||
, axis.title.x = element_text(size = x_tts
|
||||
, colour = xtt_col)
|
||||
scale_x_continuous(breaks = 1:ncol(tab_mt)
|
||||
, expand = c(0.01,0)
|
||||
, labels = colnames(tab_mt))+
|
||||
scale_y_continuous(breaks = 0:(max_mult_mut-1)
|
||||
, labels = c(1:max_mult_mut)
|
||||
, limits = c(0, max_mult_mut)) +
|
||||
#xlab(x_lab) +
|
||||
ylab(y_lab)
|
||||
|
||||
, axis.title.y = element_text(size = y_tts
|
||||
, colour = ytt_col)
|
||||
cat('\nDone: p0')
|
||||
|
||||
# further customisation
|
||||
mut_logo_p <<- p0 + theme(legend.position = leg_pos
|
||||
, 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)
|
||||
#, axis.text.y = element_blank()
|
||||
, axis.text.y = element_text(size = y_ats
|
||||
, angle = y_tangle
|
||||
, hjust = 1
|
||||
, vjust = -1.0
|
||||
, colour = yfont_bgc)
|
||||
, axis.title.x = element_text(size = x_tts
|
||||
, colour = xtt_col)
|
||||
, axis.title.y = element_text(size = y_tts
|
||||
, colour = ytt_col)
|
||||
|
||||
, plot.background = element_rect(fill = theme_bgc))
|
||||
|
||||
cat('\nDone: mut_logo_p')
|
||||
#return(mut_logo_p)
|
||||
LogoPlotL[['mut_logoP']] <- mut_logo_p
|
||||
|
||||
#------------------
|
||||
# Wild logo plot
|
||||
#------------------
|
||||
p1 = ggseqlogo(tab_wt
|
||||
, 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)
|
||||
|
||||
cat('\nDone: p1')
|
||||
|
||||
# further customisation
|
||||
wt_logo_p <<- p1 +
|
||||
|
||||
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)
|
||||
, legend.position = leg_pos
|
||||
, legend.direction = leg_dir
|
||||
, plot.background = element_rect(fill = theme_bgc))+
|
||||
|
||||
#theme(text = element_text(family = "FreeSans"))+
|
||||
# theme_logo(base_size = 18)+
|
||||
, axis.text.x = element_text(size = x_ats
|
||||
, angle = x_tangle
|
||||
, hjust = 1
|
||||
, vjust = 0.4
|
||||
, colour = xfont_bgc)
|
||||
, axis.text.y = element_blank()
|
||||
|
||||
# scale_x_continuous(breaks = 1:ncol(tab_mt)
|
||||
# , labels = colnames(tab_mt))+
|
||||
# scale_y_continuous(breaks = 1:max_mult_mut
|
||||
# , limits = c(0, max_mult_mut)) +
|
||||
scale_x_discrete(x_lab
|
||||
, labels = colnames(tab_mt)
|
||||
, limits = factor(1:ncol(tab_mt)))+
|
||||
scale_y_continuous(y_lab
|
||||
, breaks = 1:max_mult_mut
|
||||
, limits = c(0, max_mult_mut))#+
|
||||
# ylab(y_lab)+xlab(x_lab)
|
||||
, axis.title.x = element_text(size = x_tts
|
||||
, colour = xtt_col)
|
||||
, axis.title.y = element_text(size = y_tts
|
||||
, colour = ytt_col)
|
||||
|
||||
, plot.background = element_rect(fill = theme_bgc))
|
||||
|
||||
return(mut_logo_p)
|
||||
cat('\nDone: wt_logo_p')
|
||||
#return(wt_logo_p)
|
||||
LogoPlotL[['wt_logoP']] <- wt_logo_p
|
||||
|
||||
#=========================================
|
||||
# Output
|
||||
# Combined plot: logo_mutliple_muts.svg
|
||||
#=========================================
|
||||
#suppressMessages( require(cowplot) )
|
||||
#plot_grid(p1, p3, ncol = 1, align = 'v')
|
||||
cat('\nDone: mut_logo_p + wt_logo_p')
|
||||
|
||||
# colour scheme: https://rdrr.io/cran/ggseqlogo/src/R/col_schemes.r
|
||||
#cat("\nOutput plot:", LogoSNPs_comb, "\n")
|
||||
#svg(LogoSNPs_combined, width = 32, height = 10)
|
||||
LogoPlotL[['wt_logoP']] <- wt_logo_p
|
||||
|
||||
LogoSNPs_comb = cowplot::plot_grid(LogoPlotL[['mut_logoP']]
|
||||
, LogoPlotL[['wt_logoP']]
|
||||
, nrow = 2
|
||||
, align = "v"
|
||||
, rel_heights = c(3/4, 1/4))
|
||||
|
||||
return(LogoSNPs_comb)
|
||||
|
||||
}
|
||||
|
||||
|
||||
LogoPlotSnps(plot_df = merged_df3
|
||||
, x_axis_colname = "position"
|
||||
, symbol_mut_colname = "mutant_type"
|
||||
, symbol_wt_colname = "mutant_type"
|
||||
, omit_snp_count = c(0)# can be 1, 2, etc.
|
||||
|
||||
, my_logo_col = "chemistry"
|
||||
, x_lab = "Position"
|
||||
, y_lab = "Count"
|
||||
, x_ats = 1 # text size
|
||||
, x_tangle = 90 # text angle
|
||||
, y_ats = 1
|
||||
, y_tangle = 0
|
||||
, x_tts = 20 # title size
|
||||
, y_tts = 20
|
||||
, 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 = 20 # leg text size
|
||||
, leg_tts = 16 # leg title size
|
||||
)
|
||||
|
|
|
@ -6,20 +6,19 @@
|
|||
LogoPlotSnps(plot_df = merged_df3
|
||||
, 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"
|
||||
, y_lab = "Count"
|
||||
, x_ats = 1 # text size
|
||||
, my_logo_col = "taylor"
|
||||
, x_lab = "Wild-type position"
|
||||
, y_lab = ""
|
||||
, x_ats = 13 # text size
|
||||
, x_tangle = 90 # text angle
|
||||
, y_ats = 1
|
||||
, y_ats = 20
|
||||
, y_tangle = 0
|
||||
, x_tts = 20 # title size
|
||||
, y_tts = 20
|
||||
, x_tts = 18 # title size
|
||||
, y_tts = 18
|
||||
, 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 = 20 # leg text size
|
||||
, leg_ts = 14 # leg text size
|
||||
, leg_tts = 16 # leg title size
|
||||
)
|
||||
|
|
|
@ -120,44 +120,44 @@ merged_df3_comp = all_plot_dfs[[4]]
|
|||
|
||||
#source("other_plots_data.R")
|
||||
|
||||
source(paste0(plot_script_path, "dm_om_data.R"))
|
||||
|
||||
s2 = c("\nSuccessfully sourced other_plots_data.R")
|
||||
cat(s2)
|
||||
# source(paste0(plot_script_path, "dm_om_data.R"))
|
||||
#
|
||||
# s2 = c("\nSuccessfully sourced other_plots_data.R")
|
||||
# cat(s2)
|
||||
|
||||
####################################################################
|
||||
# Data for Lineage barplots: WF and LF dfs
|
||||
####################################################################
|
||||
|
||||
source(paste0(plot_script_path, "lineage_data.R"))
|
||||
|
||||
s3 = c("\nSuccessfully sourced lineage_data.R")
|
||||
cat(s3)
|
||||
#
|
||||
# source(paste0(plot_script_path, "lineage_data.R"))
|
||||
#
|
||||
# s3 = c("\nSuccessfully sourced lineage_data.R")
|
||||
# cat(s3)
|
||||
|
||||
####################################################################
|
||||
# Data for corr plots:
|
||||
####################################################################
|
||||
# make sure the above script works because merged_df2_combined is needed
|
||||
source(paste0(plot_script_path, "corr_data.R"))
|
||||
|
||||
s4 = c("\nSuccessfully sourced corr_data.R")
|
||||
cat(s4)
|
||||
# source(paste0(plot_script_path, "corr_data.R"))
|
||||
#
|
||||
# s4 = c("\nSuccessfully sourced corr_data.R")
|
||||
# cat(s4)
|
||||
|
||||
########################################################################
|
||||
# End of script
|
||||
########################################################################
|
||||
if ( all( length(s1), length(s2), length(s3), length(s4) ) > 0 ){
|
||||
cat(
|
||||
"\n##################################################"
|
||||
, "\nSuccessful: get_plotting_dfs.R worked!"
|
||||
, "\n###################################################\n")
|
||||
} else {
|
||||
cat(
|
||||
"\n#################################################"
|
||||
, "\nFAIL: get_plotting_dfs.R didn't complete fully!Please check"
|
||||
, "\n###################################################\n" )
|
||||
}
|
||||
|
||||
# if ( all( length(s1), length(s2), length(s3), length(s4) ) > 0 ){
|
||||
# cat(
|
||||
# "\n##################################################"
|
||||
# , "\nSuccessful: get_plotting_dfs.R worked!"
|
||||
# , "\n###################################################\n")
|
||||
# } else {
|
||||
# cat(
|
||||
# "\n#################################################"
|
||||
# , "\nFAIL: get_plotting_dfs.R didn't complete fully!Please check"
|
||||
# , "\n###################################################\n" )
|
||||
# }
|
||||
#
|
||||
########################################################################
|
||||
# clear excess variables: from the global enviornment
|
||||
|
||||
|
|
|
@ -190,7 +190,8 @@ cat('\nDone: p2')
|
|||
wt_logo_p = p2 +
|
||||
theme(legend.position = "bottom"
|
||||
#, legend.title = element_blank()
|
||||
, legend.title = element_text("Amino acid properties", size = 20)
|
||||
, legend.title = element_text("Amino acid properties"
|
||||
, size = 20)
|
||||
, legend.text = element_text(size = 20)
|
||||
, axis.text.x = element_text(size = 14, angle = 90)
|
||||
, axis.text.y = element_blank()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue