added shorter scripts for each different processing for plots to make it wasire to read code
This commit is contained in:
parent
96129ddc34
commit
dc5b5e2f11
6 changed files with 1292 additions and 0 deletions
80
scripts/plotting/coloured_bp_data.R
Normal file
80
scripts/plotting/coloured_bp_data.R
Normal file
|
@ -0,0 +1,80 @@
|
|||
#!/usr/bin/env Rscript
|
||||
#################################################################
|
||||
# TASK: Script to add bp colours ~ barplot heatmap
|
||||
#################################################################
|
||||
|
||||
my_df = merged_df3
|
||||
|
||||
cols_to_select = c("mutationinformation", "drtype"
|
||||
, "wild_type"
|
||||
, "position"
|
||||
, "mutant_type"
|
||||
, "chain", "ligand_id", "ligand_distance"
|
||||
, "duet_stability_change", "duet_outcome", "duet_scaled"
|
||||
, "ligand_affinity_change", "ligand_outcome", "affinity_scaled"
|
||||
, "ddg_foldx", "foldx_scaled", "foldx_outcome"
|
||||
, "deepddg", "deepddg_outcome" # comment out as not available for pnca
|
||||
, "asa", "rsa", "rd_values", "kd_values"
|
||||
, "af", "or_mychisq", "pval_fisher"
|
||||
, "or_fisher", "or_logistic", "pval_logistic"
|
||||
, "wt_prop_water", "mut_prop_water", "wt_prop_polarity", "mut_prop_polarity"
|
||||
, "wt_calcprop", "mut_calcprop")
|
||||
|
||||
#=======================
|
||||
# Data for sub colours
|
||||
# barplot: PS
|
||||
#=======================
|
||||
|
||||
cat("\nNo. of cols to select:", length(cols_to_select))
|
||||
|
||||
subcols_df_ps = my_df[, cols_to_select]
|
||||
|
||||
cat("\nNo of unique positions for ps:"
|
||||
, length(unique(subcols_df_ps$position)))
|
||||
|
||||
# add count_pos col that counts the no. of nsSNPS at a position
|
||||
setDT(subcols_df_ps)[, pos_count := .N, by = .(position)]
|
||||
|
||||
# should be a factor
|
||||
if (is.factor(subcols_df_ps$duet_outcome)){
|
||||
cat("\nDuet_outcome is factor")
|
||||
table(subcols_df_ps$duet_outcome)
|
||||
}else{
|
||||
cat("\nConverting duet_outcome to factor")
|
||||
subcols_df_ps$duet_outcome = as.factor(subcols_df_ps$duet_outcome)
|
||||
table(subcols_df_ps$duet_outcome)
|
||||
}
|
||||
|
||||
# should be -1 and 1
|
||||
min(subcols_df_ps$duet_scaled)
|
||||
max(subcols_df_ps$duet_scaled)
|
||||
|
||||
tapply(subcols_df_ps$duet_scaled, subcols_df_ps$duet_outcome, min)
|
||||
tapply(subcols_df_ps$duet_scaled, subcols_df_ps$duet_outcome, max)
|
||||
|
||||
# check unique values in normalised data
|
||||
cat("\nNo. of unique values in duet scaled, no rounding:"
|
||||
, length(unique(subcols_df_ps$duet_scaled)))
|
||||
|
||||
# No rounding
|
||||
my_grp = subcols_df_ps$duet_scaled; length(my_grp)
|
||||
|
||||
# Add rounding is to be used
|
||||
n = 3
|
||||
subcols_df_ps$duet_scaledR = round(subcols_df_ps$duet_scaled, n)
|
||||
|
||||
cat("\nNo. of unique values in duet scaled", n, "places rounding:"
|
||||
, length(unique(subcols_df_ps$duet_scaledR)))
|
||||
|
||||
my_grp_r = subcols_df_ps$duet_scaledR # rounding
|
||||
|
||||
# Add grp cols
|
||||
subcols_df_ps$group <- paste0(subcols_df_ps$duet_outcome, "_", my_grp, sep = "")
|
||||
subcols_df_ps$groupR <- paste0(subcols_df_ps$duet_outcome, "_", my_grp_r, sep = "")
|
||||
|
||||
# Call the function to create the palette based on the group defined above
|
||||
subcols_ps <- ColourPalleteMulti(subcols_df_ps, "duet_outcome", "my_grp")
|
||||
subcolsR_ps <- ColourPalleteMulti(subcols_df_ps, "duet_outcome", "my_grp_r")
|
||||
|
||||
cat("Colour palette generated for my_grp: ", length(subcols_ps), " colours")
|
||||
cat("Colour palette generated for my_grp_r: ", length(subcolsR_ps), " colours")
|
67
scripts/plotting/corr_data.R
Normal file
67
scripts/plotting/corr_data.R
Normal file
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env Rscript
|
||||
#########################################################
|
||||
# TASK: Script to format data for corr plots
|
||||
#########################################################
|
||||
|
||||
#=================================================
|
||||
# Data for Corrplots
|
||||
#=================================================
|
||||
cat("\n=========================================="
|
||||
, "\nCORR PLOTS data: ALL params"
|
||||
, "\n=========================================")
|
||||
|
||||
# use data
|
||||
#merged_df2
|
||||
|
||||
#----------------------------
|
||||
# columns for corr plots:PS
|
||||
#----------------------------
|
||||
# NOTE: you can add mcsm_ppi column as well, and it will only select what it can find!
|
||||
big_df_colnames = data.frame(names(merged_df2))
|
||||
|
||||
corr_cols_select <- c("mutationinformation", drug, "mutation_info_labels"
|
||||
, "duet_stability_change", "ligand_affinity_change", "ddg_foldx", "asa", "rsa"
|
||||
, "rd_values", "kd_values", "log10_or_mychisq", "neglog_pval_fisher","af"
|
||||
, "deepddg", "ddg_dynamut", "ddg_dynamut2", "mcsm_na_affinity"
|
||||
, "ddg_encom", "dds_encom", "ddg_mcsm", "ddg_sdm", "ddg_duet", "ligand_distance")
|
||||
|
||||
#===========================
|
||||
# Corr data for plots: PS
|
||||
# big_df ps: ~ merged_df2
|
||||
#===========================
|
||||
|
||||
corr_df_m2 = merged_df2[,colnames(merged_df2)%in%corr_cols_select]
|
||||
|
||||
#===========================
|
||||
# Corr data for plots: PS
|
||||
# short_df ps: ~merged_df3
|
||||
#===========================
|
||||
|
||||
corr_df_m3 = corr_df_m2[!duplicated(corr_df_m2$mutationinformation),]
|
||||
|
||||
na_or = sum(is.na(corr_df_m3$log10_or_mychisq))
|
||||
check1 = nrow(corr_df_m3) - na_or; check1
|
||||
|
||||
if (nrow(corr_df_m3) == nrow(merged_df3) && nrow(merged_df3_comp) == check1) {
|
||||
cat( "\nPASS: No. of rows for corr_df_m3 match"
|
||||
, "\nPASS: No. of OR values checked: " , check1)
|
||||
} else {
|
||||
cat("\nFAIL: Numbers mismatch:"
|
||||
, "\nExpected nrows: ", nrow(merged_df3)
|
||||
, "\nGot: ", nrow(corr_df_m3)
|
||||
, "\nExpected OR values: ", nrow(merged_df3_comp)
|
||||
, "\nGot: ", check1)
|
||||
}
|
||||
|
||||
cat("\nCorr Data created:"
|
||||
, "\n==================================="
|
||||
, "\ncorr_df_m2: created from merged_df2"
|
||||
, "\n==================================="
|
||||
, "\nnrows:", nrow(corr_df_m2)
|
||||
, "\nncols:", ncol(corr_df_m2)
|
||||
, "\n==================================="
|
||||
, "\ncorr_df_m3: created from merged_df3"
|
||||
, "\n==================================="
|
||||
, "\nnrows:", nrow(corr_df_m3)
|
||||
, "\nncols:", ncol(corr_df_m3)
|
||||
)
|
416
scripts/plotting/dm_om_data.R
Normal file
416
scripts/plotting/dm_om_data.R
Normal file
|
@ -0,0 +1,416 @@
|
|||
#!/usr/bin/env Rscript
|
||||
#########################################################
|
||||
# TASK: Script to format data for dm om plots:
|
||||
# generating LF data
|
||||
# sourced by get_plotting_dfs.R
|
||||
#########################################################
|
||||
##========================================================================
|
||||
# cols to select:
|
||||
# THINK: whu
|
||||
|
||||
comb_df <- merged_df3[, c("mutationinformation", "mutation"
|
||||
, "mutation_info","mutation_info_labels"
|
||||
, "position"
|
||||
, LigDist_colname
|
||||
, "duet_stability_change", "duet_scaled", "duet_outcome"
|
||||
, "ligand_affinity_change", "affinity_scaled", "ligand_outcome"
|
||||
, "ddg_foldx", "foldx_scaled", "foldx_outcome"
|
||||
, "deepddg", "deepddg_scaled", "deepddg_outcome"
|
||||
, "asa", "rsa"
|
||||
, "rd_values", "kd_values"
|
||||
, "log10_or_mychisq", "neglog_pval_fisher", "af"
|
||||
, "mcsm_na_affinity", "mcsm_na_scaled", "mcsm_na_outcome"
|
||||
, "ddg_dynamut", "ddg_dynamut_scaled","ddg_dynamut_outcome"
|
||||
, "ddg_encom", "ddg_encom_scaled", "ddg_encom_outcome"
|
||||
, "dds_encom", "dds_encom_scaled", "dds_encom_outcome"
|
||||
, "ddg_mcsm", "ddg_mcsm_scaled", "ddg_mcsm_outcome"
|
||||
, "ddg_sdm", "ddg_sdm_scaled", "ddg_sdm_outcome"
|
||||
, "ddg_duet", "ddg_duet_scaled", "ddg_duet_outcome"
|
||||
, "ddg_dynamut2","ddg_dynamut2_scaled", "ddg_dynamut2_outcome")]
|
||||
|
||||
|
||||
comb_df_s = arrange(comb_df, position)
|
||||
|
||||
#=======================================================================
|
||||
fact_cols = colnames(comb_df_s)[grepl( "_outcome|_info", colnames(comb_df_s) )]
|
||||
fact_cols
|
||||
lapply(comb_df_s[, fact_cols], class)
|
||||
comb_df_s[, fact_cols] <- lapply(comb_df_s[, fact_cols], as.factor)
|
||||
|
||||
if (any(lapply(comb_df_s[, fact_cols], class) == "character")){
|
||||
cat("\nChanging cols to factor")
|
||||
comb_df_s[, fact_cols] <- lapply(comb_df_s[, fact_cols],as.factor)
|
||||
if (all(lapply(comb_df_s[, fact_cols], class) == "factor")){
|
||||
cat("\nSuccessful: cols changed to factor")
|
||||
}
|
||||
}
|
||||
lapply(comb_df_s[, fact_cols], class)
|
||||
|
||||
#=======================================================================
|
||||
table(comb_df_s$mutation_info)
|
||||
|
||||
# further checks to make sure dr and other muts are indeed unique
|
||||
dr_muts = comb_df_s[comb_df_s$mutation_info == dr_muts_col,]
|
||||
dr_muts_names = unique(dr_muts$mutation)
|
||||
|
||||
other_muts = comb_df_s[comb_df_s$mutation_info == other_muts_col,]
|
||||
other_muts_names = unique(other_muts$mutation)
|
||||
|
||||
if ( table(dr_muts_names%in%other_muts_names)[[1]] == length(dr_muts_names) &&
|
||||
table(other_muts_names%in%dr_muts_names)[[1]] == length(other_muts_names) ){
|
||||
cat("PASS: dr and other muts are indeed unique")
|
||||
}else{
|
||||
cat("FAIL: dr and others muts are NOT unique!")
|
||||
quit()
|
||||
}
|
||||
|
||||
# pretty display names i.e. labels to reduce major code duplication later
|
||||
foo_cnames = data.frame(colnames(comb_df_s))
|
||||
names(foo_cnames) <- "old_name"
|
||||
|
||||
stability_suffix <- paste0(delta_symbol, delta_symbol, "G")
|
||||
flexibility_suffix <- paste0(delta_symbol, delta_symbol, "S")
|
||||
|
||||
lig_dn = paste0("Ligand distance (", angstroms_symbol, ")"); lig_dn
|
||||
duet_dn = paste0("DUET ", stability_suffix); duet_dn
|
||||
foldx_dn = paste0("FoldX ", stability_suffix); foldx_dn
|
||||
deepddg_dn = paste0("Deepddg " , stability_suffix); deepddg_dn
|
||||
mcsm_na_dn = paste0("mCSM-NA affinity ", stability_suffix); mcsm_na_dn
|
||||
dynamut_dn = paste0("Dynamut ", stability_suffix); dynamut_dn
|
||||
dynamut2_dn = paste0("Dynamut2 " , stability_suffix); dynamut2_dn
|
||||
encom_ddg_dn = paste0("EnCOM " , stability_suffix); encom_ddg_dn
|
||||
encom_dds_dn = paste0("EnCOM " , flexibility_suffix ); encom_dds_dn
|
||||
sdm_dn = paste0("SDM " , stability_suffix); sdm_dn
|
||||
mcsm_dn = paste0("mCSM " , stability_suffix ); mcsm_dn
|
||||
|
||||
# Change colnames of some columns using datatable
|
||||
comb_df_sl = comb_df_s
|
||||
names(comb_df_sl)
|
||||
|
||||
setnames(comb_df_sl
|
||||
, old = c("asa", "rsa", "rd_values", "kd_values"
|
||||
, "log10_or_mychisq", "neglog_pval_fisher", "af"
|
||||
, LigDist_colname
|
||||
, "duet_scaled"
|
||||
, "foldx_scaled"
|
||||
, "deepddg_scaled"
|
||||
, "mcsm_na_scaled"
|
||||
, "ddg_dynamut_scaled"
|
||||
, "ddg_dynamut2_scaled"
|
||||
, "ddg_encom_scaled"
|
||||
, "dds_encom_scaled"
|
||||
, "ddg_sdm"
|
||||
, "ddg_mcsm")
|
||||
|
||||
, new = c("ASA", "RSA", "RD", "KD"
|
||||
, "Log10 (OR)", "-Log (P)", "MAF"
|
||||
, lig_dn
|
||||
, duet_dn
|
||||
, foldx_dn
|
||||
, deepddg_dn
|
||||
, mcsm_na_dn
|
||||
, dynamut_dn
|
||||
, dynamut2_dn
|
||||
, encom_ddg_dn
|
||||
, encom_dds_dn
|
||||
, sdm_dn
|
||||
, mcsm_dn)
|
||||
)
|
||||
|
||||
foo_cnames <- cbind(foo_cnames, colnames(comb_df_sl))
|
||||
|
||||
# some more pretty labels
|
||||
table(comb_df_sl$mutation_info)
|
||||
|
||||
levels(comb_df_sl$mutation_info)[levels(comb_df_sl$mutation_info)==dr_muts_col] <- "DM"
|
||||
levels(comb_df_sl$mutation_info)[levels(comb_df_sl$mutation_info)==other_muts_col] <- "OM"
|
||||
|
||||
table(comb_df_sl$mutation_info)
|
||||
|
||||
#######################################################################
|
||||
#======================
|
||||
# Selecting dfs
|
||||
# with appropriate cols
|
||||
#=======================
|
||||
static_cols_start = c("mutationinformation"
|
||||
, "position"
|
||||
, "mutation"
|
||||
, "mutation_info")
|
||||
|
||||
static_cols_end = c(lig_dn
|
||||
, "ASA"
|
||||
, "RSA"
|
||||
, "RD"
|
||||
, "KD")
|
||||
|
||||
# ordering is important!
|
||||
|
||||
#########################################################################
|
||||
#==============
|
||||
# DUET: LF
|
||||
#==============
|
||||
cols_to_select_duet = c(static_cols_start, c("duet_outcome", duet_dn), static_cols_end)
|
||||
wf_duet = comb_df_sl[, cols_to_select_duet]
|
||||
|
||||
#pivot_cols_ps = cols_to_select_ps[1:5]; pivot_cols_ps
|
||||
pivot_cols_duet = cols_to_select_duet[1: (length(static_cols_start) + 1)]; pivot_cols_duet
|
||||
|
||||
expected_rows_lf = nrow(wf_duet) * (length(wf_duet) - length(pivot_cols_duet))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: duet
|
||||
lf_duet = gather(wf_duet
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(duet_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_duet) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", duet_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# FoldX: LF
|
||||
#==============
|
||||
cols_to_select_foldx= c(static_cols_start, c("foldx_outcome", foldx_dn), static_cols_end)
|
||||
wf_foldx = comb_df_sl[, cols_to_select_foldx]
|
||||
|
||||
pivot_cols_foldx = cols_to_select_foldx[1: (length(static_cols_start) + 1)]; pivot_cols_foldx
|
||||
|
||||
expected_rows_lf = nrow(wf_foldx) * (length(wf_foldx) - length(pivot_cols_foldx))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: Foldx
|
||||
lf_foldx <<- gather(wf_foldx
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(foldx_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_foldx) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", foldx_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# Deepddg: LF
|
||||
#==============
|
||||
cols_to_select_deepddg = c(static_cols_start, c("deepddg_outcome", deepddg_dn), static_cols_end)
|
||||
wf_deepddg = comb_df_sl[, cols_to_select_deepddg]
|
||||
|
||||
pivot_cols_deepddg = cols_to_select_deepddg[1: (length(static_cols_start) + 1)]; pivot_cols_deepddg
|
||||
|
||||
expected_rows_lf = nrow(wf_deepddg) * (length(wf_deepddg) - length(pivot_cols_deepddg))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: Deepddg
|
||||
lf_deepddg = gather(wf_deepddg
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(deepddg_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_deepddg) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", deepddg_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# mCSM-NA: LF
|
||||
#==============
|
||||
cols_to_select_mcsm_na = c(static_cols_start, c("mcsm_na_outcome", mcsm_na_dn), static_cols_end)
|
||||
wf_mcsm_na = comb_df_sl[, cols_to_select_mcsm_na]
|
||||
|
||||
pivot_cols_mcsm_na = cols_to_select_mcsm_na[1: (length(static_cols_start) + 1)]; pivot_cols_mcsm_na
|
||||
|
||||
expected_rows_lf = nrow(wf_mcsm_na) * (length(wf_mcsm_na) - length(pivot_cols_mcsm_na))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: mcsm_na
|
||||
lf_mcsm_na = gather(wf_mcsm_na
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(mcsm_na_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_mcsm_na) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", mcsm_na_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# Dynamut: LF
|
||||
#==============
|
||||
cols_to_select_dynamut = c(static_cols_start, c("ddg_dynamut_outcome", dynamut_dn), static_cols_end)
|
||||
wf_dynamut = comb_df_sl[, cols_to_select_dynamut]
|
||||
|
||||
pivot_cols_dynamut = cols_to_select_dynamut[1: (length(static_cols_start) + 1)]; pivot_cols_dynamut
|
||||
|
||||
expected_rows_lf = nrow(wf_dynamut) * (length(wf_dynamut) - length(pivot_cols_dynamut))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: dynamut
|
||||
lf_dynamut = gather(wf_dynamut
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(dynamut_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_dynamut) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", dynamut_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# Dynamut2: LF
|
||||
#==============
|
||||
cols_to_select_dynamut2 = c(static_cols_start, c("ddg_dynamut2_outcome", dynamut2_dn), static_cols_end)
|
||||
|
||||
wf_dynamut2 = comb_df_sl[, cols_to_select_dynamut2]
|
||||
|
||||
pivot_cols_dynamut2 = cols_to_select_dynamut2[1: (length(static_cols_start) + 1)]; pivot_cols_dynamut2
|
||||
|
||||
expected_rows_lf = nrow(wf_dynamut2) * (length(wf_dynamut2) - length(pivot_cols_dynamut2))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: dynamut2
|
||||
lf_dynamut2 = gather(wf_dynamut2
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(dynamut2_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_dynamut2) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", dynamut2_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# EnCOM ddg: LF
|
||||
#==============
|
||||
cols_to_select_encomddg = c(static_cols_start, c("ddg_encom_outcome", encom_ddg_dn), static_cols_end)
|
||||
wf_encomddg = comb_df_sl[, cols_to_select_encomddg]
|
||||
|
||||
pivot_cols_encomddg = cols_to_select_encomddg[1: (length(static_cols_start) + 1)]; pivot_cols_encomddg
|
||||
|
||||
expected_rows_lf = nrow(wf_encomddg ) * (length(wf_encomddg ) - length(pivot_cols_encomddg))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: encomddg
|
||||
lf_encomddg = gather(wf_encomddg
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(encom_ddg_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_encomddg) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", encom_ddg_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
############################################################################
|
||||
#==============
|
||||
# EnCOM dds: LF
|
||||
#==============
|
||||
cols_to_select_encomdds = c(static_cols_start, c("dds_encom_outcome", encom_dds_dn), static_cols_end)
|
||||
wf_encomdds = comb_df_sl[, cols_to_select_encomdds]
|
||||
|
||||
pivot_cols_encomdds = cols_to_select_encomdds[1: (length(static_cols_start) + 1)]; pivot_cols_encomdds
|
||||
|
||||
expected_rows_lf = nrow(wf_encomdds) * (length(wf_encomdds) - length(pivot_cols_encomdds))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: encomdds
|
||||
lf_encomdds = gather(wf_encomdds
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(encom_dds_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_encomdds) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for", encom_dds_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# SDM: LF
|
||||
#==============
|
||||
cols_to_select_sdm = c(static_cols_start, c("ddg_sdm_outcome", sdm_dn), static_cols_end)
|
||||
wf_sdm = comb_df_sl[, cols_to_select_sdm]
|
||||
|
||||
pivot_cols_sdm = cols_to_select_sdm[1: (length(static_cols_start) + 1)]; pivot_cols_sdm
|
||||
|
||||
expected_rows_lf = nrow(wf_sdm) * (length(wf_sdm) - length(pivot_cols_sdm))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: sdm
|
||||
lf_sdm = gather(wf_sdm
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(sdm_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_sdm) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for", sdm_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# mCSM: LF
|
||||
#==============
|
||||
cols_to_select_mcsm = c(static_cols_start, c("ddg_mcsm_outcome", mcsm_dn), static_cols_end)
|
||||
wf_mcsm = comb_df_sl[, cols_to_select_mcsm]
|
||||
|
||||
pivot_cols_mcsm = cols_to_select_mcsm[1: (length(static_cols_start) + 1)]; pivot_cols_mcsm
|
||||
|
||||
expected_rows_lf = nrow(wf_mcsm) * (length(wf_mcsm) - length(pivot_cols_mcsm))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: mcsm
|
||||
lf_mcsm = gather(wf_mcsm
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(mcsm_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_mcsm) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for", mcsm_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
#==========================
|
||||
# Duet-d(from Dynamut): LF
|
||||
#===========================
|
||||
|
||||
#Not created, redundant and chaos!
|
||||
|
||||
############################################################################
|
||||
|
142
scripts/plotting/logo_data.R
Normal file
142
scripts/plotting/logo_data.R
Normal file
|
@ -0,0 +1,142 @@
|
|||
#!/usr/bin/env Rscript
|
||||
#########################################################
|
||||
# TASK: Script to format data for Logo_plots
|
||||
#########################################################
|
||||
#-------------------------
|
||||
# choose df for logoplot
|
||||
#-------------------------
|
||||
logo_data = merged_df3
|
||||
#logo_data = merged_df3_comp
|
||||
|
||||
# quick checks
|
||||
colnames(logo_data)
|
||||
str(logo_data)
|
||||
|
||||
c1 = unique(logo_data$position)
|
||||
nrow(logo_data)
|
||||
cat("No. of rows in my_data:", nrow(logo_data)
|
||||
, "\nDistinct positions corresponding to snps:", length(c1)
|
||||
, "\n===========================================================")
|
||||
#=======================================================================
|
||||
#==================
|
||||
# logo data: OR
|
||||
#==================
|
||||
foo = logo_data[, c("position"
|
||||
, "mutant_type","duet_scaled", "or_mychisq"
|
||||
, "mut_prop_polarity", "mut_prop_water")]
|
||||
|
||||
logo_data$log10or = log10(logo_data$or_mychisq)
|
||||
logo_data_plot = logo_data[, c("position"
|
||||
, "mutant_type", "or_mychisq", "log10or")]
|
||||
|
||||
logo_data_plot_or = logo_data[, c("position", "mutant_type", "or_mychisq")]
|
||||
wide_df_or = logo_data_plot_or %>% spread(position, or_mychisq, fill = 0.0)
|
||||
|
||||
wide_df_or = as.matrix(wide_df_or)
|
||||
rownames(wide_df_or) = wide_df_or[,1]
|
||||
dim(wide_df_or)
|
||||
wide_df_or = wide_df_or[,-1]
|
||||
str(wide_df_or)
|
||||
|
||||
position_or = as.numeric(colnames(wide_df_or))
|
||||
|
||||
#==================
|
||||
# logo data: logOR
|
||||
#==================
|
||||
logo_data_plot_logor = logo_data[, c("position", "mutant_type", "log10or")]
|
||||
wide_df_logor <- logo_data_plot_logor %>% spread(position, log10or, fill = 0.0)
|
||||
|
||||
wide_df_logor = as.matrix(wide_df_logor)
|
||||
|
||||
rownames(wide_df_logor) = wide_df_logor[,1]
|
||||
wide_df_logor = subset(wide_df_logor, select = -c(1) )
|
||||
colnames(wide_df_logor)
|
||||
wide_df_logor_m = data.matrix(wide_df_logor)
|
||||
|
||||
rownames(wide_df_logor_m)
|
||||
colnames(wide_df_logor_m)
|
||||
|
||||
position_logor = as.numeric(colnames(wide_df_logor_m))
|
||||
|
||||
#===============================
|
||||
# logo data: multiple nsSNPs (>1)
|
||||
#=================================
|
||||
#require(data.table)
|
||||
|
||||
# get freq count of positions so you can subset freq<1
|
||||
setDT(logo_data)[, mut_pos_occurrence := .N, by = .(position)]
|
||||
|
||||
table(logo_data$position)
|
||||
table(logo_data$mut_pos_occurrence)
|
||||
|
||||
max_mut = max(table(logo_data$position))
|
||||
|
||||
# extract freq_pos > 1
|
||||
my_data_snp = logo_data[logo_data$mut_pos_occurrence!=1,]
|
||||
u = unique(my_data_snp$position)
|
||||
max_mult_mut = max(table(my_data_snp$position))
|
||||
|
||||
if (nrow(my_data_snp) == nrow(logo_data) - table(logo_data$mut_pos_occurrence)[[1]] ){
|
||||
|
||||
cat("PASS: positions with multiple muts extracted"
|
||||
, "\nNo. of mutations:", nrow(my_data_snp)
|
||||
, "\nNo. of positions:", length(u)
|
||||
, "\nMax no. of muts at any position", max_mult_mut)
|
||||
}else{
|
||||
cat("FAIL: positions with multiple muts could NOT be extracted"
|
||||
, "\nExpected:",nrow(logo_data) - table(logo_data$mut_pos_occurrence)[[1]]
|
||||
, "\nGot:", nrow(my_data_snp) )
|
||||
}
|
||||
|
||||
cat("\nNo. of sites with only 1 mutations:", table(logo_data$mut_pos_occurrence)[[1]])
|
||||
|
||||
#--------------------------------------
|
||||
# matrix for_mychisq mutant type
|
||||
# frequency of mutant type by position
|
||||
#---------------------------------------
|
||||
table(my_data_snp$mutant_type, my_data_snp$position)
|
||||
tab_mt = table(my_data_snp$mutant_type, my_data_snp$position)
|
||||
class(tab_mt)
|
||||
|
||||
# unclass to convert to matrix
|
||||
tab_mt = unclass(tab_mt)
|
||||
tab_mt = as.matrix(tab_mt, rownames = T)
|
||||
|
||||
# should be TRUE
|
||||
is.matrix(tab_mt)
|
||||
|
||||
rownames(tab_mt) #aa
|
||||
colnames(tab_mt) #pos
|
||||
|
||||
#-------------------------------------
|
||||
# matrix for wild type
|
||||
# frequency of wild type by position
|
||||
#-------------------------------------
|
||||
tab_wt = table(my_data_snp$wild_type, my_data_snp$position); tab_wt
|
||||
tab_wt = unclass(tab_wt)
|
||||
|
||||
# remove wt duplicates
|
||||
wt = my_data_snp[, c("position", "wild_type")]
|
||||
wt = wt[!duplicated(wt),]
|
||||
|
||||
tab_wt = table(wt$wild_type, wt$position); tab_wt # should all be 1
|
||||
|
||||
rownames(tab_wt)
|
||||
rownames(tab_wt)
|
||||
|
||||
identical(colnames(tab_mt), colnames(tab_wt))
|
||||
identical(ncol(tab_mt), ncol(tab_wt))
|
||||
|
||||
#----------------------------------
|
||||
# logo data OR: multiple nsSNPs (>1)
|
||||
#----------------------------------
|
||||
logo_data_or_mult = my_data_snp[, c("position", "mutant_type", "or_mychisq")]
|
||||
#wide_df_or = logo_data_or %>% spread(position, or_mychisq, fill = 0.0)
|
||||
wide_df_or_mult = logo_data_or_mult %>% spread(position, or_mychisq, fill = NA)
|
||||
|
||||
wide_df_or_mult = as.matrix(wide_df_or_mult)
|
||||
rownames(wide_df_or_mult) = wide_df_or_mult[,1]
|
||||
wide_df_or_mult = wide_df_or_mult[,-1]
|
||||
str(wide_df_or_mult)
|
||||
|
||||
position_or_mult = as.numeric(colnames(wide_df_or_mult))
|
117
scripts/plotting/redundant/other_dfs_data.R
Normal file
117
scripts/plotting/redundant/other_dfs_data.R
Normal file
|
@ -0,0 +1,117 @@
|
|||
#!/usr/bin/env Rscript
|
||||
|
||||
# Didn't end up using it: sorted it at the source
|
||||
# .py script to combine all dfs to output all_params
|
||||
|
||||
#################################################################
|
||||
# TASK: Script to add all other dfs to merged_df2 and merged_df3
|
||||
|
||||
#################################################################
|
||||
# Combine other dfs:
|
||||
# dynamut_df, dynamut2_df, mcsm_na_df,
|
||||
# perhaps : deepddg and mcsm ppi (for embb)
|
||||
################################################################
|
||||
# read other files
|
||||
infilename_dynamut = paste0("~/git/Data/", drug, "/output/dynamut_results/", gene
|
||||
, "_complex_dynamut_norm.csv")
|
||||
|
||||
infilename_dynamut2 = paste0("~/git/Data/", drug, "/output/dynamut_results/dynamut2/", gene
|
||||
, "_complex_dynamut2_norm.csv")
|
||||
|
||||
infilename_mcsm_na = paste0("~/git/Data/", drug, "/output/mcsm_na_results/", gene
|
||||
, "_complex_mcsm_na_norm.csv")
|
||||
|
||||
infilename_mcsm_f_snps <- paste0("~/git/Data/", drug, "/output/", gene
|
||||
, "_mcsm_formatted_snps.csv")
|
||||
|
||||
dynamut_df = read.csv(infilename_dynamut)
|
||||
dynamut2_df = read.csv(infilename_dynamut2)
|
||||
mcsm_na_df = read.csv(infilename_mcsm_na)
|
||||
mcsm_f_snps = read.csv(infilename_mcsm_f_snps, header = F)
|
||||
names(mcsm_f_snps) = "mutationinformation"
|
||||
|
||||
#=================================
|
||||
# check with intersect to find the common col, but use
|
||||
c1 = length(intersect(names(dynamut_df), names(dynamut2_df)))
|
||||
c2 = length(intersect(names(dynamut2_df), names(mcsm_na_df)))
|
||||
|
||||
if (c1 == 1 && c2 == 1) {
|
||||
n_common = 1
|
||||
}else{
|
||||
cat("\nMore than one common col found, inspect before merging!")
|
||||
}
|
||||
|
||||
# mutationinformation column to be on the safe side
|
||||
# delete chain from dynamut2_df
|
||||
#dynamut2_df = subset(dynamut2_df, select = -chain)
|
||||
|
||||
# quick checks
|
||||
lapply(list(dynamut_df
|
||||
, dynamut2_df
|
||||
, mcsm_na_df), ncol)
|
||||
|
||||
lapply(list(dynamut_df
|
||||
, dynamut2_df
|
||||
, mcsm_na_df), colnames)
|
||||
|
||||
lapply(list(dynamut_df
|
||||
, dynamut2_df
|
||||
, mcsm_na_df), nrow)
|
||||
|
||||
ncols_comb = lapply(list(dynamut_df
|
||||
, dynamut2_df
|
||||
, mcsm_na_df), ncol)
|
||||
|
||||
#---------------------------------
|
||||
# Combine 1: all other params dfs
|
||||
#---------------------------------
|
||||
combined_dfs = Reduce(inner_join, list(dynamut_df
|
||||
, dynamut2_df
|
||||
, mcsm_na_df))
|
||||
# Reduce("+", ncols_comb)
|
||||
|
||||
#-----------------------------------------
|
||||
# Combine 2: combine1 result + merged_df2
|
||||
#-----------------------------------------
|
||||
drop_cols = intersect(names(combined_dfs), names(merged_df2))
|
||||
drop_cols = drop_cols
|
||||
|
||||
drop_cols = drop_cols[! drop_cols %in% c("mutationinformation")]
|
||||
|
||||
combined_dfs_f = combined_dfs[, !colnames(combined_dfs)%in%drop_cols]
|
||||
|
||||
nrow(combined_dfs_f); nrow(merged_df2)
|
||||
ncol(combined_dfs_f); ncol(merged_df2)
|
||||
|
||||
#-----------------------------------------
|
||||
# Combined merged_df2
|
||||
#-----------------------------------------
|
||||
merged_df2_combined = merge(merged_df2
|
||||
, combined_dfs_f
|
||||
, by = "mutationinformation"
|
||||
)
|
||||
|
||||
expected_ncols = ncol(combined_dfs_f)+ ncol(merged_df2) - 1
|
||||
|
||||
if ( nrow(merged_df2_combined) == nrow(merged_df2) && ncol(merged_df2_combined) == expected_ncols ){
|
||||
|
||||
cat("\nPASS: merged_df2 combined with other parameters dfs."
|
||||
, "\nUse this for lineage distribution plots")
|
||||
}else{
|
||||
|
||||
cat("\nFAIL: merged_df2 didn't combine successfully with other parameters dfs")
|
||||
quit()
|
||||
|
||||
}
|
||||
|
||||
rm(combined_dfs, combined_dfs_f)
|
||||
|
||||
#================================
|
||||
# combined data
|
||||
# short_df ps: ~ merged_df3
|
||||
# TODO: later integrate properly
|
||||
#================================
|
||||
#-----------------------------------------
|
||||
# Combined merged_df2
|
||||
#-----------------------------------------
|
||||
merged_df3_combined = merged_df2_combined[!duplicated(merged_df2_combined$mutationinformation),]
|
470
scripts/plotting/redundant/other_plots_data.R
Executable file
470
scripts/plotting/redundant/other_plots_data.R
Executable file
|
@ -0,0 +1,470 @@
|
|||
#!/usr/bin/env Rscript
|
||||
#########################################################
|
||||
# TASK: Script to format data for dm om plots:
|
||||
# generating LF data
|
||||
# sourced by get_plotting_dfs.R
|
||||
#########################################################
|
||||
# working dir and loading libraries
|
||||
# getwd()
|
||||
# setwd("~/git/LSHTM_analysis/scripts/plotting")
|
||||
# getwd()
|
||||
|
||||
# make cmd
|
||||
# globals
|
||||
# drug = "streptomycin"
|
||||
# gene = "gid"
|
||||
|
||||
# source("get_plotting_dfs.R")
|
||||
#=======================================================================
|
||||
# MOVE TO COMBINE or singular file for deepddg
|
||||
#
|
||||
# cols_to_select = c("mutation", "mutationinformation"
|
||||
# , "wild_type", "position", "mutant_type"
|
||||
# , "mutation_info")
|
||||
#
|
||||
# merged_df3_short = merged_df3[, cols_to_select]
|
||||
|
||||
# infilename_mcsm_f_snps <- paste0("~/git/Data/", drug, "/output/", gene
|
||||
# , "_mcsm_formatted_snps.csv")
|
||||
#
|
||||
# mcsm_f_snps<- read.csv(infilename_mcsm_f_snps, header = F)
|
||||
# names(mcsm_f_snps) <- "mutationinformation"
|
||||
|
||||
# write merged_df3 to generate structural figure on chimera
|
||||
#write.csv(merged_df3_short, "merged_df3_short.csv")
|
||||
#========================================================================
|
||||
|
||||
#========================================================================
|
||||
# cols to select
|
||||
|
||||
cols_mcsm_df <- merged_df3[, c("mutationinformation", "mutation"
|
||||
, "mutation_info", "position"
|
||||
, LigDist_colname
|
||||
, "duet_stability_change", "duet_scaled", "duet_outcome"
|
||||
, "ligand_affinity_change", "affinity_scaled", "ligand_outcome"
|
||||
, "ddg_foldx", "foldx_scaled", "foldx_outcome"
|
||||
, "deepddg", "deepddg_scaled", "deepddg_outcome"
|
||||
, "asa", "rsa"
|
||||
, "rd_values", "kd_values"
|
||||
, "log10_or_mychisq", "neglog_pval_fisher", "af")]
|
||||
|
||||
cols_mcsm_na_df <- mcsm_na_df[, c("mutationinformation"
|
||||
, "mcsm_na_affinity", "mcsm_na_scaled"
|
||||
, "mcsm_na_outcome")]
|
||||
# entire dynamut_df
|
||||
|
||||
cols_dynamut2_df <- dynamut2_df[, c("mutationinformation"
|
||||
, "ddg_dynamut2", "ddg_dynamut2_scaled"
|
||||
, "ddg_dynamut2_outcome")]
|
||||
|
||||
n_comb_cols = length(cols_mcsm_df) + length(cols_mcsm_na_df) +
|
||||
length(dynamut_df) + length(cols_dynamut2_df); n_comb_cols
|
||||
|
||||
i1<- intersect(names(cols_mcsm_df), names(cols_mcsm_na_df))
|
||||
i2<- intersect(names(dynamut_df), names(cols_dynamut2_df))
|
||||
merging_cols <- intersect(i1, i2)
|
||||
cat("\nmerging_cols:", merging_cols)
|
||||
|
||||
if (merging_cols == "mutationinformation") {
|
||||
cat("\nStage 1: Found common col between dfs, checking values in it...")
|
||||
c1 <- all(mcsm_f_snps[[merging_cols]]%in%cols_mcsm_df[[merging_cols]])
|
||||
c2 <- all(mcsm_f_snps[[merging_cols]]%in%cols_mcsm_na_df[[merging_cols]])
|
||||
c3 <- all(mcsm_f_snps[[merging_cols]]%in%dynamut_df[[merging_cols]])
|
||||
c4 <- all(mcsm_f_snps[[merging_cols]]%in%cols_dynamut2_df[[merging_cols]])
|
||||
cols_check <- c(c1, c2, c3, c4)
|
||||
expected_cols = n_comb_cols - ( length(cols_check) - 1)
|
||||
if (all(cols_check)){
|
||||
cat("\nStage 2: Proceeding with merging dfs:\n")
|
||||
comb_df <- Reduce(inner_join, list(cols_mcsm_df
|
||||
, cols_mcsm_na_df
|
||||
, dynamut_df
|
||||
, cols_dynamut2_df))
|
||||
comb_df_s = arrange(comb_df, position)
|
||||
|
||||
# if ( nrow(comb_df_s) == nrow(mcsm_f_snps) && ncol(comb_df_s) == expected_cols) {
|
||||
# cat("\Stage3, PASS: dfs merged sucessfully"
|
||||
# , "\nnrow of merged_df: ", nrow(comb_df_s)
|
||||
# , "\nncol of merged_df:", ncol(comb_df_s))
|
||||
# }
|
||||
|
||||
}
|
||||
}
|
||||
#names(comb_df_s)
|
||||
cat("\n!!!IT GOT TO HERE!!!!")
|
||||
#=======================================================================
|
||||
fact_cols = colnames(comb_df_s)[grepl( "_outcome|_info", colnames(comb_df_s) )]
|
||||
fact_cols
|
||||
lapply(comb_df_s[, fact_cols], class)
|
||||
comb_df_s[, fact_cols] <- lapply(comb_df_s[, fact_cols], as.factor)
|
||||
|
||||
if (any(lapply(comb_df_s[, fact_cols], class) == "character")){
|
||||
cat("\nChanging cols to factor")
|
||||
comb_df_s[, fact_cols] <- lapply(comb_df_s[, fact_cols],as.factor)
|
||||
if (all(lapply(comb_df_s[, fact_cols], class) == "factor")){
|
||||
cat("\nSuccessful: cols changed to factor")
|
||||
}
|
||||
}
|
||||
lapply(comb_df_s[, fact_cols], class)
|
||||
|
||||
#=======================================================================
|
||||
table(comb_df_s$mutation_info)
|
||||
|
||||
# further checks to make sure dr and other muts are indeed unique
|
||||
dr_muts = comb_df_s[comb_df_s$mutation_info == dr_muts_col,]
|
||||
dr_muts_names = unique(dr_muts$mutation)
|
||||
|
||||
other_muts = comb_df_s[comb_df_s$mutation_info == other_muts_col,]
|
||||
other_muts_names = unique(other_muts$mutation)
|
||||
|
||||
if ( table(dr_muts_names%in%other_muts_names)[[1]] == length(dr_muts_names) &&
|
||||
table(other_muts_names%in%dr_muts_names)[[1]] == length(other_muts_names) ){
|
||||
cat("PASS: dr and other muts are indeed unique")
|
||||
}else{
|
||||
cat("FAIL: dr and others muts are NOT unique!")
|
||||
quit()
|
||||
}
|
||||
|
||||
# pretty display names i.e. labels to reduce major code duplication later
|
||||
foo_cnames = data.frame(colnames(comb_df_s))
|
||||
names(foo_cnames) <- "old_name"
|
||||
|
||||
stability_suffix <- paste0(delta_symbol, delta_symbol, "G")
|
||||
flexibility_suffix <- paste0(delta_symbol, delta_symbol, "S")
|
||||
|
||||
lig_dn = paste0("Ligand distance (", angstroms_symbol, ")"); lig_dn
|
||||
duet_dn = paste0("DUET ", stability_suffix); duet_dn
|
||||
foldx_dn = paste0("FoldX ", stability_suffix); foldx_dn
|
||||
deepddg_dn = paste0("Deepddg " , stability_suffix); deepddg_dn
|
||||
mcsm_na_dn = paste0("mCSM-NA affinity ", stability_suffix); mcsm_na_dn
|
||||
dynamut_dn = paste0("Dynamut ", stability_suffix); dynamut_dn
|
||||
dynamut2_dn = paste0("Dynamut2 " , stability_suffix); dynamut2_dn
|
||||
encom_ddg_dn = paste0("EnCOM " , stability_suffix); encom_ddg_dn
|
||||
encom_dds_dn = paste0("EnCOM " , flexibility_suffix ); encom_dds_dn
|
||||
sdm_dn = paste0("SDM " , stability_suffix); sdm_dn
|
||||
mcsm_dn = paste0("mCSM " , stability_suffix ); mcsm_dn
|
||||
|
||||
# Change colnames of some columns using datatable
|
||||
comb_df_sl = comb_df_s
|
||||
names(comb_df_sl)
|
||||
|
||||
setnames(comb_df_sl
|
||||
, old = c("asa", "rsa", "rd_values", "kd_values"
|
||||
, "log10_or_mychisq", "neglog_pval_fisher", "af"
|
||||
, LigDist_colname
|
||||
, "duet_scaled"
|
||||
, "foldx_scaled"
|
||||
, "deepddg_scaled"
|
||||
, "mcsm_na_scaled"
|
||||
, "ddg_dynamut_scaled"
|
||||
, "ddg_dynamut2_scaled"
|
||||
, "ddg_encom_scaled"
|
||||
, "dds_encom_scaled"
|
||||
, "ddg_sdm"
|
||||
, "ddg_mcsm")
|
||||
|
||||
, new = c("ASA", "RSA", "RD", "KD"
|
||||
, "Log10 (OR)", "-Log (P)", "MAF"
|
||||
, lig_dn
|
||||
, duet_dn
|
||||
, foldx_dn
|
||||
, deepddg_dn
|
||||
, mcsm_na_dn
|
||||
, dynamut_dn
|
||||
, dynamut2_dn
|
||||
, encom_ddg_dn
|
||||
, encom_dds_dn
|
||||
, sdm_dn
|
||||
, mcsm_dn)
|
||||
)
|
||||
|
||||
foo_cnames <- cbind(foo_cnames, colnames(comb_df_sl))
|
||||
|
||||
# some more pretty labels
|
||||
table(comb_df_sl$mutation_info)
|
||||
|
||||
levels(comb_df_sl$mutation_info)[levels(comb_df_sl$mutation_info)==dr_muts_col] <- "DM"
|
||||
levels(comb_df_sl$mutation_info)[levels(comb_df_sl$mutation_info)==other_muts_col] <- "OM"
|
||||
|
||||
table(comb_df_sl$mutation_info)
|
||||
|
||||
#######################################################################
|
||||
#======================
|
||||
# Selecting dfs
|
||||
# with appropriate cols
|
||||
#=======================
|
||||
static_cols_start = c("mutationinformation"
|
||||
, "position"
|
||||
, "mutation"
|
||||
, "mutation_info")
|
||||
|
||||
static_cols_end = c(lig_dn
|
||||
, "ASA"
|
||||
, "RSA"
|
||||
, "RD"
|
||||
, "KD")
|
||||
|
||||
# ordering is important!
|
||||
|
||||
#########################################################################
|
||||
#==============
|
||||
# DUET: LF
|
||||
#==============
|
||||
cols_to_select_duet = c(static_cols_start, c("duet_outcome", duet_dn), static_cols_end)
|
||||
wf_duet = comb_df_sl[, cols_to_select_duet]
|
||||
|
||||
#pivot_cols_ps = cols_to_select_ps[1:5]; pivot_cols_ps
|
||||
pivot_cols_duet = cols_to_select_duet[1: (length(static_cols_start) + 1)]; pivot_cols_duet
|
||||
|
||||
expected_rows_lf = nrow(wf_duet) * (length(wf_duet) - length(pivot_cols_duet))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: duet
|
||||
lf_duet = gather(wf_duet
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(duet_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_duet) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", duet_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# FoldX: LF
|
||||
#==============
|
||||
cols_to_select_foldx= c(static_cols_start, c("foldx_outcome", foldx_dn), static_cols_end)
|
||||
wf_foldx = comb_df_sl[, cols_to_select_foldx]
|
||||
|
||||
pivot_cols_foldx = cols_to_select_foldx[1: (length(static_cols_start) + 1)]; pivot_cols_foldx
|
||||
|
||||
expected_rows_lf = nrow(wf_foldx) * (length(wf_foldx) - length(pivot_cols_foldx))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: duet
|
||||
print("TESTXXXXXXXXXXXXXXXXXXXXX---------------------->>>>")
|
||||
lf_foldx <<- gather(wf_foldx
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(foldx_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_foldx) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", foldx_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# Deepddg: LF
|
||||
#==============
|
||||
cols_to_select_deepddg = c(static_cols_start, c("deepddg_outcome", deepddg_dn), static_cols_end)
|
||||
wf_deepddg = comb_df_sl[, cols_to_select_deepddg]
|
||||
|
||||
pivot_cols_deepddg = cols_to_select_deepddg[1: (length(static_cols_start) + 1)]; pivot_cols_deepddg
|
||||
|
||||
expected_rows_lf = nrow(wf_deepddg) * (length(wf_deepddg) - length(pivot_cols_deepddg))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: duet
|
||||
lf_deepddg = gather(wf_deepddg
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(deepddg_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_deepddg) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", deepddg_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# mCSM-NA: LF
|
||||
#==============
|
||||
cols_to_select_mcsm_na = c(static_cols_start, c("mcsm_na_outcome", mcsm_na_dn), static_cols_end)
|
||||
wf_mcsm_na = comb_df_sl[, cols_to_select_mcsm_na]
|
||||
|
||||
pivot_cols_mcsm_na = cols_to_select_mcsm_na[1: (length(static_cols_start) + 1)]; pivot_cols_mcsm_na
|
||||
|
||||
expected_rows_lf = nrow(wf_mcsm_na) * (length(wf_mcsm_na) - length(pivot_cols_mcsm_na))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: duet
|
||||
lf_mcsm_na = gather(wf_mcsm_na
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(mcsm_na_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_mcsm_na) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", mcsm_na_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# Dynamut: LF
|
||||
#==============
|
||||
cols_to_select_dynamut = c(static_cols_start, c("ddg_dynamut_outcome", dynamut_dn), static_cols_end)
|
||||
wf_dynamut = comb_df_sl[, cols_to_select_dynamut]
|
||||
|
||||
pivot_cols_dynamut = cols_to_select_dynamut[1: (length(static_cols_start) + 1)]; pivot_cols_dynamut
|
||||
|
||||
expected_rows_lf = nrow(wf_dynamut) * (length(wf_dynamut) - length(pivot_cols_dynamut))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: duet
|
||||
lf_dynamut = gather(wf_dynamut
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(dynamut_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_dynamut) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", dynamut_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# Dynamut2: LF
|
||||
#==============
|
||||
cols_to_select_dynamut2 = c(static_cols_start, c("ddg_dynamut2_outcome", dynamut2_dn), static_cols_end)
|
||||
|
||||
wf_dynamut2 = comb_df_sl[, cols_to_select_dynamut2]
|
||||
|
||||
pivot_cols_dynamut2 = cols_to_select_dynamut2[1: (length(static_cols_start) + 1)]; pivot_cols_dynamut2
|
||||
|
||||
expected_rows_lf = nrow(wf_dynamut2) * (length(wf_dynamut2) - length(pivot_cols_dynamut2))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: duet
|
||||
lf_dynamut2 = gather(wf_dynamut2
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(dynamut2_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_dynamut2) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", dynamut2_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# EnCOM ddg: LF
|
||||
#==============
|
||||
cols_to_select_encomddg = c(static_cols_start, c("ddg_encom_outcome", encom_ddg_dn), static_cols_end)
|
||||
wf_encomddg = comb_df_sl[, cols_to_select_encomddg]
|
||||
|
||||
pivot_cols_encomddg = cols_to_select_encomddg[1: (length(static_cols_start) + 1)]; pivot_cols_encomddg
|
||||
|
||||
expected_rows_lf = nrow(wf_encomddg ) * (length(wf_encomddg ) - length(pivot_cols_encomddg))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: encomddg
|
||||
lf_encomddg = gather(wf_encomddg
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(encom_ddg_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_encomddg) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for ", encom_ddg_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
############################################################################
|
||||
#==============
|
||||
# EnCOM dds: LF
|
||||
#==============
|
||||
cols_to_select_encomdds = c(static_cols_start, c("dds_encom_outcome", encom_dds_dn), static_cols_end)
|
||||
wf_encomdds = comb_df_sl[, cols_to_select_encomdds]
|
||||
|
||||
pivot_cols_encomdds = cols_to_select_encomdds[1: (length(static_cols_start) + 1)]; pivot_cols_encomdds
|
||||
|
||||
expected_rows_lf = nrow(wf_encomdds) * (length(wf_encomdds) - length(pivot_cols_encomdds))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: encomddg
|
||||
lf_encomdds = gather(wf_encomdds
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(encom_dds_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_encomdds) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for", encom_dds_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# SDM: LF
|
||||
#==============
|
||||
cols_to_select_sdm = c(static_cols_start, c("ddg_sdm_outcome", sdm_dn), static_cols_end)
|
||||
wf_sdm = comb_df_sl[, cols_to_select_sdm]
|
||||
|
||||
pivot_cols_sdm = cols_to_select_sdm[1: (length(static_cols_start) + 1)]; pivot_cols_sdm
|
||||
|
||||
expected_rows_lf = nrow(wf_sdm) * (length(wf_sdm) - length(pivot_cols_sdm))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: encomddg
|
||||
lf_sdm = gather(wf_sdm
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(sdm_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_sdm) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for", sdm_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
|
||||
############################################################################
|
||||
#==============
|
||||
# mCSM: LF
|
||||
#==============
|
||||
cols_to_select_mcsm = c(static_cols_start, c("ddg_mcsm_outcome", mcsm_dn), static_cols_end)
|
||||
wf_mcsm = comb_df_sl[, cols_to_select_mcsm]
|
||||
|
||||
pivot_cols_mcsm = cols_to_select_mcsm[1: (length(static_cols_start) + 1)]; pivot_cols_mcsm
|
||||
|
||||
expected_rows_lf = nrow(wf_mcsm) * (length(wf_mcsm) - length(pivot_cols_mcsm))
|
||||
expected_rows_lf
|
||||
|
||||
# LF data: encomddg
|
||||
lf_mcsm = gather(wf_mcsm
|
||||
, key = param_type
|
||||
, value = param_value
|
||||
, all_of(mcsm_dn):tail(static_cols_end,1)
|
||||
, factor_key = TRUE)
|
||||
|
||||
if (nrow(lf_mcsm) == expected_rows_lf){
|
||||
cat("\nPASS: long format data created for", mcsm_dn)
|
||||
}else{
|
||||
cat("\nFAIL: long format data could not be created for duet")
|
||||
quit()
|
||||
}
|
||||
############################################################################
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue