Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
^LICENSE\.md$
^icons$
^\.github$
^\.Rlib$
^scripts$
^DEV_PLAN\.md$
^install_deps\.log$
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
.Rhistory
.RData
.Ruserdata
.Rlib/
install_deps.log
src/*.o
src/*.so
src/*.dll
.DS_Store
install_extra.log
Rplots.pdf
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: plotgardener
Title: Coordinate-Based Genomic Visualization Package for R
Version: 1.15.1
Version: 1.15.1.9000
Date: 2024-06-28
Authors@R: c(
person("Nicole", "Kramer", email = "nekramer27@gmail.com",
Expand Down Expand Up @@ -65,6 +65,7 @@ Suggests:
BSgenome,
BSgenome.Hsapiens.UCSC.hg19,
ComplexHeatmap,
ensembldb,
GenomicFeatures,
ggplot2,
InteractionSet,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export(defaultPackages)
export(genomes)
export(mapColors)
export(pageCreate)
export(pageExport)
export(pageGuideHide)
export(pageGuideHorizontal)
export(pageGuideShow)
Expand All @@ -26,6 +27,7 @@ export(pageLayoutCol)
export(pageLayoutRow)
export(pagePlotPlace)
export(pagePlotRemove)
export(pageRedraw)
export(pgParams)
export(plotCircle)
export(plotGG)
Expand Down Expand Up @@ -76,6 +78,7 @@ importFrom(ggplotify,as.grob)
importFrom(ggplotify,base2grob)
importFrom(glue,glue)
importFrom(glue,glue_collapse)
importFrom(grDevices,as.raster)
importFrom(grDevices,colorRampPalette)
importFrom(grDevices,dev.size)
importFrom(methods,hasArg)
Expand All @@ -90,6 +93,7 @@ importFrom(rlang,abort)
importFrom(rlang,arg_match)
importFrom(rlang,inform)
importFrom(rlang,warn)
importFrom(stats,aggregate)
importFrom(stats,na.omit)
importFrom(strawr,readHicBpResolutions)
importFrom(strawr,straw)
Expand Down
58 changes: 58 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
# DEVELOPMENT VERSION
## NEW FEATURES

* Added `pageExport()` for writing the current page to PDF, PNG, TIFF, JPEG,
or SVG without a user `dev.off()` call.
* `pageGuideHide()` and `pagePlotRemove()` now defer removals until
`pageExport()`/`pageRedraw()` instead of calling `grid.remove()` on the
active device, avoiding extra PDF pages.
* `plotHicSquare()`, `plotHicRectangle()`, and `plotHicTriangle()` gain
`raster = c("auto", "never", "always")` and `raster.max` for rasterizing
large contact maps.
* `plotSignal()` gains `label.position`, `label.offset`, numeric baselines,
and `baseline.lty`. Baselines are now drawn after signal/cutoff grobs so
filled tracks cannot cover them.
* `plotMultiSignal()` now honors a user-supplied `range` and passes through
label/baseline styling parameters.
* `annoYaxis()` and `annoXaxis()` gain `tcl`, `label.offset`,
`axisLine.lwd/col/lty`, and `tick.lwd/col/lty` for flexible axis styling.
Default tick length is now shorter (`tcl = 0.25`) and default tick/axis
line width is thinner (`0.5`).
* Interchromosomal `plotHicSquare()` plots are no longer mirrored and store
explicit x/y chromosome metadata for `annoGenomeLabel()`. Add
`aspect = "fixed"` for equal basepairs-per-inch on unequal-length
chromosomes.
* `plotTranscripts()` adds `labelPriority` and centers labels on the
in-bounds transcript portion.
* `plotGenes()` adds `labelClusters`/`labelClusterRot` for dense gene
clusters.
* `assembly()` accepts an `EnsDb` object and converts it to a TxDb for
plotting.
* `read_rangeData()` respects named `chrom`/`start`/`end` or `chrom`/`pos`
columns in any order.
* `annoPixels()` handles factor chromosome columns with different level sets.
* `plotLegend()` documents the cairosvg/SVG rendering caveat.

## BUG FIXES

* `readCool()` now returns all pixels in the final bin of a region. The
previous pixel-range calculation stopped at the first pixel of the last bin.
* `readCool()` applies cooler balancing weights multiplicatively
(`counts * weight1 * weight2`) instead of dividing by them. This also applies
to `sweight`, `KR`, `VC`, and `VC_SQRT` weights.
* `readCoolNorms()` now returns the exact column names stored in the file
(for example `weight`, `sweight`, `KR`, or `obj_weight`) instead of mapping
`weight` to `BALANCE`.
* `readCool()` accepts chromosome names with or without a `chr` prefix and
matches regions that do not start exactly on a bin boundary.
* `readCool()` now reads interchromosomal mcool pixels when the requested
`chrom` comes after `altchrom` in the file, and expands both coordinates for
same-chromosome off-diagonal regions.
* `readCool()` supports `norm = "auto"`, and `plotHicSquare()`,
`plotHicRectangle()`, and `plotHicTriangle()` now use `norm = "auto"` by
default. For `.hic` files this resolves to `"KR"`; for `.(m)cool` files it
chooses an available weight.
* Hi-C plotting no longer requests negative `chromstart` values from
`.hic`/`.(m)cool` files when padding a region near the start of a chromosome.
* `.checkCool()` recognizes `.mcool` files with extra root-level groups.

# VERSION 1.11.2
## NEW FEATURES

Expand Down
75 changes: 66 additions & 9 deletions R/annoGenomeLabel.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,77 @@ annoGenomeLabel <- function(plot, fontsize = 10, fontcolor = "black",
# ASSIGN PARAMETERS BASED ON PLOT INPUT
# =========================================================================

chrom <- genomeLabelInternal$plot$chrom
chromstart <- genomeLabelInternal$plot$chromstart
chromend <- genomeLabelInternal$plot$chromend
assembly <- genomeLabelInternal$plot$assembly
plotObject <- genomeLabelInternal$plot
chrom <- if (!is.null(plotObject$xchrom)) {
plotObject$xchrom
} else {
plotObject$chrom
}
chromstart <- if (!is.null(plotObject$xchromstart)) {
plotObject$xchromstart
} else {
plotObject$chromstart
}
chromend <- if (!is.null(plotObject$xchromend)) {
plotObject$xchromend
} else {
plotObject$chromend
}
assembly <- plotObject$assembly
x <- genomeLabelInternal$x
y <- genomeLabelInternal$y
length <- genomeLabelInternal$plot$width
length <- plotObject$width
if (genomeLabelInternal$axis == "y") {
length <- genomeLabelInternal$plot$height
chrom <- genomeLabelInternal$plot$altchrom
chromstart <- genomeLabelInternal$plot$grobs$vp$yscale[1]
chromend <- genomeLabelInternal$plot$grobs$vp$yscale[2]
length <- plotObject$height
chrom <- if (!is.null(plotObject$ychrom)) {
plotObject$ychrom
} else {
plotObject$altchrom
}
chromstart <- if (!is.null(plotObject$ychromstart)) {
plotObject$ychromstart
} else {
plotObject$grobs$vp$yscale[1]
}
chromend <- if (!is.null(plotObject$ychromend)) {
plotObject$ychromend
} else {
plotObject$grobs$vp$yscale[2]
}
}

## Account for padded axis ranges (for example interchromosomal
## plotHicSquare(aspect = "fixed")).
if (genomeLabelInternal$axis == "x" &&
!is.null(plotObject$xaxisRange)) {
axisRange <- range(plotObject$xaxisRange)
actualRange <- range(c(chromstart, chromend))
if (diff(axisRange) > 0) {
fracStart <- (actualRange[1] - axisRange[1]) / diff(axisRange)
fracLength <- diff(actualRange) / diff(axisRange)
x <- misc_defaultUnits(x, "x", genomeLabelInternal$default.units) +
plotObject$width * fracStart
length <- plotObject$width * fracLength
}
}
if (genomeLabelInternal$axis == "y" &&
!is.null(plotObject$yaxisRange)) {
axisRange <- range(plotObject$yaxisRange)
actualRange <- range(c(chromstart, chromend))
if (diff(axisRange) > 0) {
if (plotObject$yaxisRange[1] < plotObject$yaxisRange[2]) {
offsetTop <- (axisRange[2] - actualRange[2]) / diff(axisRange)
} else {
offsetTop <- (actualRange[1] - axisRange[1]) / diff(axisRange)
}
fracLength <- diff(actualRange) / diff(axisRange)
y <- misc_defaultUnits(y, "y", genomeLabelInternal$default.units,
funName = "annoGenomeLabel") +
plotObject$height * offsetTop
length <- plotObject$height * fracLength
}
}

just <- justConversion(just = genomeLabelInternal$just)

## Whole genome Manhattan plot spacing
Expand Down
19 changes: 13 additions & 6 deletions R/annoPixels.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,29 +218,36 @@ annoPixels <- function(plot, data, type = "box", half = "inherit",
## Define a function that subsets loop data for hic region
subset_loops <- function(hic, loopData, object, plotObject) {

## Avoid factor-level mismatches when the plot chromosome came from
## pgParams(gene=) and the loop data contains all chromosomes.
loopData[, "chrom1"] <- as.character(loopData[, "chrom1"])
loopData[, "chrom2"] <- as.character(loopData[, "chrom2"])
plotChrom <- as.character(object$chrom)
plotAltchrom <- as.character(object$altchrom)

## chrom always in col1
## altchrom always in col4
## triangle hic plots will not have altchrom parameters
if (is(hic, "hicTriangle")) {
loops_subset <- loopData[which(
loopData[, "chrom1"] == object$chrom &
loopData[, "chrom2"] == object$chrom &
loopData[, "chrom1"] == plotChrom &
loopData[, "chrom2"] == plotChrom &
loopData[, "start1"] >= object$chromstart &
loopData[, "end1"] <= object$chromend &
loopData[, "start2"] >= object$chromstart &
loopData[, "end2"] <= object$chromend), ]
} else if (is(hic, "hicRectangle")){
loops_subset <- loopData[which(
loopData[, "chrom1"] == object$chrom &
loopData[, "chrom2"] == object$chrom &
loopData[, "chrom1"] == plotChrom &
loopData[, "chrom2"] == plotChrom &
loopData[, "start1"] >= plotObject$chromstartAdjusted &
loopData[, "end1"] <= plotObject$chromendAdjusted &
loopData[, "start2"] >= plotObject$chromstartAdjusted &
loopData[, "end2"] <= plotObject$chromendAdjusted), ]
} else {
loops_subset <- loopData[which(
loopData[, "chrom1"] == object$chrom &
loopData[, "chrom2"] == object$altchrom &
loopData[, "chrom1"] == plotChrom &
loopData[, "chrom2"] == plotAltchrom &
loopData[, "start1"] >= object$chromstart &
loopData[, "end1"] <= object$chromend &
loopData[, "start2"] >= object$altchromstart &
Expand Down
64 changes: 47 additions & 17 deletions R/annoXaxis.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
#' main = TRUE,
#' scipen = 999,
#' axisLine = FALSE,
#' tcl = 0.25,
#' label.offset = 0.35,
#' axisLine.lwd = 0.5,
#' axisLine.col = NULL,
#' axisLine.lty = NULL,
#' tick.lwd = 0.5,
#' tick.col = NULL,
#' tick.lty = NULL,
#' params = NULL,
#' ...
#' )
Expand All @@ -28,6 +36,17 @@
#' Default value is \code{scipen = 999}.
#' @param axisLine A logical value indicating whether to show the axis line.
#' Default value is \code{axisLine = FALSE}.
#' @param tcl Tick length in lines. Default value is \code{tcl = 0.25}.
#' @param label.offset Label offset from the tick ends in lines.
#' Default value is \code{label.offset = 0.35}.
#' @param axisLine.lwd Axis line width. Default value is
#' \code{axisLine.lwd = 0.5}.
#' @param axisLine.col Axis line color.
#' @param axisLine.lty Axis line type.
#' @param tick.lwd Tick line width. Default value is
#' \code{tick.lwd = 0.5}.
#' @param tick.col Tick line color.
#' @param tick.lty Tick line type.
#' @param params An optional \link[plotgardener]{pgParams} object
#' containing relevant function parameters.
#' @param ... Additional grid graphical parameters. See \link[grid]{gpar}.
Expand Down Expand Up @@ -70,7 +89,12 @@
#' pageGuideHide()
#' @export
annoXaxis <- function(plot, at = NULL, label = TRUE, main = TRUE,
scipen = 999, axisLine = FALSE, params = NULL, ...) {
scipen = 999, axisLine = FALSE,
tcl = 0.25, label.offset = 0.35,
axisLine.lwd = 0.5, axisLine.col = NULL,
axisLine.lty = NULL,
tick.lwd = 0.5, tick.col = NULL, tick.lty = NULL,
params = NULL, ...) {

# =========================================================================
# PARSE PARAMETERS
Expand Down Expand Up @@ -110,16 +134,6 @@ annoXaxis <- function(plot, at = NULL, label = TRUE, main = TRUE,

xAxis <- structure(list(grobs = NULL), class = "xaxis")

# =========================================================================
# CREATE GROB WITHOUT DRAWING
# =========================================================================

xGrob <- xaxisGrob(
at = xInternal$at, label = xInternal$label,
main = xInternal$main, gp = xInternal$gp,
vp = xInternal$plot$grobs$vp
)

# =========================================================================
# GET CENTER OF INPUT PLOT VIEWPORT BASED ON INPUT PLOT TYPE AND JUST
# =========================================================================
Expand All @@ -137,6 +151,26 @@ annoXaxis <- function(plot, at = NULL, label = TRUE, main = TRUE,
xInternal$at <- c(plotVP$xscale[1], plotVP$xscale[2])
}

# =========================================================================
# CREATE GROB
# =========================================================================

xGrob <- xaxisGrob(
at = xInternal$at, label = xInternal$label,
main = xInternal$main, gp = xInternal$gp
)
xGrob <- .modifyAxisGrob(
axisGrob = xGrob, main = xInternal$main,
tcl = xInternal$tcl, label.offset = xInternal$label.offset,
axisLine = xInternal$axisLine,
axisLine.lwd = xInternal$axisLine.lwd,
axisLine.col = xInternal$axisLine.col,
axisLine.lty = xInternal$axisLine.lty,
tick.lwd = xInternal$tick.lwd,
tick.col = xInternal$tick.col,
tick.lty = xInternal$tick.lty
)

# =========================================================================
# VIEWPORTS
# =========================================================================
Expand Down Expand Up @@ -170,16 +204,12 @@ annoXaxis <- function(plot, at = NULL, label = TRUE, main = TRUE,
)
}


# =========================================================================
# PLOT
# =========================================================================

xGrob <- grid.xaxis(
at = xInternal$at, label = xInternal$label,
main = xInternal$main, gp = xInternal$gp, vp = vp
)
if (!xInternal$axisLine) grid.remove(paste0(xGrob$name, "::major"))
xGrob$vp <- vp
grid.draw(xGrob)
xaxis_grobs <- gTree(vp = vp, children = gList(xGrob))
xAxis$grobs <- xaxis_grobs

Expand Down
Loading