updated and tested logoP_snp.R. All done nicely

This commit is contained in:
Tanushree Tunstall 2022-01-15 13:17:26 +00:00
parent 0334188801
commit 9546355241
4 changed files with 155 additions and 99 deletions

View file

@ -142,11 +142,11 @@ LogoPlotSnps <- function(plot_df
, "\nRownames of mutant matrix:", rownames(tab_wt)
, "\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) +
#####################################
# Generating logo plots for nsSNPs
#####################################
#-------------------
# Mutant logo plot
#-------------------
p0 = ggseqlogo(tab_mt
, method = 'custom'
, col_scheme = my_logo_col
, seq_type = 'aa') +
theme(
# panel.grid = element_blank(),
theme(text=element_text(family="FreeSans"))+
theme(axis.text.x = element_blank()) +
theme_logo()+
# axis.text.x = element_text(size = x_ats
# , angle = x_tangle
# , hjust = 1
# , vjust = 0.4
# , colour = xfont_bgc)
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.text.y = element_text(size = y_ats
# , angle = y_tangle
# , hjust = 1
# , vjust = 0
# , colour = yfont_bgc)
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.title.x = element_text(size = x_tts
, colour = xtt_col)
, 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
, axis.title.y = element_text(size = y_tts
, colour = ytt_col)
#------------------
# 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)+
# 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.text.x = element_text(size = x_ats
, angle = x_tangle
, hjust = 1
, vjust = 0.4
, colour = xfont_bgc)
, axis.text.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)
, plot.background = element_rect(fill = theme_bgc))
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')
return(mut_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
)

View file

@ -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
)