moved functions/ in the scripts dir
This commit is contained in:
parent
0c3645705d
commit
f6259aa517
6 changed files with 4 additions and 4 deletions
|
@ -1,126 +0,0 @@
|
|||
#!/usr/bin/env Rscript
|
||||
#########################################################
|
||||
# TASK: formatting data that will be used for various plots
|
||||
#########################################################
|
||||
# load libraries and functions
|
||||
library(data.table)
|
||||
library(dplyr)
|
||||
#========================================================
|
||||
# plotting_data(): formatting data for plots
|
||||
# input args:
|
||||
## input csv file
|
||||
## lig cut off dist, default = 10 Ang
|
||||
# output: list of 4 dfs, that need to be decompressed
|
||||
## my_df
|
||||
## my_df_u
|
||||
## my_df_u_lig
|
||||
## dup_muts
|
||||
#========================================================
|
||||
plotting_data <- function(infile_params, mcsm_lig_cutoff = 10) {
|
||||
my_df = data.frame()
|
||||
my_df_u = data.frame()
|
||||
my_df_u_lig = data.frame()
|
||||
dup_muts = data.frame()
|
||||
|
||||
cat(paste0("\nInput file to prepare for plotting:", infile_params, "\n") )
|
||||
|
||||
#===========================
|
||||
# Read file: struct params
|
||||
#===========================
|
||||
my_df = read.csv(infile_params, header = T)
|
||||
|
||||
cat("\nInput dimensions:", dim(my_df))
|
||||
|
||||
#==================================
|
||||
# add foldx outcome category
|
||||
# and foldx scaled values
|
||||
|
||||
# This will enable to always have these variables available
|
||||
# when calling for plots
|
||||
#==================================
|
||||
|
||||
#------------------------------
|
||||
# adding foldx scaled values
|
||||
# scale data b/w -1 and 1
|
||||
#------------------------------
|
||||
n = which(colnames(my_df) == "ddg"); n
|
||||
|
||||
my_min = min(my_df[,n]); my_min
|
||||
my_max = max(my_df[,n]); my_max
|
||||
|
||||
my_df$foldx_scaled = ifelse(my_df[,n] < 0
|
||||
, my_df[,n]/abs(my_min)
|
||||
, my_df[,n]/my_max)
|
||||
# sanity check
|
||||
my_min = min(my_df$foldx_scaled); my_min
|
||||
my_max = max(my_df$foldx_scaled); my_max
|
||||
|
||||
if (my_min == -1 && my_max == 1){
|
||||
cat("\nPASS: foldx ddg successfully scaled b/w -1 and 1"
|
||||
, "\nProceeding with assigning foldx outcome category")
|
||||
}else{
|
||||
cat("\nFAIL: could not scale foldx ddg values"
|
||||
, "Aborting!\n")
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
# adding foldx outcome category
|
||||
# ddg<0 = "Stabilising" (-ve)
|
||||
#------------------------------
|
||||
c1 = table(my_df$ddg < 0)
|
||||
my_df$foldx_outcome = ifelse(my_df$ddg < 0, "Stabilising", "Destabilising")
|
||||
c2 = table(my_df$ddg < 0)
|
||||
|
||||
if ( all(c1 == c2) ){
|
||||
cat("\nPASS: foldx outcome successfully created")
|
||||
}else{
|
||||
cat("\nFAIL: foldx outcome could not be created. Aborting!\n")
|
||||
exit()
|
||||
}
|
||||
|
||||
#==================================
|
||||
# extract unique mutation entries
|
||||
#==================================
|
||||
|
||||
# check for duplicate mutations
|
||||
if ( length(unique(my_df$mutationinformation)) != length(my_df$mutationinformation)){
|
||||
cat(paste0("\nCAUTION:", " Duplicate mutations identified"
|
||||
, "\nExtracting these...\n"))
|
||||
#cat(my_df[duplicated(my_df$mutationinformation),])
|
||||
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\n"))
|
||||
my_df_u = my_df[!duplicated(my_df$mutationinformation),]
|
||||
}else{
|
||||
cat(paste0("\nNo duplicate mutations detected\n"))
|
||||
my_df_u = my_df
|
||||
}
|
||||
|
||||
upos = unique(my_df_u$position)
|
||||
cat("\nDim of clean df:"); cat(dim(my_df_u), "\n")
|
||||
cat("\nNo. of unique mutational positions:"); cat(length(upos), "\n")
|
||||
|
||||
#===============================================
|
||||
# extract mutations <10 Angstroms and symbol
|
||||
#===============================================
|
||||
table(my_df_u$ligand_distance<mcsm_lig_cutoff)
|
||||
|
||||
my_df_u_lig = my_df_u[my_df_u$ligand_distance <mcsm_lig_cutoff,]
|
||||
|
||||
cat(paste0("There are ", nrow(my_df_u_lig), " sites lying within 10\u212b of the ligand\n"))
|
||||
|
||||
# return list of DFs
|
||||
|
||||
#return(list(my_df, my_df_u, my_df_u_lig, dup_muts))
|
||||
#df_names = c("my_df", "my_df_u", "my_df_u_lig", "dup_muts")
|
||||
all_df = list(my_df, my_df_u, my_df_u_lig, dup_muts)
|
||||
#all_df = Map(setNames, all_df, df_names)
|
||||
|
||||
return(all_df)
|
||||
}
|
||||
|
||||
########################################################################
|
||||
# end of data extraction and cleaning for plots #
|
||||
########################################################################
|
Loading…
Add table
Add a link
Reference in a new issue