# -*- tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
# vi: set ts=2 noet:
#
# (c) Copyright Rosetta Commons Member Institutions.
# (c) This file is part of the Rosetta software suite and is made available under license.
# (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
# (c) For more information, see http://www.rosettacommons.org. Questions about this can be
# (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
library(ggplot2)
library(plyr)
library(viridis)
feature_analyses <- c(feature_analyses, methods::new("FeaturesAnalysis",
id = "chi_BAH_eq_polar_density_bb_by_ss",
author = "Matthew O'Meara",
brief_description = "",
feature_reporter_dependencies = c("HBondFeatures"),
run=function(self, sample_sources, output_dir, output_formats){
sele <-"
SELECT
geom.cosBAH,
geom.chi,
don_ss.dssp AS don_ss, acc_ss.dssp AS acc_ss
FROM
hbond_geom_coords AS geom,
hbonds AS hbond,
hbond_sites AS don_site,
hbond_sites AS acc_site,
residue_secondary_structure AS don_ss,
residue_secondary_structure AS acc_ss
WHERE
hbond.struct_id = geom.struct_id AND hbond.hbond_id = geom.hbond_id AND
hbond.struct_id = don_site.struct_id AND hbond.don_id = don_site.site_id AND
hbond.struct_id = acc_site.struct_id AND hbond.acc_id = acc_site.site_id AND
don_ss.struct_id = don_site.struct_id AND don_ss.resNum = don_site.resNum AND
acc_ss.struct_id = acc_site.struct_id AND acc_ss.resNum = acc_site.resNum AND
don_site.HBChemType = 'hbdon_PBA' AND acc_site.HBChemType = 'hbacc_PBA';"
f <- query_sample_sources(sample_sources, sele)
# The coding for loop and irregular is " ", change this to "C"
levels(f$acc_ss)[levels(f$acc_ss) == " "] <- "C"
levels(f$don_ss)[levels(f$don_ss) == " "] <- "C"
#equal area projection
f <- with(f,
data.frame(
sample_source=sample_source,
don_ss_name = factor(don_ss,
levels = c("H", "E", "T", "G", "B", "S", "I", "C"),
labels = c('H: a-Helix', 'E: b-Sheet', 'T: HB Turn', 'G: 3/10 Helix',
'B: b-Bridge', 'S: Bend', 'I: pi-Helix','C: Irregular')),
acc_ss_name = factor(f$acc_ss,
levels = c("H", "E", "T", "G", "B", "S", "I", "C"),
labels = c('H: a-Helix', 'E: b-Sheet', 'T: HB Turn', 'G: 3/10 Helix',
'B: b-Bridge', 'S: Bend', 'I: pi-Helix','C: Irregular')),
capx = 2*sin(acos(cosBAH)/2)*cos(chi),
capy = 2*sin(acos(cosBAH)/2)*sin(chi)))
capx_limits <- c(-1.5,1.5); capy_limits <- capx_limits;
f <- na.omit(f, method="r")
plot_parts <- list(
theme_bw(),
theme(panel.background=element_rect(fill="#00007F", colour="#00007F")),
geom_raster(aes(x=x, y=y, fill=log(z+1))),
geom_indicator(aes(indicator=counts), color="white", group=1),
coord_equal(ratio=1),
scale_fill_viridis("Density"),
scale_x_continuous('', limits=capx_limits, breaks=c()),
scale_y_continuous('', limits=capy_limits, breaks=c()),
theme(
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank()))
#plot_id = "chi_sinBAH_eq_polar_density_bb_by_dssp_all"
#d_ply(sample_sources
# f[,c("sample_source", "don_ss_name", "acc_ss_name", "capx", "capy")],
# .(sample_source), function(sub_f){
#
# ss_id <- sub_f$sample_source[1]
# plot_id <- paste(plot_id, ss_id, sep="_")
# dens <- estimate_density_2d(
# sub_f, c("don_ss_name", "acc_ss_name"), "capx", "capy")
# ggplot(dens) + plot_parts +
# polar_equal_area_grids_bw(scale=.6, label_scale=.4) +
# ggtitle(paste("Backbone-Backbone HBonds: CHI vs BAH Angles by DSSP\nEqual Coordinate Projection Sample Source: ", ss_id, sep="")) +
# facet_grid(don_ss_name ~ acc_ss_name) +
# save_plots(self, plot_id, sample_sources, output_dir, output_formats)
#})
#
dens <- estimate_density_2d(
f[f$don_ss_name == f$acc_ss_name,],
c("sample_source", "acc_ss_name"), "capx", "capy", n_pts=100)
scaled_dens <- ddply(dens, .(sample_source, acc_ss_name), function(sub_dens){
max_z <- max(sub_dens$z)
transform(sub_dens, z=z/max_z)
})
plot_id = "chi_sinBAH_eq_polar_density_bb_by_dssp_sample_source"
ggplot(scaled_dens) + plot_parts +
polar_equal_area_grids_bw(scale=.6, label_scale=.4) +
ggtitle("Backbone-Backbone HBonds: CHI vs BAH Angles by DSSP\nEqual Coordinate Projection") +
facet_grid(sample_source ~ acc_ss_name) +
theme(legend.position="bottom", legend.direction="horizontal")
save_plots(self, plot_id, sample_sources, output_dir, output_formats)
})) # end FeaturesAnalysis
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.