inst/scripts/analysis/plots/hbonds/geo_dim_2d/chi_BAH_eq_polar_density_PBAtoPBA.R

# -*- 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_PBAtoPBA",
author = "Matthew O'Meara",
brief_description = "",
feature_reporter_dependencies = c("HBondFeatures"),
run=function(self, sample_sources, output_dir, output_formats){


sele <-"
SELECT
	geom.AHdist,
	geom.cosBAH,
	geom.chi,
  don_site.HBChemType AS don_chem_type,
  acc_site.HBChemType AS acc_chem_type,
	CASE don_site.resNum - acc_site.resNum
		WHEN -1 THEN '-1' WHEN -2 THEN '-2' WHEN -3 THEN '-3' WHEN -4 THEN '-4'
		WHEN 2 THEN '2' WHEN 3 THEN '3' WHEN 4 THEN '4' WHEN 5 THEN '5'
		ELSE 'long' END AS seq_sep
FROM
	hbond_geom_coords AS geom,
	hbonds AS hbond,
	hbond_sites AS don_site,
	hbond_sites AS acc_site
WHERE
  don_site.HBChemType == 'hbdon_PBA' AND acc_site.HBChemType == 'hbacc_PBA' AND
	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
	ABS(don_site.resNum - acc_site.resNum) > 5;";
f <- query_sample_sources(sample_sources, sele)

f <- ddply(f, c("sample_source"),
	transform, counts = length(sample_source))

#equal area projection
f <- transform(f,
	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

narrow_output_formats <- transform(output_formats, width=height)

plot_parts <- list(
	theme_bw(),
	theme(panel.background=element_rect(fill="#00007F", colour="#00007F")),
	geom_raster(aes(x=x, y=y, fill=z)),
	geom_indicator(aes(indicator=counts), color="white", group=1),
	polar_equal_area_grids_bw(scale=.4, label_scale=.6),
	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()))

d_ply(f, .(sample_source), function(sub_f){
	ss_id <- sub_f$sample_source[1]
	ss = sample_sources[sample_sources$sample_source == ss_id,]

	plot_id = paste("chi_BAH_eq_polar_density_lr_bbbb", ss_id, sep="_")
	dens <- estimate_density_2d(
		subset(sub_f, seq_sep='long'), c(), "capx", "capy", n_pts=500, scaled=T)
	ggplot(data=dens) + plot_parts +
		ggtitle(paste("Hydrogen Bonds chi vs BAH Angles with Sequence Separation > 5\nBackbone/Backbone Hydrogen Bonds\nEqual Coordinate Projection   Sample Source: ", ss_id, sep=""))
	save_plots(self, plot_id, ss, output_dir, narrow_output_formats)


	plot_id = paste("chi_BAH_eq_polar_density_PBAtoPBA_by_sequence_separation", ss_id, sep="_")
	dens <- estimate_density_2d(
		sub_f, c("seq_sep"), "capx", "capy", n_pts=500, scaled=T)
	ggplot(data=dens) + plot_parts +
		facet_wrap( ~ seq_sep) +
		ggtitle(paste("Hydrogen Bonds chi vs BAH Angles\nBackbone-Backbone Hydrogen Bonds by sequence separation\nEqual Coordinate Projection   Sample Source: ", ss_id, sep=""))
	save_plots(self, plot_id, ss, output_dir, narrow_output_formats)

})


})) # end FeaturesAnalysis
momeara/RosettaFeatures documentation built on May 23, 2019, 6:07 a.m.