Skip to content

Commit

Permalink
updated documentation for feature functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole Kramer committed Jan 21, 2021
1 parent d0df2ba commit 9643ad5
Show file tree
Hide file tree
Showing 62 changed files with 1,155 additions and 929 deletions.
13 changes: 9 additions & 4 deletions R/bb_annoBedpeAnchors.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#' Annotate vertical boxes at anchors of BEDPE elements
#'
#' @usage bb_annoBedpeAnchors(bedpePlot, x, y, height, just = c("left", "top"), default.units = "inches")
#' @usage
#' bb_annoBedpeAnchors(bedpePlot, x, y, height,
#' just = c("left", "top"),
#' default.units = "inches")
#'
#' @param bedpePlot BEDPE plot object from \code{bb_plotBedpe} or \code{bb_plotBedpeArches} with which to highlight the anchors of BEDPE elements.
#' @param fill Character value specifying fill color of highlight boxes. Default value is \code{fill = "lightgrey"}.
Expand All @@ -24,11 +27,13 @@
#' bb_pageCreate(width = 4, height = 2.5, default.units = "inches", xgrid = 0, ygrid = 0)
#'
#' ## Plot and place a BEDPE arches plot
#' bedpeArches <- bb_plotBedpeArches(bedpeData = bb_bedpeData, chrom = "chr21", chromstart = 28000000, chromend = 30300000, linecolor = "black",
#' x = 0.5, y = 0.5, width = 3, height = 1, just = c("left", "top"), default.units = "inches")
#' bedpeArches <- bb_plotBedpeArches(bedpeData = bb_bedpeData, chrom = "chr21", chromstart = 28000000, chromend = 30300000,
#' linecolor = "black", x = 0.5, y = 0.5, width = 3, height = 1,
#' just = c("left", "top"), default.units = "inches")
#'
#' ## Annotate anchors
#' bb_annoBedpeAnchors(bedpePlot = bedpeArches, fill = "steel blue", x = 0.5, y = 1.5, height = 0.5, default.units = "inches")
#' bb_annoBedpeAnchors(bedpePlot = bedpeArches, fill = "steel blue",
#' x = 0.5, y = 1.5, height = 0.5, default.units = "inches")
#'
#' @export
bb_annoBedpeAnchors <- function(bedpePlot, fill = "lightgrey", linecolor = NA, alpha = 0.4, x, y, height, just = c("left", "top"), default.units = "inches", params = NULL){
Expand Down
14 changes: 9 additions & 5 deletions R/bb_annoHeatmapLegend.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#' Add a color scale legend for heatmap-style plots
#'
#' @usage bb_annoHeatmapLegend(heatmapPlot, x, y, width, height, just = c("left", "top"), default.units = "inches")
#' @usage
#' bb_annoHeatmapLegend(heatmapPlot, x, y, width,
#' height, just = c("left", "top"),
#' default.units = "inches")
#'
#' @param heatmapPlot Heatmap-style plot object to add heatmap legend for.
#' @param orientation A string specifying legend orientation. Default value is \code{orientation = "v"}. Options are:
#' \itemize{
#' \item{\code{"v"}:}{Vertical legend orientation.}
#' \item{\code{"h"}:}{Horizontal legend orientation.}
#' \item{\code{"v"}: }{Vertical legend orientation.}
#' \item{\code{"h"}: }{Horizontal legend orientation.}
#' }
#' @param fontsize A numeric specifying text fontsize in points. Default value is \code{fontsize = 8}.
#' @param fontcolor Character value specfying text fontcolor. Default value is \code{fontcolor = "dark grey"}.
Expand All @@ -31,8 +34,9 @@
#' bb_pageCreate(width = 4, height = 3.5, default.units = "inches", xgrid = 0, ygrid = 0)
#'
#' ## Plot and place a square Hi-C plot
#' hicPlot <- bb_plotHicSquare(hicData = bb_hicData, resolution = 10000, zrange = c(0, 70), chrom = "chr21", chromstart = 28000000, chromend = 30300000,
#' x = 0.5, y = 0.5, width = 2.5, height = 2.5, just = c("left", "top"), default.units = "inches")
#' hicPlot <- bb_plotHicSquare(hicData = bb_hicData, resolution = 10000, zrange = c(0, 70),
#' chrom = "chr21", chromstart = 28000000, chromend = 30300000,
#' x = 0.5, y = 0.5, width = 2.5, height = 2.5, just = c("left", "top"), default.units = "inches")
#'
#' ## Add heatmap legend
#' bb_annoHeatmapLegend(heatmapPlot = hicPlot, x = 3.2, y = 0.5, width = 0.25, height = 0.75, just = c("left", "top"), default.units = "inches")
Expand Down
41 changes: 21 additions & 20 deletions R/bb_annoLoops.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
#' @param bedpeData A string specifying the BEDPE file path or a dataframe in BEDPE format specifying loop positions.
#' @param type Character value specifying type of annotation. Default value is \code{type = "box"}. Options are:
#' \itemize{
#' \item{\code{"box"}:}{Boxes are drawn around each loop.}
#' \item{\code{"circle"}:}{Circles are drawn around each loop.}
#' \item{\code{"arrow"}:}{Arrows are drawn pointing to each loop.}
#' \item{\code{"box"}: }{Boxes are drawn around each loop.}
#' \item{\code{"circle"}: }{Circles are drawn around each loop.}
#' \item{\code{"arrow"}: }{Arrows are drawn pointing to each loop.}
#' }
#' @param half Character value specifying which half of hic plots to annotate. Triangle Hi-C plots will always default to the entirety of the triangular plot. Default value is \code{half = "inherit"}. Options are:
#' \itemize{
#' \item{\code{"inherit"}:}{Loops will be annotated on the \code{half} inherited by the input Hi-C plot.}
#' \item{\code{"both"}:}{Loops will be annotated on both halves of the diagonal of a square Hi-C plot.}
#' \item{\code{"top"}:}{Loops will be annotated on the upper diagonal half of a square Hi-C plot.}
#' \item{\code{"bottom"}:}{Loops will be annotated ont the bottom diagonal half of a square Hi-C plot.}
#' \item{\code{"inherit"}: }{Loops will be annotated on the \code{half} inherited by the input Hi-C plot.}
#' \item{\code{"both"}: }{Loops will be annotated on both halves of the diagonal of a square Hi-C plot.}
#' \item{\code{"top"}: }{Loops will be annotated on the upper diagonal half of a square Hi-C plot.}
#' \item{\code{"bottom"}: }{Loops will be annotated ont the bottom diagonal half of a square Hi-C plot.}
#' }
#' @param shift Numeric specifying the number of pixels on either end of loop in a box or circle. Numeric specifying number of pixels for the length of an arrow.
#' @param params An optional \link[BentoBox]{bb_assembly} object containing relevant function parameters.
Expand All @@ -32,8 +32,9 @@
#' bb_pageCreate(width = 3, height = 3, default.units = "inches", xgrid = 0, ygrid = 0)
#'
#' ## Plot and place a square Hi-C plot
#' hicPlot <- bb_plotHicSquare(hicData = bb_hicData, resolution = 10000, zrange = c(0, 70), chrom = "chr21", chromstart = 28000000, chromend = 30300000,
#' x = 0, y = 0, width = 3, height = 3, just = c("left", "top"), default.units = "inches")
#' hicPlot <- bb_plotHicSquare(hicData = bb_hicData, resolution = 10000, zrange = c(0, 70),
#' chrom = "chr21", chromstart = 28000000, chromend = 30300000,
#' x = 0, y = 0, width = 3, height = 3, just = c("left", "top"), default.units = "inches")
#'
#' ## Annotate loops of Hi-C plot
#' bb_annoLoops(hicPlot = hicPlot, bedpeData = bb_bedpeData, type = "box", half = "both")
Expand All @@ -53,9 +54,9 @@ bb_annoLoops <- function(hicPlot, bedpeData, type = "box", half = "inherit", shi
###### hic #####

## check type of input for hic
if (!class(hic) %in% c("bb_hic", "bb_trianglehic" )){
if (!class(hic) %in% c("bb_hicSquare", "bb_hicTriangle" )){

stop("Input plot must be a plot of class \'bb_hic\' or \'bb_trianglehic\'.", call. = FALSE)
stop("Input plot must be a plot of class \'bb_hicSquare\' or \'bb_hicTriangle\'.", call. = FALSE)

}

Expand All @@ -64,7 +65,7 @@ bb_annoLoops <- function(hicPlot, bedpeData, type = "box", half = "inherit", shi
## if loops is a dataframe or datatable, it needs to be properly formatted
if ("data.frame" %in% class(loops) && ncol(loops) < 6){

stop("Invalid dataframe format. Dataframe must be in bedpe format.", call. = FALSE)
stop("Invalid dataframe format. Dataframe must be in BEDPE format.", call. = FALSE)

}

Expand Down Expand Up @@ -140,11 +141,11 @@ bb_annoLoops <- function(hicPlot, bedpeData, type = "box", half = "inherit", shi

}

} else if (class(hic) == "bb_trianglehic"){
} else if (class(hic) == "bb_hicTriangle"){

if (half == "both" | half == "bottom"){

warning("Plot of class \'bb_trianglehic\' detected. Loops will automatically be annotated in the upper triangular of the plot.", call. = FALSE)
warning("Plot of class \'bb_hicTriangle\' detected. Loops will automatically be annotated in the upper triangular of the plot.", call. = FALSE)

}

Expand All @@ -167,7 +168,7 @@ bb_annoLoops <- function(hicPlot, bedpeData, type = "box", half = "inherit", shi
## chrom always in col1
## altchrom always in col4
## triangle hic plots will not have altchrom parameters
if (class(hic) == "bb_trianglehic"){
if (class(hic) == "bb_hicTriangle"){
loops_subset <- loops[which(loops[,1] == object$chrom & loops[,4] == object$chrom & loops[,2] >= object$chromstart & loops[,3] <= object$chromend
& loops[,5] >= object$chromstart & loops[,6] <= object$chromend),]
} else {
Expand All @@ -182,7 +183,7 @@ bb_annoLoops <- function(hicPlot, bedpeData, type = "box", half = "inherit", shi
## Define a function that parses an inherited half
inherit_half <- function(hic){

if (class(hic) == "bb_hic"){
if (class(hic) == "bb_hicSquare"){

if (is.null(hic$althalf)){

Expand All @@ -194,7 +195,7 @@ bb_annoLoops <- function(hicPlot, bedpeData, type = "box", half = "inherit", shi

}

} else if (class(hic) == "bb_trianglehic"){
} else if (class(hic) == "bb_hicTriangle"){

half <- "top"

Expand Down Expand Up @@ -398,7 +399,7 @@ bb_annoLoops <- function(hicPlot, bedpeData, type = "box", half = "inherit", shi

}

if (class(bb_loopsInternal$hicPlot) == "bb_trianglehic"){
if (class(bb_loopsInternal$hicPlot) == "bb_hicTriangle"){

half <- "top"

Expand Down Expand Up @@ -455,7 +456,7 @@ bb_annoLoops <- function(hicPlot, bedpeData, type = "box", half = "inherit", shi
vp_name <- paste0("bb_loopAnnotation", length(grep(pattern = "bb_loopAnnotation", x = currentViewports)) + 1)

## Make viewport based on hic input viewport
if (class(bb_loopsInternal$hicPlot) == "bb_hic"){
if (class(bb_loopsInternal$hicPlot) == "bb_hicSquare"){

vp <- viewport(height = bb_loopsInternal$hicPlot$grobs$vp$height, width = bb_loopsInternal$hicPlot$grobs$vp$width,
x = bb_loopsInternal$hicPlot$grobs$vp$x, y = bb_loopsInternal$hicPlot$grobs$vp$y,
Expand All @@ -464,7 +465,7 @@ bb_annoLoops <- function(hicPlot, bedpeData, type = "box", half = "inherit", shi
yscale = bb_loopsInternal$hicPlot$grobs$vp$yscale,
just = bb_loopsInternal$hicPlot$grobs$vp$justification,
name = vp_name)
} else if (class(bb_loopsInternal$hicPlot) == "bb_trianglehic"){
} else if (class(bb_loopsInternal$hicPlot) == "bb_hicTriangle"){


width <- convertUnit(bb_loopsInternal$hicPlot$outsideVP$width, unitTo = get("page_units", bbEnv), valueOnly = T)
Expand Down
6 changes: 3 additions & 3 deletions R/bb_annoXaxis.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#' @param label A logical value indicating whether to draw the labels on the tick marks, or an expression or character vector which specify the labels to use. If not logical, must be the same length as the \code{at} argument.
#' @param main A logical value indicating whether to draw the x-axis at the bottom of the plot. Default value is \code{main = TRUE}. Options are:
#' \itemize{
#' \item{\code{TRUE}:}{x-axis is drawn at the bottom of the plot.}
#' \item{\code{FALSE}:}{x-axis is drawn at the top of the plot.}
#' \item{\code{TRUE}: }{x-axis is drawn at the bottom of the plot.}
#' \item{\code{FALSE}: }{x-axis is drawn at the top of the plot.}
#' }
#' @param gp Grid graphical parameters. See \link[grid]{gpar}.
#' @param params An optional \link[BentoBox]{bb_assembly} object containing relevant function parameters.
Expand All @@ -25,7 +25,7 @@
#'
#' ## Plot gene transcripts
#' transcriptPlot <- bb_plotTranscripts(chrom = "chr1", chromstart = 1000000, chromend = 2000000,
#' x = 0, y = 0, width = 3, height = 1.5, just = c("left", "top"), default.units = "inches")
#' x = 0, y = 0, width = 3, height = 1.5, just = c("left", "top"), default.units = "inches")
#'
#' ## Add standard x-axis to transcript plot
#' bb_annoXaxis(plot = transcriptPlot, at = c(1000000, 1250000, 1500000, 1750000, 2000000), gp = gpar(fontsize = 8))
Expand Down
6 changes: 3 additions & 3 deletions R/bb_annoYaxis.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#' If not logical, must be the same length as the \code{at} argument.
#' @param main A logical value indicating whether to draw the y-axis at the left of the plot. Default value is \code{main = TRUE}. Options are:
#' \itemize{
#' \item{\code{TRUE}:}{y-axis is drawn at the left of the plot.}
#' \item{\code{FALSE}:}{y-axis is drawn at the right of the plot.}
#' \item{\code{TRUE}: }{y-axis is drawn at the left of the plot.}
#' \item{\code{FALSE}: }{y-axis is drawn at the right of the plot.}
#' }
#' @param gp Grid graphical parameters. See \link[grid]{gpar}.
#' @param params An optional \link[BentoBox]{bb_assembly} object containing relevant function parameters.
Expand All @@ -25,7 +25,7 @@
#'
#' ## Plot and place a square Hi-C plot
#' hicPlot <- bb_plotHicSquare(hicData = bb_hicData, resolution = 10000, zrange = c(0, 70), chrom = "chr21", chromstart = 28000000, chromend = 30300000,
#' x = 1, y = 0.5, width = 2.5, height = 2.5, just = c("left", "top"), default.units = "inches")
#' x = 1, y = 0.5, width = 2.5, height = 2.5, just = c("left", "top"), default.units = "inches")
#'
#' ## Add standard y-axis to Hi-C plot
#' bb_annoYaxis(plot = hicPlot, at = c(28000000, 29000000, 30300000), gp = gpar(fontsize = 8))
Expand Down
10 changes: 7 additions & 3 deletions R/bb_assembly.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Make a \code{bb_assembly} object for alternate TxDB, OrgDb,and BSgenome genomic annotation packages
#' Make a \code{bb_assembly} object for alternate TxDb, OrgDb,and BSgenome genomic annotation packages
#'
#' @usage bb_assembly(Genome, TxDb, OrgDb)
#'
Expand All @@ -15,8 +15,12 @@
#'
#' @examples
#' ## Create a custom bb_assembly object for hg38/GRCh38 packages
#' newAssembly <- bb_assembly(Genome = "hg38_GRCh38", TxDb = "TxDb.Hsapiens.UCSC.hg38.knownGene",
#' OrgDb = "org.Hs.eg.db", BSgenome = "BSgenome.Hsapiens.NCBI.GRCh38")
#' newAssembly <- bb_assembly(Genome = "hg38_GRCh38",
#' TxDb = "TxDb.Hsapiens.UCSC.hg38.knownGene",
#' OrgDb = "org.Hs.eg.db",
#' BSgenome = "BSgenome.Hsapiens.NCBI.GRCh38")
#'
#' @seealso \link[GenomicFeatures]{TxDb}, \link[AnnotationDb]{OrgDb-class}, \link[BSgenome]{BSgenome}
#'
#' @export
bb_assembly <- function(Genome, TxDb, OrgDb, gene.id.column = "ENTREZID", display.column = "SYMBOL", BSgenome = NULL){
Expand Down
4 changes: 3 additions & 1 deletion R/bb_pageCreate.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#' Create a page for a BentoBox layout
#'
#' @usage bb_pageCreate(width = 8.5, height = 11, default.units = "inches")
#' @usage
#' bb_pageCreate(width = 8.5, height = 11,
#' default.units = "inches")
#'
#' @param width A numeric or unit object specifying page width. Default value is \code{width = 8}.
#' @param height A numeric or unit object specifying page height. Default value is \code{height = 11}.
Expand Down
2 changes: 2 additions & 0 deletions R/bb_pageGuideShow.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#' Reshow guides drawn with \code{bb_pageCreate}, \code{bb_pageGuideHorizontal}, and \code{bb_pageGuideVertical}
#'
#'
#' @seealso \link[BentoBox]{bb_pageCreate}, \link[BentoBox]{bb_pageGuideHorizontal}, \link[BentoBox]{bb_pageGuideVertical}
#' @export
bb_pageGuideShow <- function(){

Expand Down
10 changes: 7 additions & 3 deletions R/bb_pagePlotPlace.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#' Place a BentoBox plot that has been previously created but not drawn
#'
#' @usage
#' bb_pagePlotPlace(plot, x, y, width, height, just = c("left", "top"), default.units = "inches")
#' bb_pagePlotPlace(plot, x, y, width, height,
#' just = c("left", "top"),
#' default.units = "inches")
#'
#' @param plot BentoBox plot object to be placed, defined by the output of a BentoBox plotting function.
#' @param x A numeric or unit object specifying plot x-location.
Expand All @@ -21,13 +23,15 @@
#' data("bb_hicData")
#'
#' ## Create, but do not plot, square Hi-C plot
#' hicPlot <- bb_plotHicSquare(hicData = bb_hicData, resolution = 10000, zrange = c(0, 70), chrom = "chr21", chromstart = 28000000, chromend = 30300000, draw = FALSE)
#' hicPlot <- bb_plotHicSquare(hicData = bb_hicData, resolution = 10000, zrange = c(0, 70),
#' chrom = "chr21", chromstart = 28000000, chromend = 30300000, draw = FALSE)
#'
#' ## Create BentoBox page
#' bb_pageCreate(width = 4, height = 3.5, default.units = "inches", xgrid = 0, ygrid = 0)
#'
#' ## Place Hi-C plot on BentoBox page
#' bb_pagePlotPlace(plot = hicPlot, x = 0.5, y = 0.5, width = 2.5, height = 2.5, just = c("left", "top"), default.units = "inches", draw = TRUE)
#' bb_pagePlotPlace(plot = hicPlot,
#' x = 0.5, y = 0.5, width = 2.5, height = 2.5, just = c("left", "top"), default.units = "inches", draw = TRUE)
#'
#' @export
bb_pagePlotPlace <- function(plot, x = NULL, y = NULL, width = NULL, height = NULL, just = c("left", "top"), default.units = "inches",
Expand Down
9 changes: 5 additions & 4 deletions R/bb_pagePlotRemove.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#' bb_pageCreate(width = 4, height = 3.5, default.units = "inches", xgrid = 0, ygrid = 0)
#'
#' ## Plot and place a square Hi-C plot
#' hicPlot <- bb_plotHicSquare(hicData = bb_hicData, resolution = 10000, zrange = c(0, 70), chrom = "chr21", chromstart = 28000000, chromend = 30300000,
#' x = 0.5, y = 0.5, width = 2.5, height = 2.5, just = c("left", "top"), default.units = "inches")
#' hicPlot <- bb_plotHicSquare(hicData = bb_hicData, resolution = 10000, zrange = c(0, 70),
#' chrom = "chr21", chromstart = 28000000, chromend = 30300000,
#' x = 0.5, y = 0.5, width = 2.5, height = 2.5, just = c("left", "top"), default.units = "inches")
#'
#' ## Remove square Hi-C plot from page
#' bb_pagePlotRemove(plot = hicPlot)
Expand All @@ -25,8 +26,8 @@ bb_pagePlotRemove <- function(plot){
grid.remove(gPath(plot$grobs$name))


## Need to remove outer viewport of bb_trianglehic plot
if (class(plot) == "bb_trianglehic"){
## Need to remove outer viewport of bb_hicTriangle plot
if (class(plot) == "bb_hicTriangle"){
vp_name <- plot$grobs$vp$name
vp_name <- gsub("inside", "outside", vp_name)
seekViewport(vp_name)
Expand Down
8 changes: 6 additions & 2 deletions R/bb_plotBase.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#' Plot a base R plot in a BentoBox layout
#'
#' @usage bb_plotBase(basePlot, x, y, width, height, just = c("left", "top"), default.units = "inches")
#' @usage
#' bb_plotBase(basePlot, x, y, width, height,
#' just = c("left", "top"),
#' default.units = "inches")
#'
#' @param basePlot Plot formula of base R plotting functions.
#' @param x A numeric or unit object specifying plot x-location.
Expand All @@ -23,7 +26,8 @@
#' bb_pageCreate(width = 5, height = 5, default.units = "inches", xgrid = 0, ygrid = 0)
#'
#' ## Place base R plot in BentoBox page
#' bb_plotBase(basePlot = p, x = 0.5, y = 0.5, width = 4, height = 4, just = c("left", "top"), default.units = "inches")
#' bb_plotBase(basePlot = p,
#' x = 0.5, y = 0.5, width = 4, height = 4, just = c("left", "top"), default.units = "inches")
#'
#' @export
bb_plotBase <- function(basePlot, x, y, width, height, just = c("left", "top"), default.units = "inches", bg = NA, params = NULL){
Expand Down
6 changes: 4 additions & 2 deletions R/bb_plotBedpe.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#'
#' @usage
#' bb_plotBedpe(bedpeData, chrom)
#' bb_plotBedpe(bedpeData, chrom, x, y, width, height, just = c("left", "top"), default.units = "inches")
#' bb_plotBedpe(bedpeData, chrom, x, y, width, height,
#' just = c("left", "top"),
#' default.units = "inches")
#'
#' @param bedpeData A string specifying the BEDPE file path or a dataframe in BEDPE format specifying data to be plotted.
#' @param chrom Chromosome of region to be plotted, as a string.
Expand Down Expand Up @@ -40,7 +42,7 @@
#' ## Plot and place BEDPE plot on a BentoBox page
#' bb_pageCreate(width = 5, height = 2, default.units = "inches", xgrid = 0, ygrid = 0)
#' bedpePlot <- bb_plotBedpe(bedpeData = bb_bedpeData, chrom = "chr21", chromstart = 28000000, chromend = 30300000,
#' x = 0.5, y = 0.5, width = 4, height = 1, just = c("left", "top"), default.units = "inches")
#' x = 0.5, y = 0.5, width = 4, height = 1, just = c("left", "top"), default.units = "inches")
#'
#' @export
bb_plotBedpe <- function(bedpeData, chrom, chromstart = NULL, chromend = NULL, assembly = "hg19", fill = "black", colorby = NULL, linecolor = NA,
Expand Down
Loading

0 comments on commit 9643ad5

Please sign in to comment.