R/polar_landscape.R

#' This function generates the hydrophobicity landscape by computed logP values. The plots are faceted based on the protein chains
#' You can specify a formula to smoothen out the landscape, although the default is specified as a 20 order polynomial.
#' You also have the option to specify more options passed on to the facet wrap function in ggplot2
#' @param mypdb
#' This is an object given processed by pdb_dataframe() and parameters given by assign_params(). If one wants to use a different set of logP values they could alter the assign_params() function or they could add it manually as long as the column is named logP. Additionally one can add their own acidity categories as long as the column name is still "Acidity"
#' @param formulae
#' This is any formula accepted by the geom_smooth() function, defaultd as a 20 order polynomial
#' There is some unexpected activity when tring to throw it diverse functions, works best with a polynomial function and just changing the order like so y~poly(x, degree)
#' @param ...
#' This passes parameters to a facet_wrap() call from ggplot
#' @return
#' This function returns a ggplot2 object with logP vs atomic coordinate plotted
#' @export
#'
#' @examples
#' library(Rpdb)
#' library(tidyverse)
#' library(dplyr)
#' library(ggplot2)
#'
#' y <- pdb_dataframe(CYP)
#' z <- assign_params(y)
#' polar_landscape(z)
#'
polar_landscape <- function(mypdb, formulae = y~stats::poly(x,20), ...){
  if(!(tibble::is.tibble(mypdb))) {
    stop('This function can only handle pdb files processed by pdb_dataframe!\n',
         'You have provided an object of class:', class(mypdb$logP)[1])
  }
  if(!(class(mypdb$logP) == "numeric")) {
    stop('This function can only handle numeric values for the plot!\n',
         'You have provided an object of class:', class(mypdb)[1])
  }
  eleid <- Acidity <- logP <- NULL
  mypdb2 <- stats::na.omit(mypdb)
  ggplot2::ggplot(mypdb2, ggplot2::aes(x = eleid, y = logP)) + ggplot2::geom_smooth(method = 'gam', na.rm =TRUE, formula = formulae) + ggplot2::facet_wrap(~chainid, scales = "free", ...)+ ggplot2::ggtitle("logP Landscape")+ggplot2::labs(x="atom coordinate", y="logP")

}
zalperst/visualizeprot documentation built on May 4, 2019, 9:08 p.m.