added separate scripts for layout for convinience

This commit is contained in:
Tanushree Tunstall 2022-08-09 21:47:24 +01:00
parent d78b072732
commit cd86fcf8e8
6 changed files with 468 additions and 78 deletions

View file

@ -326,15 +326,13 @@ snap2P = stability_count_bp(plotdf = df3
#
# dev.off()
#####################################################################
# LAYOUT
my_label_size = 25
#ratio 11.69 by 8.27
w = 8.27*2
h = 11.69*2
#============
# Plot labels
#============
tit1 = "Stability outcome"
tit2 = "Affinity outcome"
tit3 = "Conservation outcome"
pt_size = 30
theme_georgia <- function(...) {
@ -351,7 +349,7 @@ pt1 = ggdraw() +
fontfamily = title_theme$family,
fontface = title_theme$face,
#size = title_theme$size
size = 30
size = pt_size
)
pt2 = ggdraw() +
@ -359,7 +357,7 @@ pt2 = ggdraw() +
tit2,
fontfamily = title_theme$family,
fontface = title_theme$face,
size = 30
size = pt_size
)
pt3 = ggdraw() +
@ -367,7 +365,7 @@ pt3 = ggdraw() +
tit3,
fontfamily = title_theme$family,
fontface = title_theme$face,
size = 30
size = pt_size
)
# extract common legend
@ -376,9 +374,11 @@ common_legend_outcome = get_legend(mLigP +
theme(legend.position = "top"))
#=============
# Output plot
#=============
my_label_size = 25
#======================
# Output plot function
#======================
OutPlotBP = function(x){
cowplot::plot_grid(
cowplot::plot_grid(pt1,
@ -422,25 +422,35 @@ cowplot::plot_grid(
)
}
#=====================
# OutPlot: svg and png
#======================
#ratio 11.69 by 8.27
w = 8.27*2
h = 11.69*2
#svg
bp_all_CLP = paste0(outdir_images
,tolower(gene)
,"_bp_all_CL.svg"); print(paste0("plot filename:", bp_all_CLP))
bp_all_CLP_png = paste0(outdir_images
,tolower(gene)
,"_bp_all_CL.png"); print(paste0("plot filename:", bp_all_CLP_png))
,"_bp_all_CL.svg")
cat(paste0("plot filename:", bp_all_CLP))
svg(bp_all_CLP, width = w, height = h)
OutPlotBP()
dev.off()
#png
bp_all_CLP_png = paste0(outdir_images
,tolower(gene)
,"_bp_all_CL.png")
cat(paste0("plot filename:", bp_all_CLP_png))
png(bp_all_CLP_png, width = w, height = h, units = "in", res = 300 )
OutPlotBP()
dev.off()
#####################################################################
#===============================================================
#####################################################################
# ------------------------------
# bp site site count: ALL
# <10 Ang ligand
@ -505,7 +515,6 @@ cowplot::plot_grid(posC_all, posC_lig, posC_ppi2
#, posC_na
, nrow = 1
, ncol = 3
#, labels = c("(a)", "(b)", "(c)", "(d)")
, labels = "AUTO"
, label_size = my_label_size)

View file

@ -1,27 +1,198 @@
#!/usr/bin/env Rscript
#########################################################
#main script that generates plot objects:
#source("basic_barplots.R")
#########################################################
# source basic_barplots.R
#============
# Plot labels
#============
tit1 = "Stability outcome"
tit2 = "Affinity outcome"
tit3 = "Conservation outcome"
pt_size = 30
theme_georgia <- function(...) {
theme_gray(base_family = "sans", ...) +
theme(plot.title = element_text(face = "bold"))
}
title_theme <- calc_element("plot.title", theme_georgia())
pt1 = ggdraw() +
draw_label(
tit1,
fontfamily = title_theme$family,
fontface = title_theme$face,
#size = title_theme$size
size = pt_size
)
pt2 = ggdraw() +
draw_label(
tit2,
fontfamily = title_theme$family,
fontface = title_theme$face,
size = pt_size
)
pt3 = ggdraw() +
draw_label(
tit3,
fontfamily = title_theme$family,
fontface = title_theme$face,
size = pt_size
)
# extract common legend
common_legend_outcome = get_legend(mLigP +
guides(color = guide_legend(nrow = 1)) +
theme(legend.position = "top"))
my_label_size = 25
#======================
# Output plot function
#======================
OutPlotBP = function(x){
cowplot::plot_grid(
cowplot::plot_grid(pt1,
common_legend_outcome,
cowplot::plot_grid( duetP, foldxP
, deepddgP, dynamut2P
, nrow = 2
, ncol = 2
, labels = c("A", "B", "C","D")
, label_size = my_label_size
)
, ncol = 1
, rel_heights = c(7, 3, 90)),
cowplot::plot_grid(pt2,
cowplot::plot_grid(mLigP, mmLigP, ppi2P
, nrow = 1
, ncol = 3
, labels = c("E","F", "G")
, label_size = my_label_size
)
, ncol = 1
, rel_heights = c(1, 9)),
cowplot::plot_grid(pt3,
cowplot::plot_grid(consurfP, proveanP, snap2P
, nrow = 1
, ncol = 3
, labels = c("H", "I", "J")
, labels_x = 0.2
, label_size = my_label_size
, rel_widths = c(0.2, 0.2, 0.2)
)
, ncol = 1
, rel_heights = c(0.07, 0.93)
),
nrow = 3,
rel_heights = c(0.58, 0.25, 0.27),
align = "hv"
)
}
#=======================================================================
#=======
# output
#=======
outdir_images = paste0("~/git/Writing/thesis/images/results/"
, tolower(gene), "/")
cat("plots will output to:", outdir_images)
#=====================
# OutPlot: svg and png
#======================
#ratio 11.69 by 8.27
w = 8.27*2
h = 11.69*2
df_colname = "duet_outcome"
#svg
bp_all_CLP = paste0(outdir_images
,tolower(gene)
,"_bp_all_CL.svg")
cat(paste0("plot filename:", bp_all_CLP))
OutPlot_count = ggplot(df3, aes_string(x = df_colname)) +
geom_bar(aes(fill = eval(parse(text = df_colname)))
, show.legend = TRUE) +
geom_label(stat = "count"
, aes(label = ..count..)
, color = "black"
, show.legend = FALSE
, size = geom_ls)
svg(bp_all_CLP, width = w, height = h)
OutPlotBP()
dev.off()
#png
bp_all_CLP_png = paste0(outdir_images
,tolower(gene)
,"_bp_all_CL.png")
cat(paste0("plot filename:", bp_all_CLP_png))
png(bp_all_CLP_png, width = w, height = h, units = "in", res = 300 )
OutPlotBP()
dev.off()
#####################################################################
#####################################################################
# ------------------------------
# bp site site count: ALL
# <10 Ang ligand
# ------------------------------
posC_all = site_snp_count_bp(plotdf = df3
, df_colname = "position"
, xaxis_title = "Number of nsSNPs"
, yaxis_title = "Number of Sites"
, subtitle_size = 20)
# ------------------------------
# bp site site count: mCSM-lig
# < 10 Ang ligand
# ------------------------------
common_bp_title = paste0("Sites <", DistCutOff, angstroms_symbol)
posC_lig = site_snp_count_bp(plotdf = df3_lig
, df_colname = "position"
, xaxis_title = "Number of nsSNPs"
, yaxis_title = "Number of Sites"#+ annotate("text", x = 1.5, y = 2.2, label = "Text No. 1")
, subtitle_text = paste0(common_bp_title, " ligand")
, subtitle_size = 20
, subtitle_colour = subtitle_colour)
# ------------------------------
# bp site site count: ppi2
# < 10 Ang interface
# ------------------------------
posC_ppi2 = site_snp_count_bp(plotdf = df3_ppi2
, df_colname = "position"
, xaxis_title = "Number of nsSNPs"
, yaxis_title = "Number of Sites"
, subtitle_text = paste0(common_bp_title, " interface")
, subtitle_size = 20
, subtitle_colour = subtitle_colour)
# ------------------------------
#FIXME: bp site site count: na
# < 10 Ang TBC
# ------------------------------
# posC_na = site_snp_count_bp(plotdf = df3_na
# , df_colname = "position"
# , xaxis_title = ""
# , yaxis_title = "")
#===========================
# output: SITE SNP count:
# all + affinity
#==========================
my_label_size = 25
pos_count_combined_CLP = paste0(outdir_images
,tolower(gene)
,"_pos_count_PS_AFF.svg")
svg(pos_count_combined_CLP, width = 20, height = 5.5)
print(paste0("plot filename:", pos_count_combined_CLP))
cowplot::plot_grid(posC_all, posC_lig, posC_ppi2
#, posC_na
, nrow = 1
, ncol = 3
, labels = "AUTO"
, label_size = my_label_size)
dev.off()
#===============================================================

View file

@ -22,7 +22,7 @@ genomics_param = c("Log10(MAF)")
dist_genP = lf_bp2(lf_dist_genP
#, p_title
, violin_quantiles = c(0.5), monochrome = F)
#dist_genP
#-------------------
# Genomics data plot
#-------------------
@ -42,12 +42,18 @@ wilcox.test(wf_dist_genP$`Log10(MAF)`[wf_dist_genP$mutation_info_labels=="R"]
tapply(wf_dist_genP$`Log10(MAF)`, wf_dist_genP$mutation_info_labels, summary)
#---------------------------------------
# Distance data plot: not genomics data
#---------------------------------------
#-------------------
# Distance data plot:
#--------------------
# not genomics
dist_dataP = lf_dist_genP[!lf_dist_genP$param_type%in%genomics_param,]
#dist_dataP$param_type = factor(dist_dataP$param_type)
dist_dataP$param_type = factor(dist_dataP$param_type)
table(dist_dataP$param_type)
levels(dist_dataP$param_type)
# relevel factor to control ordering of appearance of plot
dist_dataP$param_type <-relevel(dist_dataP$param_type, "Lig Dist(Å)" )
table(dist_dataP$param_type)
levels(dist_dataP$param_type)
distanceP = lf_bp2(dist_dataP
#, p_title = ""
@ -66,6 +72,55 @@ tapply(wf_dist_genP$`PPI Dist(Å)`, wf_dist_genP$mutation_info_labels, summary)
tapply(wf_dist_genP$`Lig Dist(Å)`, wf_dist_genP$mutation_info_labels, summary)
#-------------------
# Distance data plot: LigDist
#--------------------
levels(dist_dataP$param_type)[[1]]
#Lig Dist(Å), PPI Dist(Å)
dist_data_lig = dist_dataP[dist_dataP$param_type%in%c(levels(dist_dataP$param_type)[[1]]),]
dist_data_lig$param_type = factor(dist_data_lig$param_type)
table(dist_data_lig$param_type)
levels(dist_data_lig$param_type)
distanceP_lig = lf_bp2(dist_data_lig
#, p_title = ""
, violin_quantiles = c(0.5), monochrome = F)
distanceP_lig
if (tolower(gene)%in%geneL_ppi2){
#-------------------
# Distance data plot: LigDist
#--------------------
levels(dist_dataP$param_type)[[2]]
#Lig Dist(Å), PPI Dist(Å)
dist_data_ppi2 = dist_dataP[dist_dataP$param_type%in%c(levels(dist_dataP$param_type)[[2]]),]
dist_data_ppi2$param_type = factor(dist_data_ppi2$param_type)
table(dist_data_ppi2$param_type)
levels(dist_data_ppi2$param_type)
distanceP_ppi2 = lf_bp2(dist_data_ppi2
#, p_title = ""
, violin_quantiles = c(0.5), monochrome = F)
distanceP_ppi2
}
if (tolower(gene)%in%geneL_na){
#-------------------
# Distance data plot: NADist
#--------------------
levels(dist_dataP$param_type)[[3]]
#Lig Dist(Å), PPI Dist(Å)
dist_data_na = dist_dataP[dist_dataP$param_type%in%c(levels(dist_dataP$param_type)[[3]]),]
dist_data_na$param_type = factor(dist_data_na$param_type)
table(dist_data_na$param_type)
levels(dist_data_na$param_type)
distanceP_na = lf_bp2(dist_data_na
#, p_title = ""
, violin_quantiles = c(0.5), monochrome = F)
distanceP_na
}
#==============
# Plot:DUET
#==============
@ -234,35 +289,27 @@ if (tolower(gene)%in%geneL_na){
######################################
# Outplot with stats
######################################
outdir_images = paste0("~/git/Writing/thesis/images/results/", tolower(gene), "/")
dm_om_combinedP = paste0(outdir_images
,tolower(gene)
,"_dm_om_all.svg" )
cat("DM OM plots with stats:", dm_om_combinedP)
svg(dm_om_combinedP, width = 32, height = 18)
cowplot::plot_grid(
cowplot::plot_grid(duetP, foldxP, deepddgP, dynamut2P, genomicsP, distanceP
, nrow=1
, rel_widths = c(1/7, 1/7,1/7,1/7, 1/7, 1.75/7)),
#, rel_widths = c(1/8, 1/8,1/8,1/8, 1/8, 2.75/8)), # for 3 distances
cowplot::plot_grid(consurfP, proveanP, snap2P
, mcsmligP
, mcsmlig2P
, mcsmppi2P
#, mcsmnaP
, nrow=1),
nrow=2)
dev.off()
#foo = lf_consurfP
# proveanP = lf_bp2(lf_proveanP, colour_categ = "mutation_info_labels"
# , p_title = paste0("Evolutionary conservation")
# , dot_transparency = 1
# , violin_quantiles = c(0.5), monochrome = F)
# outdir_images = paste0("~/git/Writing/thesis/images/results/", tolower(gene), "/")
#
# proveanP
# dm_om_combinedP = paste0(outdir_images
# ,tolower(gene)
# ,"_dm_om_all.svg" )
#
# cat("DM OM plots with stats:", dm_om_combinedP)
# svg(dm_om_combinedP, width = 32, height = 18)
# cowplot::plot_grid(
# cowplot::plot_grid(duetP, foldxP, deepddgP, dynamut2P, genomicsP, distanceP
# , nrow=1
# , rel_widths = c(1/7, 1/7,1/7,1/7, 1/7, 1.75/7)),
# #, rel_widths = c(1/8, 1/8,1/8,1/8, 1/8, 2.75/8)), # for 3 distances
# cowplot::plot_grid(consurfP, proveanP, snap2P
# , mcsmligP
# , mcsmlig2P
# , mcsmppi2P
# #, mcsmnaP
# , nrow=1),
# nrow=2)
#
# dev.off()

View file

@ -0,0 +1,163 @@
# source dm_om_plots.R
#============
# Plot labels
#============
tit1 = "Stability changes"
tit2 = "Genomic measure"
tit3 = "Distance to partners"
tit4 = "Evolutionary Conservation"
tit5 = "Affinity changes"
pt_size = 30
theme_georgia <- function(...) {
theme_gray(base_family = "sans", ...) +
theme(plot.title = element_text(face = "bold"))
}
title_theme <- calc_element("plot.title", theme_georgia())
pt1 = ggdraw() +
draw_label(
tit1,
fontfamily = title_theme$family,
fontface = title_theme$face,
#size = title_theme$size
size = pt_size
)
pt2 = ggdraw() +
draw_label(
tit2,
fontfamily = title_theme$family,
fontface = title_theme$face,
size = pt_size
)
pt3 = ggdraw() +
draw_label(
tit3,
fontfamily = title_theme$family,
fontface = title_theme$face,
size = pt_size
)
pt4 = ggdraw() +
draw_label(
tit4,
fontfamily = title_theme$family,
fontface = title_theme$face,
size = pt_size
)
pt5 = ggdraw() +
draw_label(
tit5,
fontfamily = title_theme$family,
fontface = title_theme$face,
size = pt_size
)
#======================
# Output plot function
#======================
OutPlot_dm_om = function(x){
# dist b/w plot title and plot
relH_tp = c(0.08, 0.92)
my_label_size = 25
#----------------
# Top panel
#----------------
top_panel = cowplot::plot_grid(
cowplot::plot_grid(pt1,
cowplot::plot_grid(duetP, foldxP, deepddgP, dynamut2P
, nrow = 1
, labels = c("A", "B", "C", "D")
, label_size = my_label_size)
, ncol = 1
, rel_heights = relH_tp
),
NULL,
cowplot::plot_grid(pt2,
cowplot::plot_grid(genomicsP
, nrow = 1
, labels = c("E")
, label_size = my_label_size)
, ncol = 1
, rel_heights = relH_tp
),
NULL,
cowplot::plot_grid(pt3,
cowplot::plot_grid( #distanceP
distanceP_lig, distanceP_ppi2
#, distanceP_na
, nrow = 1
, labels = c("F", "G")
, label_size = my_label_size)
, ncol = 1
, rel_heights = relH_tp
),
nrow = 1,
rel_widths = c(2/7, 0.1/7, 0.5/7, 0.1/7, 1/7)
)
#----------------
# Bottom panel
#----------------
bottom_panel = cowplot::plot_grid(
cowplot::plot_grid(pt4,
cowplot::plot_grid(consurfP, proveanP, snap2P
, nrow = 1
, labels = c("H", "I", "J")
, label_size = my_label_size)
, ncol = 1
, rel_heights =relH_tp
),NULL,
cowplot::plot_grid(pt5,
cowplot::plot_grid(mcsmligP, mcsmlig2P
, mcsmppi2P
#, mcsmnaP
, nrow = 1
, labels = c("K", "L", "M")
, label_size = my_label_size)
, ncol = 1
, rel_heights = relH_tp
),NULL,
nrow = 1,
rel_widths = c(3/6,0.1/6,3/6, 0.1/6 )
)
#-------------------------------
# combine: Top and Bottom panel
#-------------------------------
cowplot::plot_grid (top_panel, bottom_panel
, nrow =2
, rel_widths = c(1, 1)
, align = "hv")
}
#=====================
# OutPlot: svg and png
#======================
dm_om_combinedP = paste0(outdir_images
,tolower(gene)
,"_dm_om_all.svg")
cat("DM OM plots with stats:", dm_om_combinedP)
svg(dm_om_combinedP, width = 32, height = 18)
OutPlot_dm_om()
dev.off()
dm_om_combinedP_png = paste0(outdir_images
,tolower(gene)
,"_dm_om_all.png")
cat("DM OM plots with stats:", dm_om_combinedP_png)
png(dm_om_combinedP_png, width = 32, height = 18, units = "in", res = 300)
OutPlot_dm_om()
dev.off()