154 lines
4.1 KiB
R
154 lines
4.1 KiB
R
getwd()
|
|
setwd("~/git/LSHTM_analysis/mcsm_analysis/pyrazinamide/scripts/plotting")
|
|
getwd()
|
|
|
|
########################################################################
|
|
# Installing and loading required packages #
|
|
########################################################################
|
|
|
|
source("../Header_TT.R")
|
|
|
|
########################################################################
|
|
# Read file: call script for combining df for lig #
|
|
########################################################################
|
|
|
|
source("../combining_two_df_lig.R")
|
|
|
|
#---------------------- PAY ATTENTION
|
|
# the above changes the working dir
|
|
#[1] "git/LSHTM_analysis/mcsm_analysis/pyrazinamide/scripts"
|
|
#---------------------- PAY ATTENTION
|
|
|
|
#==========================
|
|
# This will return:
|
|
|
|
# df with NA:
|
|
# merged_df2
|
|
# merged_df3
|
|
|
|
# df without NA:
|
|
# merged_df2_comp
|
|
# merged_df3_comp
|
|
#===========================
|
|
|
|
###########################
|
|
# Data for Lig plots
|
|
# you need merged_df3
|
|
# or
|
|
# merged_df3_comp
|
|
# since these have unique SNPs
|
|
# I prefer to use the merged_df3
|
|
# because using the _comp dataset means
|
|
# we lose some muts and at this level, we should use
|
|
# as much info as available
|
|
###########################
|
|
|
|
# uncomment as necessary
|
|
#%%%%%%%%%%%%%%%%%%%%%%%%
|
|
# REASSIGNMENT
|
|
my_df = merged_df3
|
|
#my_df = merged_df3_comp
|
|
#%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
# delete variables not required
|
|
rm(merged_df2, merged_df2_comp, merged_df3, merged_df3_comp)
|
|
|
|
# quick checks
|
|
colnames(my_df)
|
|
str(my_df)
|
|
|
|
#############################
|
|
# Extra sanity check:
|
|
# for mcsm_lig ONLY
|
|
# Dis_lig_Ang should be <10
|
|
#############################
|
|
|
|
if (max(my_df$Dis_lig_Ang) < 10){
|
|
print ("Sanity check passed: lig data is <10Ang")
|
|
}else{
|
|
print ("Error: data should be filtered to be within 10Ang")
|
|
}
|
|
########################################################################
|
|
# end of data extraction and cleaning for plots #
|
|
########################################################################
|
|
|
|
#==========================
|
|
# Plot: Barplot with scores (unordered)
|
|
# corresponds to Lig_outcome
|
|
# Stacked Barplot with colours: Lig_outcome @ position coloured by
|
|
# Lig_outcome. This is a barplot where each bar corresponds
|
|
# to a SNP and is coloured by its corresponding Lig_outcome.
|
|
#============================
|
|
|
|
#===================
|
|
# Data for plots
|
|
#===================
|
|
|
|
#%%%%%%%%%%%%%%%%%%%%%%%%
|
|
# REASSIGNMENT
|
|
df = my_df
|
|
#%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
rm(my_df)
|
|
|
|
# sanity checks
|
|
upos = unique(my_df$Position)
|
|
|
|
# should be a factor
|
|
is.factor(df$Lig_outcome)
|
|
#TRUE
|
|
|
|
table(df$Lig_outcome)
|
|
|
|
# should be -1 and 1: may not be in this case because you have filtered the data
|
|
# FIXME: normalisation before or after filtering?
|
|
min(df$ratioPredAff) #
|
|
max(df$ratioPredAff) #
|
|
|
|
# sanity checks
|
|
tapply(df$ratioPredAff, df$Lig_outcome, min)
|
|
tapply(df$ratioPredAff, df$Lig_outcome, max)
|
|
|
|
#******************
|
|
# generate plot
|
|
#******************
|
|
|
|
# set output dir for plots
|
|
getwd()
|
|
setwd("~/git/Data/pyrazinamide/output/plots")
|
|
getwd()
|
|
|
|
my_title = "Ligand affinity"
|
|
|
|
# axis label size
|
|
my_xaxls = 13
|
|
my_yaxls = 15
|
|
|
|
# axes text size
|
|
my_xaxts = 15
|
|
my_yaxts = 15
|
|
|
|
# no ordering of x-axis
|
|
g = ggplot(df, aes(factor(Position, ordered = T)))
|
|
g +
|
|
geom_bar(aes(fill = Lig_outcome), colour = "grey") +
|
|
theme( axis.text.x = element_text(size = my_xaxls
|
|
, angle = 90
|
|
, hjust = 1
|
|
, vjust = 0.4)
|
|
, axis.text.y = element_text(size = my_yaxls
|
|
, angle = 0
|
|
, hjust = 1
|
|
, vjust = 0)
|
|
, axis.title.x = element_text(size = my_xaxts)
|
|
, axis.title.y = element_text(size = my_yaxts ) ) +
|
|
labs(title = my_title
|
|
, x = "Position"
|
|
, y = "Frequency")
|
|
|
|
# for sanity and good practice
|
|
rm(df)
|
|
#======================= end of plot
|
|
# axis colours labels
|
|
# https://stackoverflow.com/questions/38862303/customize-ggplot2-axis-labels-with-different-colors
|
|
# https://stackoverflow.com/questions/56543485/plot-coloured-boxes-around-axis-label
|