added scripts
This commit is contained in:
parent
dd69da01f6
commit
23b4f06017
10 changed files with 147 additions and 1014 deletions
|
@ -1,11 +1,7 @@
|
|||
#!/usr/bin/env Rscript
|
||||
|
||||
#source("~/git/LSHTM_analysis/config/alr.R")
|
||||
source("~/git/LSHTM_analysis/config/embb.R")
|
||||
#source("~/git/LSHTM_analysis/config/katg.R")
|
||||
#source("~/git/LSHTM_analysis/config/gid.R")
|
||||
#source("~/git/LSHTM_analysis/config/pnca.R")
|
||||
#source("~/git/LSHTM_analysis/config/rpob.R")
|
||||
source("~/git/LSHTM_analysis/config/gid.R")
|
||||
source("~/git/LSHTM_analysis/scripts/plotting/get_plotting_dfs.R")
|
||||
|
||||
#########################################################
|
||||
# TASK: Replace B-factors in the pdb file with the mean
|
||||
# normalised stability values.
|
||||
|
@ -20,31 +16,12 @@ source("~/git/LSHTM_analysis/config/embb.R")
|
|||
|
||||
#########################################################
|
||||
# working dir and loading libraries
|
||||
getwd()
|
||||
setwd("~/git/LSHTM_analysis/scripts/plotting")
|
||||
cat(c(getwd(),"\n"))
|
||||
|
||||
#source("~/git/LSHTM_analysis/scripts/Header_TT.R")
|
||||
library(bio3d)
|
||||
require("getopt", quietly = TRUE) # cmd parse arguments
|
||||
#========================================================
|
||||
#drug = ""
|
||||
#gene = ""
|
||||
|
||||
# # command line args
|
||||
# spec = matrix(c(
|
||||
# "drug" , "d", 1, "character",
|
||||
# "gene" , "g", 1, "character"
|
||||
# ), byrow = TRUE, ncol = 4)
|
||||
#
|
||||
# opt = getopt(spec)
|
||||
#
|
||||
# drug = opt$drug
|
||||
# gene = opt$gene
|
||||
#
|
||||
# if(is.null(drug)|is.null(gene)) {
|
||||
# stop("Missing arguments: --drug and --gene must both be specified (case-sensitive)")
|
||||
# }
|
||||
#========================================================
|
||||
cat(gene)
|
||||
gene_match = paste0(gene,"_p."); cat(gene_match)
|
||||
|
@ -56,29 +33,25 @@ cat(gene_match)
|
|||
datadir = paste0("~/git/Data")
|
||||
indir = paste0(datadir, "/", drug, "/input")
|
||||
outdir = paste0("~/git/Data", "/", drug, "/output")
|
||||
#outdir_plots = paste0("~/git/Data", "/", drug, "/output/plots")
|
||||
outdir_plots = paste0("~/git/Writing/thesis/images/results/", tolower(gene))
|
||||
#outdir_plots = paste0("~/git/Writing/thesis/images/results/", tolower(gene))
|
||||
|
||||
#======
|
||||
# input
|
||||
#======
|
||||
in_filename_pdb = paste0(tolower(gene), "_complex.pdb")
|
||||
#in_filename_pdb = "/home/tanu/git/Writing/thesis/images/results/gid/str_figures/gid_complex_copy_arpeg.pdb"
|
||||
infile_pdb = paste0(indir, "/", in_filename_pdb)
|
||||
cat(paste0("Input file:", infile_pdb) )
|
||||
|
||||
#in_filename_mean_stability = paste0(tolower(gene), "_mean_stability.csv")
|
||||
#infile_mean_stability = paste0(outdir, "/", in_filename_mean_stability)
|
||||
|
||||
in_filename_mean_stability = paste0(tolower(gene), "_mean_ens_stability.csv")
|
||||
infile_mean_stability = paste0(outdir_plots, "/", in_filename_mean_stability)
|
||||
cat(paste0("Input file:", infile_mean_stability) )
|
||||
|
||||
#=======
|
||||
# output
|
||||
#=======
|
||||
outdir_images = paste0("~/git/Writing/thesis/images/results/", tolower(gene), "/")
|
||||
cat("plots will output to:", outdir_images)
|
||||
|
||||
#out_filename_duet_mspdb = paste0(tolower(gene), "_complex_bduet_ms.pdb")
|
||||
out_filename_duet_mspdb = paste0(tolower(gene), "_complex_b_stab_ms.pdb")
|
||||
outfile_duet_mspdb = paste0(outdir_plots, "/", out_filename_duet_mspdb)
|
||||
outfile_duet_mspdb = paste0(outdir_images, out_filename_duet_mspdb)
|
||||
print(paste0("Output file:", outfile_duet_mspdb))
|
||||
|
||||
#%%===============================================================
|
||||
|
@ -88,8 +61,31 @@ print(paste0("Output file:", outfile_duet_mspdb))
|
|||
# Read file: average stability values
|
||||
# or mcsm_normalised file
|
||||
###########################
|
||||
my_df <- read.csv(infile_mean_stability, header = T)
|
||||
str(my_df)
|
||||
my_df_raw = merged_df3[, c("position", "avg_stability", "avg_stability_scaled")]
|
||||
|
||||
# avg by position on the SCALED values
|
||||
my_df <- my_df_raw %>%
|
||||
group_by(position) %>%
|
||||
summarize(avg_stab_sc_pos = mean(avg_stability_scaled))
|
||||
|
||||
max(my_df$avg_stab_sc_pos)
|
||||
min(my_df$avg_stab_sc_pos)
|
||||
#============================================================
|
||||
# # scale b/w -1 and 1
|
||||
# duet_min = min(my_df_by_position['avg_stab_sc_pos'])
|
||||
# duet_max = max(my_df_by_position['avg_stab_sc_pos'])
|
||||
#
|
||||
# # scale the averaged_duet values
|
||||
# my_df_by_position['avg_stab_sc_pos_scaled'] = lapply(my_df_by_position['avg_stab_sc_pos']
|
||||
# , function(x) ifelse(x < 0, x/abs(duet_min), x/duet_max))
|
||||
#
|
||||
# cat(paste0('Average duet scores:\n', head(my_df_by_position['avg_stab_sc_pos_scaled'])
|
||||
# , '\n---------------------------------------------------------------'
|
||||
# , '\nScaled duet scores:\n', head(my_df_by_position['avg_stab_sc_pos_scaled'])))
|
||||
#
|
||||
# min(my_df_by_position['avg_stab_sc_pos_scaled'])
|
||||
# max(my_df_by_position['avg_stab_sc_pos_scaled'])
|
||||
#============================================================
|
||||
|
||||
#############
|
||||
# Read pdb
|
||||
|
@ -104,8 +100,6 @@ my_pdb = read.pdb(infile_pdb
|
|||
, hex = FALSE
|
||||
, verbose = TRUE)
|
||||
|
||||
rm(in_filename_mean_stability, in_filename_pdb)
|
||||
|
||||
# assign separately for duet and ligand
|
||||
my_pdb_duet = my_pdb
|
||||
|
||||
|
@ -113,9 +107,6 @@ my_pdb_duet = my_pdb
|
|||
# Replacing B factor with mean stability scores
|
||||
# within the respective dfs
|
||||
#==========================================================
|
||||
# extract atom list into a variable
|
||||
# since in the list this corresponds to data frame, variable will be a df
|
||||
#df_duet = my_pdb_duet[[1]]
|
||||
df_duet= my_pdb_duet[['atom']]
|
||||
|
||||
# make a copy: required for downstream sanity checks
|
||||
|
@ -156,35 +147,22 @@ plot(density(df_duet$b)
|
|||
#=============
|
||||
|
||||
#hist(my_df$averaged_duet
|
||||
hist(my_df$avg_stability_scaled_pos_scaled
|
||||
hist(my_df$avg_stab_sc_pos
|
||||
, xlab = ""
|
||||
, main = "mean stability values")
|
||||
|
||||
#plot(density(my_df$averaged_duet)
|
||||
plot(density(my_df$avg_stability_scaled_pos_scaled)
|
||||
plot(density(my_df$avg_stab_sc_pos)
|
||||
, xlab = ""
|
||||
, main = "mean stability values")
|
||||
|
||||
#==============
|
||||
# Row 3 plots: replaced B-factors with mean stability values
|
||||
# After actual replacement in the b factor column
|
||||
#===============
|
||||
################################################################
|
||||
#=========
|
||||
# step 0_P1: DONT RUN once you have double checked the matched output
|
||||
#=========
|
||||
# sanity check: match and assign to a separate column to double check
|
||||
# colnames(my_df)
|
||||
# df_duet$duet_scaled = my_df$averge_duet_scaled[match(df_duet$resno, my_df$position)]
|
||||
|
||||
#=========
|
||||
# step 1_P1
|
||||
#=========
|
||||
# Be brave and replace in place now (don"t run sanity check)
|
||||
# this makes all the B-factor values in the non-matched positions as NA
|
||||
|
||||
#df_duet$b = my_df$averaged_duet_scaled[match(df_duet$resno, my_df$position)]
|
||||
df_duet$b = my_df$avg_stability_scaled_pos_scaled[match(df_duet$resno, my_df$position)]
|
||||
df_duet$b = my_df$avg_stab_sc_pos[match(df_duet$resno, my_df$position)]
|
||||
|
||||
#=========
|
||||
# step 2_P1
|
||||
|
@ -198,26 +176,6 @@ sum(df_duet$b == 0)
|
|||
# replace all NA in b factor with 0
|
||||
na_rep = 2
|
||||
df_duet$b[is.na(df_duet$b)] = na_rep
|
||||
|
||||
# # sanity check: should be 0 and True
|
||||
# # duet
|
||||
# if ( (sum(df_duet$b == na_rep) == b_na_duet) {
|
||||
# print ("PASS: NA's replaced with 0s successfully in df_duet and df_lig")
|
||||
# } else {
|
||||
# print("FAIL: NA replacement in df_duet NOT successful")
|
||||
# quit()
|
||||
# }
|
||||
#
|
||||
# max(df_duet$b); min(df_duet$b)
|
||||
#
|
||||
# # sanity checks: should be True
|
||||
# if( (max(df_duet$b) == max(my_df$avg_stability_scaled_pos_scaled)) & (min(df_duet$b) == min(my_df$avg_stability_scaled_pos_scaled)) ){
|
||||
# print("PASS: B-factors replaced correctly in df_duet")
|
||||
# } else {
|
||||
# print ("FAIL: To replace B-factors in df_duet")
|
||||
# quit()
|
||||
# }
|
||||
|
||||
#=========
|
||||
# step 3_P1
|
||||
#=========
|
||||
|
@ -269,12 +227,4 @@ mtext(text = paste0(tolower(gene), ": stability distribution")
|
|||
, side = 3
|
||||
, line = 0
|
||||
, outer = TRUE)
|
||||
#============================================
|
||||
|
||||
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
# NOTE: This replaced B-factor distribution has the same
|
||||
# x-axis as the PredAff normalised values, but the distribution
|
||||
# is affected since 0 is overinflated/or hs an additional blip because
|
||||
# of the positions not associated with resistance. This is because all the positions
|
||||
# where there are no SNPs have been assigned 0???
|
||||
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
#============================================
|
Loading…
Add table
Add a link
Reference in a new issue