From 18e1f14455231483be1d611000eb4f26c79e5cdf Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Mon, 14 Feb 2022 11:14:40 +0000 Subject: [PATCH] saving changes --- config/embb.R | 4 + config/gid.R | 9 +- config/katg.R | 2 + config/pnca.R | 14 +- scripts/Header_TT.R | 1 + .../functions/tests/test_lineage_plot_data.R | 6 +- scripts/plotting/consurf_plot.R | 218 ------------------ 7 files changed, 26 insertions(+), 228 deletions(-) delete mode 100644 scripts/plotting/consurf_plot.R diff --git a/config/embb.R b/config/embb.R index c8db852..adfbd05 100644 --- a/config/embb.R +++ b/config/embb.R @@ -108,3 +108,7 @@ cat("\n===================================================" , aa_pos_dsl, "\n" ) ############################################################## +# var for position customisation for plots +aa_pos_lig1 = aa_pos_ca +aa_pos_lig2 = aa_pos_cdl +aa_pos_lig3 = aa_pos_dsl \ No newline at end of file diff --git a/config/gid.R b/config/gid.R index bb645e4..0f04044 100644 --- a/config/gid.R +++ b/config/gid.R @@ -80,12 +80,13 @@ aa_pos_sry = sort(unique(c( aa_ligplus_sry , aa_plip_sry , aa_arpeg_sry))) - + +aa_pos_drug = aa_pos_sry + aa_pos_sry_hbond = sort(unique(c( aa_ligplus_sry_hbond , aa_plip_sry_hbond))) -aa_pos_drug = aa_pos_sry aa_pos_rna = sort(unique(c( aa_ligplus_rna @@ -127,3 +128,7 @@ cat("\n===================================================" , aa_pos_amp, "\n") ############################################################## +# var for position customisation for plots +aa_pos_lig1 = aa_pos_rna +aa_pos_lig2 = aa_pos_sam +aa_pos_lig3 = aa_pos_amp \ No newline at end of file diff --git a/config/katg.R b/config/katg.R index 7924596..8bbac19 100644 --- a/config/katg.R +++ b/config/katg.R @@ -102,3 +102,5 @@ cat("\n===================================================" , aa_pos_hem, "\n") ############################################################## +# var for position customisation for plots +aa_pos_lig1 = aa_pos_hem \ No newline at end of file diff --git a/config/pnca.R b/config/pnca.R index de15189..2ac7a36 100644 --- a/config/pnca.R +++ b/config/pnca.R @@ -25,10 +25,10 @@ aa_pos_drug = aa_pos_pza aa_arpeg = c(102) ############################################################## -active_aa_pos = sort(unique(c(metal_aa_pos - , catalytic_aa_pos - , substrate_aa_pos - , hbond_aa_pos +active_aa_pos = sort(unique(c(aa_pos_pza + , aa_pos_fe + , aa_pos_catalytic + , aa_pos_hbond , aa_arpeg))) ############################################################## cat("\nNo. of active site residues for gene" @@ -49,4 +49,8 @@ cat("\n===================================================" , "\nH-bonding residues:" , length(aa_pos_hbond) , "\n" , aa_pos_hbond , "\n") -############################################################## \ No newline at end of file +############################################################## +# var for position customisation for plots +aa_pos_lig1 = aa_pos_fe +#aa_pos_lig2 = aa_pos_catalytic +#aa_pos_lig3 = aa_pos_hbond \ No newline at end of file diff --git a/scripts/Header_TT.R b/scripts/Header_TT.R index 4bc5792..e9c83e2 100755 --- a/scripts/Header_TT.R +++ b/scripts/Header_TT.R @@ -2,6 +2,7 @@ # A) Installing and loading required packages # B) My functions ######################################################### +check = function(x) tryCatch(if(class(x) == 'logical') 1 else 1, error = function(e) 0) ######################################################### #lib_loc = "/usr/local/lib/R/site-library") diff --git a/scripts/functions/tests/test_lineage_plot_data.R b/scripts/functions/tests/test_lineage_plot_data.R index 4a3c7cf..9763d4f 100644 --- a/scripts/functions/tests/test_lineage_plot_data.R +++ b/scripts/functions/tests/test_lineage_plot_data.R @@ -1,10 +1,10 @@ #!/usr/bin/env Rscript #source("~/git/LSHTM_analysis/config/alr.R") #source("~/git/LSHTM_analysis/config/embb.R") -source("~/git/LSHTM_analysis/config/gid.R") +#source("~/git/LSHTM_analysis/config/gid.R") #source("~/git/LSHTM_analysis/config/katg.R") -#source("~/git/LSHTM_analysis/config/pnca.R") -#source("~/git/LSHTM_analysis/config/rpob.R") +source("~/git/LSHTM_analysis/config/pnca.R") +source("~/git/LSHTM_analysis/config/rpob.R") source("~/git/LSHTM_analysis/scripts/plotting/get_plotting_dfs.R") ##################################################################### diff --git a/scripts/plotting/consurf_plot.R b/scripts/plotting/consurf_plot.R deleted file mode 100644 index 86c1ec1..0000000 --- a/scripts/plotting/consurf_plot.R +++ /dev/null @@ -1,218 +0,0 @@ -consurf_cols = consurf_palette1 -consurf_cols = consurf_palette2 -#consurf_cols = myCOL -consurf_col_labs = c("Insufficient Data" - , "Variable" - , "2", "3", "4", "5" - , "6", "7", "8", "Conserved") - - -#breaks <- levels(as.factor(mtcars$cyl)) -#colours <- ifelse(breaks == 4, "red", "blue") - -aa_position_colname = "position" -length(unique(merged_df3[[aa_position_colname]])) - -positionF <- levels(as.factor(merged_df3[[aa_position_colname]])) -length(positionF) -aa_pos_colours = ifelse(positionF%in%aa_pos_sry, "purple" - , ifelse(positionF%in%aa_pos_rna, "orange", "black" )) -bar = merged_df3 -aa_colour_colname = "lab_bg" - -bar[[aa_colour_colname]] = ifelse(bar[[aa_position_colname]]%in%aa_pos_sry - , "purple" - , ifelse(bar[[aa_position_colname]]%in%aa_pos_rna - , "orange", "white" )) -head(bar[[aa_position_colname]]) -head(bar[[aa_colour_colname]]) - -###################################################################### -my_xlim = length(unique(bar[[aa_position_colname]])); my_xlim - -ymin = min(bar$consurf_score) -ymax = max(bar$consurf_score) - -g = ggplot(bar, aes(x = factor(position) - , y = consurf_score - , colour = factor(consurf_colour_rev))) + - - coord_cartesian(xlim = c(1, my_xlim) - , ylim = c(ymin, ymax) - , clip = "off") + - geom_point() + - scale_colour_manual( values = consurf_cols - , labels = consurf_col_labs - ) + - geom_errorbar(aes(ymin = consurf_ci_lower, ymax = consurf_ci_upper)) - - # g0 = g + geom_tile(aes(,-2, width = 0.95, height = -0.2) - # #, fill = bar$lab_bg - # , fill = bar[[aa_colour_colname]] - # , colour = "white") - - g0 = g + - geom_tile(aes(,-1.7, width = 0.95, height = 0.3) - , fill = bar$ligD_colours - , colour = "black") - - # g0 = g + - # geom_tile(aes(,-1.9, width = 0.95, height = 0.2) - # , fill = bar[[aa_colour_colname4]] - # , colour = "white") + - # geom_tile(aes(,-2, width = 0.95, height = 0.3) - # , fill = bar[[aa_colour_colname3]] - # , colour = "white" - # )+ - # geom_tile(aes(,-2.1, width = 0.95, height = 0.35) - # , fill = bar[[aa_colour_colname2]] - # , colour = "white" - # )+ - # geom_tile(aes(,-2.2, width = 0.95, height = 0.45) - # , fill = bar[[aa_colour_colname1]] - # , colour = "white" - # ) - -g1 = g + theme( axis.text.x = element_text(size = 10 - , angle = 90 - , hjust = 1 - , vjust = 0.4 - , face = "bold" - #, colour = aa_pos_colours - ) - , axis.text.y = element_text(size = 12 - , angle = 0 - , hjust = 1 - , vjust = 0) - , axis.title.x = element_text(size = 12) - , axis.title.y = element_text(size =12 ) - , panel.background = element_rect(fill = "black", color = "black") - , panel.grid.major = element_line(color = "black") - , panel.grid.minor = element_line(color = "black")) + - guides(colour = guide_legend(title = "Consurf" - , position = "top" - #, direction = "horizontal" - )) + - labs(title = "" - #, x = "Wild-type position" - , x = "" - , y = "Consurf score") - -g1 - -# add tile afterwards -g2 = g1 + geom_tile(aes(,-1.7, width = 0.95, height = 0.3) - , fill = bar$ligD_colours - , colour = "black") -g2 - -g3 = g2 + - geom_tile(aes(,-1.9, width = 0.95, height = 0.3) - , fill = bar[[aa_colour_colname4]] - , colour = "white") + - geom_tile(aes(,-2, width = 0.95, height = 0.3) - , fill = bar[[aa_colour_colname3]] - , colour = "white" - )+ - geom_tile(aes(,-2.1, width = 0.95, height = 0.35) - , fill = bar[[aa_colour_colname2]] - , colour = "white" - )+ - geom_tile(aes(,-2.2, width = 0.95, height = 0.35) - , fill = bar[[aa_colour_colname1]] - , colour = "white" - ) - -g3 - -#============================================== -#Multiple legends in a plot with geom_tile -#============================================== - -# https://stackoverflow.com/questions/24822621/multiple-legends-in-a-plot-with-geom-tile -g_legend<-function(a.gplot){ - tmp <- ggplot_gtable(ggplot_build(a.gplot)) - leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box") - legend <- tmp$grobs[[leg]] - legend -} - -legend1 = g_legend(g1) - -g2 = g1 + geom_tile(aes(,-1.7, width = 0.95, height = 0.3) - , fill = bar$ligD_colours - , colour = "black") - -g2 - -legend2 = g_legend(g2) - -grid.arrange(g1+theme(legend.position = 'none') - #, legend1 - , legend2 - , ncol = 2 - , widths=c(4/6, 1/6)) -############################################################### -############################################################### - -lig_min = min(round(bar[[LigDist_colname]])); lig_min -lig_max = max(round(bar[[LigDist_colname]])); lig_max -lig_mean = round(mean(bar[[LigDist_colname]])); lig_mean -labels = seq(lig_min, lig_max, len = 5); labels -labelsD = round(labels, digits = 0); labelsD - -g = ggplot(bar, aes( x = factor(.data[[aa_position_colname]]) - , y = .data[[LigDist_colname]])) -g -# yayy -g1 = g + geom_tile(aes(fill = .data[[LigDist_colname]]) - , colour = "white") + - #scale_fill_gradient(low = "green", high = "red") - scale_fill_gradient2(midpoint = lig_mean - , low = "green" - , mid = "yellow" - , high = "red" - , breaks = labels - #, n.breaks = 11 - #, minor_breaks = c(2, 4, 6, 8, 10) - , limits = c(lig_min, lig_max) - , labels = labelsD - , name = "Ligand Distance") -g1 - - -main_leg = g_legend(g2) -main_leg - -ligD_leg = g_legend(g1) -grid.arrange(ligD_leg - , ncol = 2 - , widths=c(4/6, 1/6)) - -grid.arrange(g2+theme(legend.position = 'none') - , main_leg - , ligD_leg - , ncol = 3 - , widths=c(9/10, 0.5/10, 0.5/10)) - - -########################## -g3 = g2 + theme(legend.position = 'none') -g3 -g4 = g3 + geom_tile(aes(fill = .data[['consurf_score']]) - , colour = "white") - -g4 + geom_tile(scale_fill_gradient(consurf_palette2) - - - midpoint = lig_mean - , low = "green" - , mid = "yellow" - , high = "red" - , breaks = labels - #, n.breaks = 11 - #, minor_breaks = c(2, 4, 6, 8, 10) - , limits = c(lig_min, lig_max) - , labels = labelsD - , name = "Ligand Distance") -g1