#'Plot the abundance of Predicted G-quadruplexes
#'Relative to a Central Postiion
#'
#'Using a vector returned by getQuadCoveragePercentage(),
#'plot the percentage of peaks that have G-quadruplexes across
#'positions in sequences around the ChIP-SEQ peaks
#'
#'@param featurePercentages a numeric vector containing percentages such as
#' a vector returned by getQuadCoveragePercentage()
#'
#'@param title a string specifying the title of the plot
#'
#'@return returns a plot of G-Quadruplex Abundance
#'
#'@examples
#' path <- system.file("extdata", "MAZ_very_small_test.bed", package = "ChIPAnalyzer")
#' reports <- findQuads(bedPath = path,
#' seqWidth = 200,
#' assemblyVersion = "hg19")
#' qMatrix <- getQuadMatrix(quadReports = reports)
#' quadCoveragePercentage <- getQuadCoveragePercentage(quadMatrix = qMatrix)
#' plotQuadPosition(quadCoveragePercentage, "MAZ G-Quad Abundance")
#'
#'@export
plotQuadPosition <- function (featurePercentages, title) {
if (length(featurePercentages) < 1) {
stop("empty vector provided")
}
#calculate the bounds for the x axis
leftBound <- as.integer(-1*floor(length(featurePercentages)/2))
rightBound <- as.integer(ceiling(length(featurePercentages)/2) - 1)
#display the plot
plot(c(leftBound, rightBound),
c(0, 100),
type = "n",
xlab = "Position",
ylab = "Percentage")
lines(x = leftBound:rightBound,
type = "l",
y = featurePercentages,
col = "blue")
abline(v = 0)
title(title)
quadPlot <- recordPlot()
return(quadPlot)
}
#'Generate a Pie Chart of The percentage of ChIP peak nucleotides that
#'are methylated
#'
#'Using the dataframe of methylation data for ChIP peak nucleotides
#' generated by getMethylOverlap, create a pie chart showing the
#' percentage of peak sites that are methylated
#'
#'@param methylOverlapData a data frame with a coverage column specifying
#' the percentage of reads methylated. This column must be named coverage
#'
#'@return returns a pie plot of methylation percentages
#'
#'@examples
#' path1 <- system.file("extdata", "MAZ_high_score.bed", package = "ChIPAnalyzer")
#' path2 <- system.file("extdata", "HcfUMethylData.bed", package = "ChIPAnalyzer")
#' overlap <- getMethylOverlap(path1, path2)
#' plotMethylPercentage(overlap)
#'
#'@export
plotMethylPercentage <- function(methylOverlapData) {
if(nrow(methylOverlapData) < 1) {
stop("empty dataframe provided")
}
#calculate the average percentages of reads methylated at each position
avgPercentMethyl <- mean(methylOverlapData$coverage)
#define the labels and sections for the pie chart
pieLabels <-c(paste(round(avgPercentMethyl, 4), "%"),
paste(round(100 - avgPercentMethyl, 4), "%"))
sections <- c(avgPercentMethyl, 100 - avgPercentMethyl)
#display the plot
pie(sections, pieLabels,
col = c("green", "blue"),
cex = 0.7)
title("Avg % Reads Methylated", cex = 0.3)
legend("topright", c("Methylated", "Not Methylated"),
cex = 0.5, fill= c("green", "blue"))
methylPiePlot <- recordPlot()
return(methylPiePlot)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.