all barplots generated for ps and lig
This commit is contained in:
parent
8ee7d4234e
commit
de14752a0c
5 changed files with 656 additions and 0 deletions
193
scripts/plotting/basic_barplots_LIG.R
Executable file
193
scripts/plotting/basic_barplots_LIG.R
Executable file
|
@ -0,0 +1,193 @@
|
|||
#!/usr/bin/env Rscript
|
||||
#########################################################
|
||||
# TASK: producing barplots
|
||||
# basic barplots with count of mutations
|
||||
# basic barplots with frequency of count of mutations
|
||||
#########################################################
|
||||
#=======================================================================
|
||||
# working dir and loading libraries
|
||||
getwd()
|
||||
setwd("~/git/LSHTM_analysis/scripts/plotting")
|
||||
getwd()
|
||||
|
||||
#source("Header_TT.R")
|
||||
library(ggplot2)
|
||||
library(data.table)
|
||||
library(dplyr)
|
||||
source("plotting_data.R")
|
||||
|
||||
# should return the following dfs and directories
|
||||
# my_df
|
||||
# my_df_u
|
||||
# my_df_u_lig
|
||||
# dup_muts
|
||||
|
||||
cat(paste0("Directories imported:"
|
||||
, "\ndatadir:", datadir
|
||||
, "\nindir:", indir
|
||||
, "\noutdir:", outdir
|
||||
, "\nplotdir:", plotdir))
|
||||
|
||||
cat(paste0("Variables imported:"
|
||||
, "\ndrug:", drug
|
||||
, "\ngene:", gene
|
||||
, "\ngene_match:", gene_match
|
||||
, "\nLength of upos:", length(upos)
|
||||
, "\nAngstrom symbol:", angstroms_symbol))
|
||||
|
||||
# clear excess variable
|
||||
rm(my_df, upos, dup_muts, my_df_u)
|
||||
|
||||
#=======================================================================
|
||||
#=======
|
||||
# output
|
||||
#=======
|
||||
# plot 1
|
||||
basic_bp_ligand = "basic_barplot_LIG.svg"
|
||||
plot_basic_bp_ligand = paste0(plotdir,"/", basic_bp_ligand)
|
||||
|
||||
# plot 2
|
||||
pos_count_ligand = "position_count_LIG.svg"
|
||||
plot_pos_count_ligand = paste0(plotdir, "/", pos_count_ligand)
|
||||
|
||||
#=======================================================================
|
||||
#================
|
||||
# Data for plots
|
||||
#================
|
||||
# REASSIGNMENT as necessary
|
||||
df = my_df_u_lig
|
||||
rm(my_df_u, my_df, upos, dup_muts)
|
||||
|
||||
# sanity checks
|
||||
str(df)
|
||||
#=====================================================================
|
||||
#****************
|
||||
# Plot 1:Count of stabilising and destabilsing muts
|
||||
#****************
|
||||
|
||||
#svg("basic_barplots_LIG.svg")
|
||||
svg(plot_basic_bp_ligand)
|
||||
print(paste0("plot1 filename:", basic_bp_ligand))
|
||||
|
||||
my_ats = 25 # axis text size
|
||||
my_als = 22 # axis label size
|
||||
|
||||
theme_set(theme_grey())
|
||||
|
||||
#--------------
|
||||
# start plot 1
|
||||
#--------------
|
||||
g = ggplot(df, aes(x = ligand_outcome))
|
||||
outPlot = g + geom_bar(aes(fill = ligand_outcome)
|
||||
, show.legend = TRUE) +
|
||||
geom_label(stat = "count"
|
||||
, aes(label = ..count..)
|
||||
, color = "black"
|
||||
, show.legend = FALSE
|
||||
, size = 10) +
|
||||
theme(axis.text.x = element_blank()
|
||||
, axis.title.x = element_blank()
|
||||
, axis.title.y = element_text(size=my_als)
|
||||
, axis.text.y = element_text(size = my_ats)
|
||||
, legend.position = c(0.73,0.8)
|
||||
, legend.text = element_text(size=my_als-2)
|
||||
, legend.title = element_text(size=my_als)
|
||||
, plot.title = element_blank()) +
|
||||
labs(title = ""
|
||||
, y = "Number of SNPs"
|
||||
#, fill="ligand_outcome"
|
||||
) +
|
||||
scale_fill_discrete(name = "Ligand Outcome"
|
||||
, labels = c("Destabilising", "Stabilising"))
|
||||
|
||||
print(outPlot)
|
||||
dev.off()
|
||||
|
||||
table(df$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
|
||||
|
||||
# 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_pos = 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 SNPs"
|
||||
, y = "Number of Sites")
|
||||
|
||||
print(outPlot_pos)
|
||||
dev.off()
|
||||
########################################################################
|
||||
# end of lig barplots
|
||||
########################################################################
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue