sourcing plotting_data for subcols_axis_PS
This commit is contained in:
parent
b5ad53f7d1
commit
7e0bddd7d2
4 changed files with 110 additions and 90 deletions
|
@ -3,52 +3,92 @@ setwd("~/git/LSHTM_analysis/scripts/plotting")
|
|||
getwd()
|
||||
|
||||
#########################################################
|
||||
# TASK:
|
||||
|
||||
# TASK: output barplot by position with each bar coloured by
|
||||
# its stability value and active site positions indicated
|
||||
# according to colour specified in "subcols_axis_PS.R"
|
||||
#########################################################
|
||||
|
||||
#=======================================================================
|
||||
|
||||
############################################################
|
||||
# 1: Installing and loading required packages and functions
|
||||
############################################################
|
||||
|
||||
#source("Header_TT.R")
|
||||
library(ggplot2)
|
||||
library(data.table)
|
||||
source("barplot_colour_function.R")
|
||||
|
||||
############################################################
|
||||
# 2: Read file: struct params data with columns containing
|
||||
# colours for axis labels
|
||||
############################################################
|
||||
#source("subcols_axis.R")
|
||||
source("subcols_axis_PS.R")
|
||||
|
||||
# this should return
|
||||
# should return the following dfs, directories and variables
|
||||
# mut_pos_cols
|
||||
# my_df
|
||||
# my_df_u: df with unique mutations
|
||||
# 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
|
||||
# "mut_pos_cols" is just for inspection in case you need to cross check
|
||||
rm(my_df, upos, dup_muts, my_df_u_lig)
|
||||
#=======================================================================
|
||||
#================
|
||||
# Inspecting mut_pos_cols
|
||||
# position numbers and colours
|
||||
# open file from deskptop ("sample_axis_cols") for cross checking
|
||||
# open file from desktop ("sample_axis_cols") for cross checking
|
||||
#================
|
||||
|
||||
table(mut_pos_cols$lab_bg)
|
||||
sum( table(mut_pos_cols$lab_bg) ) == nrow(mut_pos_cols) # should be True
|
||||
|
||||
check_lab_bg = sum( table(mut_pos_cols$lab_bg) ) == nrow(mut_pos_cols) # should be True
|
||||
check_lab_bg
|
||||
|
||||
table(mut_pos_cols$lab_bg2)
|
||||
sum( table(mut_pos_cols$lab_bg2) ) == nrow(mut_pos_cols) # should be True
|
||||
check_lab_bg2 = sum( table(mut_pos_cols$lab_bg2) ) == nrow(mut_pos_cols) # should be True
|
||||
check_lab_bg2
|
||||
|
||||
table(mut_pos_cols$lab_fg)
|
||||
sum( table(mut_pos_cols$lab_fg) ) == nrow(mut_pos_cols) # should be True
|
||||
check_lab_fg = sum( table(mut_pos_cols$lab_fg) ) == nrow(mut_pos_cols) # should be True
|
||||
check_lab_fg
|
||||
|
||||
# sanity checks:
|
||||
if (check_lab_bg && check_lab_bg2 && check_lab_fg) {
|
||||
print("PASS: No. of assigned colours match length")
|
||||
}else{
|
||||
print("FAIL: length of assigned colours mismatch")
|
||||
quit()
|
||||
}
|
||||
|
||||
# very important!
|
||||
my_axis_colours = mut_pos_cols$lab_fg
|
||||
|
||||
# now clear mut_pos_cols
|
||||
rm(mut_pos_cols)
|
||||
rm(mut_pos_cols)
|
||||
#=======================================================================
|
||||
#================
|
||||
# Data for plots
|
||||
#================
|
||||
# REASSIGNMENT as necessary
|
||||
df = my_df_u
|
||||
|
||||
# sanity checks
|
||||
str(df)
|
||||
|
||||
###########################
|
||||
# 2: Plot: DUET scores
|
||||
###########################
|
||||
|
||||
#==========================
|
||||
# Plot 2: Barplot with scores (unordered)
|
||||
# corresponds to duet_outcome
|
||||
|
@ -62,20 +102,12 @@ rm(mut_pos_cols)
|
|||
# will require generating the colour scale separately.
|
||||
#============================
|
||||
# sanity checks
|
||||
upos = unique(my_df$position)
|
||||
upos = unique(df$position)
|
||||
|
||||
table(my_df$duet_outcome)
|
||||
table(my_df_u$duet_outcome)
|
||||
table(df$duet_outcome)
|
||||
table(df$duet_outcome)
|
||||
|
||||
#===========================
|
||||
# Data preparation for plots
|
||||
#===========================
|
||||
# REASSIGNMENT as necessary
|
||||
df <- my_df_u
|
||||
rm(my_df, my_df_u)
|
||||
|
||||
# add frequency of positions
|
||||
library(data.table)
|
||||
# add frequency of positions (from lib data.table)
|
||||
setDT(df)[, pos_count := .N, by = .(position)]
|
||||
|
||||
# this is cummulative
|
||||
|
@ -93,8 +125,8 @@ snp_count = sort(unique(snpsBYpos_df$snpsBYpos))
|
|||
|
||||
# sanity checks
|
||||
# should be a factor
|
||||
df$duet_outcome = as.factor(df$duet_outcome)
|
||||
is.factor(df$duet_outcome)
|
||||
#TRUE
|
||||
|
||||
table(df$duet_outcome)
|
||||
|
||||
|
@ -116,13 +148,14 @@ tapply(df$duet_scaled, df$duet_outcome, max)
|
|||
|
||||
# check unique values in normalised data
|
||||
u = unique(df$duet_scaled)
|
||||
cat("No. of unique values in normalised data:", length(u))
|
||||
|
||||
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
# Run this section if rounding is to be used
|
||||
# specify number for rounding
|
||||
n = 3
|
||||
df$duet_scaledR = round(df$duet_scaled, n)
|
||||
ur = unique(df$duet_scaledR)
|
||||
#n = 3
|
||||
#df$duet_scaledR = round(df$duet_scaled, n)
|
||||
#ur = unique(df$duet_scaledR)
|
||||
|
||||
# create an extra column called group which contains the "gp name and score"
|
||||
# so colours can be generated for each unique values in this column
|
||||
|
@ -158,7 +191,8 @@ my_yats = 18
|
|||
#******************
|
||||
# plot name and location
|
||||
# outdir/ (should be imported from reading file)
|
||||
print(paste0("plot will be in:", outdir))
|
||||
plotdir = paste0(outdir, "/", "plots") #should be imported from reading file
|
||||
print(paste0("plot will be in:", plotdir))
|
||||
|
||||
bp_aa_subcols_duet = "barplot_acoloured_PS.svg"
|
||||
plot_bp_aa_subcols_duet = paste0(outdir, "/plots/", bp_aa_subcols_duet)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue