From 883207bc4be175ea0b2db1e1a99e129bc7e2aa0b Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Thu, 17 Sep 2020 17:04:03 +0100 Subject: [PATCH] updated corr_PS_LIG.R to output both styles of corr plots --- scripts/plotting/corr_PS_LIG.R | 143 ++++++++++++++++++++++++--------- 1 file changed, 105 insertions(+), 38 deletions(-) diff --git a/scripts/plotting/corr_PS_LIG.R b/scripts/plotting/corr_PS_LIG.R index dadc3fe..d57ae26 100644 --- a/scripts/plotting/corr_PS_LIG.R +++ b/scripts/plotting/corr_PS_LIG.R @@ -59,10 +59,16 @@ cat(paste0("Variables imported:" corr_ps = "corr_PS.svg" plot_corr_ps = paste0(plotdir,"/", corr_ps) +corr_upper_ps = "corr_upper_PS.svg" +plot_corr_upper_ps = paste0(plotdir,"/", corr_upper_ps) + # LIG corr_lig = "corr_LIG.svg" plot_corr_lig = paste0(plotdir,"/", corr_lig) +corr_upper_lig = "corr_upper_LIG.svg" +plot_corr_upper_lig = paste0(plotdir,"/", corr_upper_lig) + #################################################################### # end of loading libraries and functions # ######################################################################## @@ -159,8 +165,8 @@ my_corr_colnames = c("DUET" , "Foldx" - , "Log(OR)" - , "-Log(P)" + , "Log (OR)" + , "-Log (P)" , "AF" @@ -173,9 +179,6 @@ colnames(corr_data_ps) colnames(corr_data_ps) <- my_corr_colnames colnames(corr_data_ps) -#----------------- -# generate corr PS plot -#----------------- start = 1 end = which(colnames(corr_data_ps) == drug); end # should be the last column offset = 1 @@ -187,11 +190,14 @@ head(my_corr_ps) # deep blue :#007d85 # deep red: #ae301e +#--------------------------------------- +# generate corr PS plot 1: both panels +#--------------------------------------- + cat("Corr plot PS:", plot_corr_ps) svg(plot_corr_ps, width = 15, height = 15) -#OutPlot1 = pairs.panels([1:(length(my_corr_ps)-1)] -OutPlot1 = my_pp(my_corr_ps[1:(length(my_corr_ps)-1)] +OutPlot1 = pairs.panels(my_corr_ps[1:(length(my_corr_ps)-1)] , method = "spearman" # correlation method , hist.col = "grey" ##00AFBB , density = TRUE # show density plots @@ -206,8 +212,8 @@ OutPlot1 = my_pp(my_corr_ps[1:(length(my_corr_ps)-1)] #, alpha = .05 #, points(pch = 19, col = c("#f8766d", "#00bfc4")) , cex = 3 - , cex.axis = 1.5 - , cex.labels = 2.1 + , cex.axis = 2 + , cex.labels = 4 , cex.cor = 1 , smooth = F @@ -216,6 +222,39 @@ OutPlot1 = my_pp(my_corr_ps[1:(length(my_corr_ps)-1)] print(OutPlot1) dev.off() + +#---------------------------------------------- +# generate corr PS plot 2: upper_panel only +#---------------------------------------------- +cat("Corr plot upper PS:", plot_corr_upper_ps) +svg(plot_corr_upper_ps, width = 15, height = 15) + +OutPlot1_upper = my_pp(my_corr_ps[1:(length(my_corr_ps)-1)] # no lower panel + , method = "spearman" # correlation method + , hist.col = "grey" ##00AFBB + , density = TRUE # show density plots + , ellipses = F # show correlation ellipses + , stars = T + , rug = F + , breaks = "Sturges" + , show.points = T + , bg = c("#f8766d", "#00bfc4")[unclass(factor(my_corr_ps$duet_outcome))] + , pch = 21 + , jitter = T + #, alpha = .05 + #, points(pch = 19, col = c("#f8766d", "#00bfc4")) + , cex = 3 + , cex.axis = 1.6 + , cex.labels = 4 + , cex.cor = 1 + , smooth = F + +) + +print(OutPlot1_upper) +dev.off() + +################################################################################################ #=========================== # Data for Correlation plots: LIG #=========================== @@ -224,11 +263,9 @@ table(df_lig$ligand_outcome) df_lig$log10_or_mychisq = log10(df_lig$or_mychisq) df_lig$neglog_pval_fisher = -log10(df_lig$pval_fisher) - df_lig$log10_or_kin = log10(df_lig$or_kin) df_lig$neglog_pwald_kin = -log10(df_lig$pwald_kin) - # subset data to generate pairwise correlations cols_to_select = c("affinity_scaled" @@ -248,8 +285,8 @@ dim(corr_data_lig) # assign nice colnames (for display) my_corr_colnames = c("Ligand Affinity" - , "Log(OR)" - , "-Log(P)" + , "Log (OR)" + , "-Log (P)" , "AF" @@ -262,10 +299,6 @@ colnames(corr_data_lig) colnames(corr_data_lig) <- my_corr_colnames colnames(corr_data_lig) -#----------------- -# generate corr LIG plot -#----------------- - start = 1 end = which(colnames(corr_data_lig) == drug); end # should be the last column offset = 1 @@ -273,32 +306,66 @@ offset = 1 my_corr_lig = corr_data_lig[start:(end-offset)] head(my_corr_lig) +#--------------------------------------- +# generate corr LIG plot 1: both panels +#--------------------------------------- cat("Corr LIG plot:", plot_corr_lig) svg(plot_corr_lig, width = 15, height = 15) -#OutPlot2 = pairs.panels(my_corr_lig[1:(length(my_corr_lig)-1)] -OutPlot2 = my_pp(my_corr_lig[1:(length(my_corr_lig)-1)] - , method = "spearman" # correlation method - , hist.col = "grey" ##00AFBB - , density = TRUE # show density plots - , ellipses = F # show correlation ellipses - , stars = T - , rug = F - , breaks = "Sturges" - , show.points = T - , bg = c("#f8766d", "#00bfc4")[unclass(factor(my_corr_lig$ligand_outcome))] - , pch = 21 - , jitter = T - #, alpha = .05 - #, points(pch = 19, col = c("#f8766d", "#00bfc4")) - , cex = 3 - , cex.axis = 1.5 - , cex.labels = 2.1 - , cex.cor = 1 - , smooth = F +# uncomment as necessary +OutPlot2 = pairs.panels(my_corr_lig[1:(length(my_corr_lig)-1)] + , method = "spearman" # correlation method + , hist.col = "grey" ##00AFBB + , density = TRUE # show density plots + , ellipses = F # show correlation ellipses + , stars = T + , rug = F + , breaks = "Sturges" + , show.points = T + , bg = c("#f8766d", "#00bfc4")[unclass(factor(my_corr_lig$ligand_outcome))] + , pch = 21 + , jitter = T + #, alpha = .05 + #, points(pch = 19, col = c("#f8766d", "#00bfc4")) + , cex = 3 + , cex.axis = 2 + , cex.labels = 4 + , cex.cor = 1 + , smooth = F ) print(OutPlot2) dev.off() + + +#--------------------------------------- +# generate corr LIG plot 2: upper panels +#--------------------------------------- +cat("Corr LIG plot:", plot_corr_upper_lig) +svg(plot_corr_upper_lig, width = 15, height = 15) + +# uncomment as necessary +OutPlot2_upper = my_pp(my_corr_lig[1:(length(my_corr_lig)-1)] + , method = "spearman" # correlation method + , hist.col = "grey" ##00AFBB + , density = TRUE # show density plots + , ellipses = F # show correlation ellipses + , stars = T + , rug = F + , breaks = "Sturges" + , show.points = T + , bg = c("#f8766d", "#00bfc4")[unclass(factor(my_corr_lig$ligand_outcome))] + , pch = 21 + , jitter = T + #, alpha = .05 + #, points(pch = 19, col = c("#f8766d", "#00bfc4")) + , cex = 3 + , cex.axis = 1.6 + , cex.labels = 4 + , cex.cor = 1 + , smooth = F +) + +print(OutPlot2_upper) +dev.off() ####################################################### -library(lattice)