moved plotting_func to functions and replaced 3 basic_barplots scripts with 1

This commit is contained in:
Tanushree Tunstall 2021-06-10 16:09:58 +01:00
parent b9d176afa4
commit ff7522eca2
9 changed files with 287 additions and 237 deletions

View file

@ -21,8 +21,10 @@ library(dplyr)
require("getopt", quietly = TRUE) # cmd parse arguments
# load functions
source("plotting_globals.R")
source("plotting_data.R")
source("functions/plotting_globals.R")
source("functions/plotting_data.R")
source("functions/stability_count_bp.R")
source("functions/position_count_bp.R")
#########################################################
# command line args
#********************
@ -117,17 +119,7 @@ plot_basic_bp_ligand = paste0(plotdir,"/", basic_bp_ligand)
# plot 2
pos_count_ligand = paste0(tolower(gene), "_position_count_LIG.svg")
plot_pos_count_ligand = paste0(plotdir, "/", pos_count_ligand)
#=======================================================================
#================
# Data for plots
#================
# REASSIGNMENT as necessary
df = my_df_u_lig
# sanity checks
str(df)
#=====================================================================
#****************
# Plot 1: Count of stabilising and destabilsing muts
#****************
@ -135,9 +127,6 @@ str(df)
svg(plot_basic_bp_ligand)
print(paste0("plot1 filename:", basic_bp_ligand))
#--------------
# start plot 1: call function
#--------------
stability_count_bp(plotdf = my_df_u_lig
, df_colname = "ligand_outcome"
, leg_title = "Ligand outcome")
@ -148,84 +137,12 @@ table(my_df_u_lig$ligand_outcome)
#****************
# Plot 2: frequency of positions
#****************
df_ncols = ncol(df)
df_nrows = nrow(df)
cat(paste0("original df dimensions:"
, "\nNo. of rows:", df_nrows
, "\nNo. of cols:", df_ncols
, "\nNow adding column: frequency of mutational positions"))
#setDT(df)[, .(pos_count := .N), by = .(position)]
setDT(df)[, pos_count := .N, by = .(position)]
rm(df_nrows, df_ncols)
df_nrows = nrow(df)
df_ncols = ncol(df)
cat(paste0("revised df dimensions:"
, "\nNo. of rows:", df_nrows
, "\nNo. of cols:", df_ncols))
# this is cummulative
table(df$pos_count)
# use group by on this
snpsBYpos_df <- df %>%
group_by(position) %>%
summarize(snpsBYpos = mean(pos_count))
table(snpsBYpos_df$snpsBYpos)
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# FIXME, get this mutation_info, perhaLIG useful!
foo = select(df, mutationinformation
, wild_pos
, wild_type
, mutant_type
#, mutation_info # comes from meta data, notused yet
, position
, pos_count)
#write.csv(foo, "/pos_count_freq.csv")
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#--------------
# start plot 2
#--------------
#svg("position_count_LIG.svg")
svg(plot_pos_count_ligand)
print(paste0("plot filename:", plot_pos_count_ligand))
my_ats = 25 # axis text size
my_als = 22 # axis label size
site_snp_count_bp(plotdf = my_df_u
, df_colname = "position")
# to make x axis display all positions
# not sure if to use with sort or directly
my_x = sort(unique(snpsBYpos_df$snpsBYpos))
g = ggplot(snpsBYpos_df, aes(x = snpsBYpos))
OutPlot_lig_pos_count = g + geom_bar(aes (alpha = 0.5)
, show.legend = FALSE) +
scale_x_continuous(breaks = unique(snpsBYpos_df$snpsBYpos)) +
#scale_x_continuous(breaks = my_x) +
geom_label(stat = "count", aes(label = ..count..)
, color = "black"
, size = 10) +
theme(axis.text.x = element_text(size = my_ats
, angle = 0)
, axis.text.y = element_text(size = my_ats
, angle = 0
, hjust = 1)
, axis.title.x = element_text(size = my_als)
, axis.title.y = element_text(size = my_als)
, plot.title = element_blank()) +
labs(x = "Number of nsSNPs"
, y = "Number of Sites")
print(OutPlot_lig_pos_count)
dev.off()
########################################################################
# end of LIG barplots