saving changes

This commit is contained in:
Tanushree Tunstall 2022-02-14 11:14:40 +00:00
parent 6ffb084546
commit 18e1f14455
7 changed files with 26 additions and 228 deletions

View file

@ -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

View file

@ -81,11 +81,12 @@ aa_pos_sry = sort(unique(c(
, 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

View file

@ -102,3 +102,5 @@ cat("\n==================================================="
, aa_pos_hem, "\n")
##############################################################
# var for position customisation for plots
aa_pos_lig1 = aa_pos_hem

View file

@ -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"
@ -50,3 +50,7 @@ cat("\n==================================================="
, aa_pos_hbond , "\n")
##############################################################
# var for position customisation for plots
aa_pos_lig1 = aa_pos_fe
#aa_pos_lig2 = aa_pos_catalytic
#aa_pos_lig3 = aa_pos_hbond

View file

@ -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")

View file

@ -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")
#####################################################################

View file

@ -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