generated subcolour bps for PS
This commit is contained in:
parent
7e0bddd7d2
commit
2e53c8007a
3 changed files with 121 additions and 96 deletions
|
@ -3,105 +3,71 @@ setwd("~/git/LSHTM_analysis/scripts/plotting")
|
|||
getwd()
|
||||
|
||||
#########################################################
|
||||
# TASK:
|
||||
|
||||
# TASK: output barplot by position with each bar coloured by
|
||||
# its stability value and NO coloured positions indicated
|
||||
#########################################################
|
||||
#=======================================================================
|
||||
|
||||
########################################################################
|
||||
# Installing and loading required packages and functions #
|
||||
########################################################################
|
||||
############################################################
|
||||
# 1: Installing and loading required packages and functions
|
||||
#############################################################
|
||||
|
||||
source("Header_TT.R")
|
||||
#source("Header_TT.R")
|
||||
library(ggplot2)
|
||||
library(data.table)
|
||||
source("barplot_colour_function.R")
|
||||
source("plotting_data.R")
|
||||
|
||||
########################################################################
|
||||
# Read file: call script for combining df for PS #
|
||||
########################################################################
|
||||
#?????????????
|
||||
#
|
||||
# should return the following dfs, directories and variables
|
||||
# mut_pos_cols
|
||||
# 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_lig)
|
||||
########################################################
|
||||
#%% variable assignment: input and output paths & filenames
|
||||
drug = "pyrazinamide"
|
||||
gene = "pncA"
|
||||
gene_match = paste0(gene,"_p.")
|
||||
cat(gene_match)
|
||||
|
||||
#=============
|
||||
# directories
|
||||
#=============
|
||||
datadir = paste0("~/git/Data")
|
||||
indir = paste0(datadir, "/", drug, "/input")
|
||||
outdir = paste0("~/git/Data", "/", drug, "/output")
|
||||
|
||||
#======
|
||||
# input
|
||||
#======
|
||||
#in_filename = "mcsm_complex1_normalised.csv"
|
||||
in_filename_params = paste0(tolower(gene), "_all_params.csv")
|
||||
infile_params = paste0(outdir, "/", in_filename_params)
|
||||
cat(paste0("Input file:", infile_params) )
|
||||
|
||||
#=======
|
||||
# output
|
||||
#=======
|
||||
subcols_bp_duet = "barplot_subcols_DUET.svg"
|
||||
outPlot_subcols_bp_duet = paste0(outdir, "/plots/", subcols_bp_duet)
|
||||
print(paste0("plot will be in:", plotdir))
|
||||
bp_subcols_duet = "barplot_coloured_PS.svg"
|
||||
plot_bp_subcols_duet = paste0(plotdir, "/", bp_subcols_duet)
|
||||
|
||||
#%%===============================================================
|
||||
###########################
|
||||
# Read file: struct params
|
||||
###########################
|
||||
cat("Reading struct params including mcsm:", in_filename_params)
|
||||
|
||||
my_df = read.csv(infile_params
|
||||
#, stringsAsFactors = F
|
||||
, header = T)
|
||||
|
||||
cat("Input dimensions:", dim(my_df))
|
||||
|
||||
# clear variables
|
||||
rm(in_filename_params, infile_params)
|
||||
|
||||
# quick checks
|
||||
colnames(my_df)
|
||||
str(my_df)
|
||||
|
||||
# check for duplicate mutations
|
||||
if ( length(unique(my_df$mutationinformation)) != length(my_df$mutationinformation)){
|
||||
cat(paste0("CAUTION:", " Duplicate mutations identified"
|
||||
, "\nExtracting these..."))
|
||||
dup_muts = my_df[duplicated(my_df$mutationinformation),]
|
||||
dup_muts_nu = length(unique(dup_muts$mutationinformation))
|
||||
cat(paste0("\nDim of duplicate mutation df:", nrow(dup_muts)
|
||||
, "\nNo. of unique duplicate mutations:", dup_muts_nu
|
||||
, "\n\nExtracting df with unique mutations only"))
|
||||
my_df_u = my_df[!duplicated(my_df$mutationinformation),]
|
||||
}else{
|
||||
cat(paste0("No duplicate mutations detected"))
|
||||
my_df_u = my_df
|
||||
}
|
||||
|
||||
upos = unique(my_df_u$position)
|
||||
cat("Dim of clean df:"); cat(dim(my_df_u))
|
||||
cat("\nNo. of unique mutational positions:"); cat(length(upos))
|
||||
|
||||
########################################################################
|
||||
# end of data extraction and cleaning for plots #
|
||||
########################################################################
|
||||
#===================
|
||||
# Data for plots
|
||||
#===================
|
||||
# REASSIGNMENT as necessary
|
||||
df = my_df_u
|
||||
|
||||
rm(my_df)
|
||||
|
||||
# sanity checks
|
||||
str(df)
|
||||
upos = unique(df$position)
|
||||
|
||||
# should be a factor
|
||||
is.factor(my_df$duet_outcome)
|
||||
#[1] TRUE
|
||||
if (is.factor(df$duet_outcome)){
|
||||
print("duet_outcome is factor")
|
||||
}else{
|
||||
print("convert duet_outcome to factor")
|
||||
df$duet_outcome = as.factor(df$duet_outcome)
|
||||
}
|
||||
|
||||
is.factor(df$duet_outcome)
|
||||
|
||||
table(df$duet_outcome)
|
||||
|
||||
|
@ -167,12 +133,7 @@ my_yaxts = 15
|
|||
|
||||
#******************
|
||||
# generate plot: NO axis colours
|
||||
# no ordering of x-axis
|
||||
#******************
|
||||
# plot name and location
|
||||
print(paste0("plot will be in:", outdir))
|
||||
bp_subcols_duet = "barplot_coloured_PS.svg"
|
||||
plot_bp_subcols_duet = paste0(outdir, "/plots/", bp_subcols_duet)
|
||||
print(paste0("plot name:", plot_bp_subcols_duet))
|
||||
|
||||
svg(plot_bp_subcols_duet, width = 26, height = 4)
|
||||
|
@ -192,7 +153,8 @@ outPlot = g +
|
|||
, vjust = 0)
|
||||
, axis.title.x = element_text(size = my_xaxts)
|
||||
, axis.title.y = element_text(size = my_yaxts ) ) +
|
||||
labs(title = my_title
|
||||
labs(title = ""
|
||||
#title = my_title
|
||||
, x = "position"
|
||||
, y = "Frequency")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue