plotgardener Meta Functions (original) (raw)
plotgardener
meta functions enhance theplotgardener
user experience by providing simple methods to display various genomic assembly data, simplifyplotgardener
code, and construct plotgardener
objects. Functions in this category include:
genomes
and**defaultPackages
**
Simple functions to display the strings of available default genomic builds and the genomic annotation packages associated with these builds in plotgardener
functions.
genomes()
#> bosTau8
#> bosTau9
#> canFam3
#> ce6
#> ce11
#> danRer10
#> danRer11
#> dm3
#> dm6
#> galGal4
#> galGal5
#> galGal6
#> hg18
#> hg19
#> hg38
#> mm9
#> mm10
#> rheMac3
#> rheMac8
#> rheMac10
#> panTro5
#> panTro6
#> rn4
#> rn5
#> rn6
#> sacCer2
#> sacCer3
#> susScr3
#> susScr11
defaultPackages("hg19")
#> 'data.frame': 1 obs. of 6 variables:
#> $ Genome : chr "hg19"
#> $ TxDb : chr "TxDb.Hsapiens.UCSC.hg19.knownGene"
#> $ OrgDb : chr "org.Hs.eg.db"
#> $ gene.id.column: chr "ENTREZID"
#> $ display.column: chr "SYMBOL"
#> $ BSgenome : chr "BSgenome.Hsapiens.UCSC.hg19"
assembly
A constructor to make custom combinations of genomic annotation packages for use in plotgardener
functions through theassembly
parameter.
pgParams
A constructor to capture sets of parameters to be shared across multiple function calls. pgParams
objects can hold any argument from any plotgardener
function. Most often,pgParams
objects are used to store a common genomic region and common x-placement coordinate information. For a detailed example using the pgParams
object, refer to the vignette Plotting Multi-omic Data.
colorby
and**mapColors
**
The colorby
constructor allows us to color the data elements in plotgardener
plots by various data features. These features can be a numerical range, like some kind of score value, or categorical values, like positive or negative strand. Thecolorby
object is constructed by specifying the name of the data column to color by, an optional color palette function, and an optional range for numerical values. If not specified,plotgardener
will use the RColorBrewer
“YlGnBl” palette for mapping numerical data and the “Pairs” palette for qualitative data.
For example, if we revist the BED plot above,IMR90_ChIP_CTCF_reads
has an additional strand
column for each BED element:
data("IMR90_ChIP_CTCF_reads")
head(IMR90_ChIP_CTCF_reads)
#> chrom start end strand
#> 15554862 chr21 28000052 28000088 -
#> 15554863 chr21 28000092 28000128 -
#> 15554864 chr21 28000162 28000198 -
#> 15554865 chr21 28000251 28000287 +
#> 15554866 chr21 28000335 28000371 -
#> 15554867 chr21 28000500 28000536 +
Thus, we can use the colorby
constructor to color BED elements by positive or negative strand. The strand
column will be converted to a factor with a -
level and+
level. These values will be mapped to our inputpalette
:
set.seed(nrow(IMR90_ChIP_CTCF_reads))
plotRanges(
data = IMR90_ChIP_CTCF_reads,
chrom = "chr21", chromstart = 29073000, chromend = 29074000,
assembly = "hg19",
order = "random",
fill = colorby("strand", palette =
colorRampPalette(c("#7ecdbb", "#37a7db"))),
x = 0.5, y = 0.25, width = 6.5, height = 4.25,
just = c("left", "top"), default.units = "inches"
)
To further control the order of color mapping, we can set our categorical colorby
column as a factor with our own order of levels before plotting:
data("IMR90_ChIP_CTCF_reads")
IMR90_ChIP_CTCF_reads$strand <- factor(IMR90_ChIP_CTCF_reads$strand, levels = c("+", "-"))
head(IMR90_ChIP_CTCF_reads$strand)
#> [1] - - - + - +
#> Levels: + -
Now we’ve set the +
level as our first level, so ourpalette
will map colors in the opposite order from before:
In this example, we will color BEDPE arches by a range of numerical values we will add as a length
column:
data("IMR90_DNAloops_pairs")
IMR90_DNAloops_pairs$length <- (IMR90_DNAloops_pairs$start2 - IMR90_DNAloops_pairs$start1) / 1000
head(IMR90_DNAloops_pairs$length)
#> [1] 65 1960 2100 850 1200 1485
Now we can set fill
as a colorby
object to color the BEDPE length
column by:
bedpePlot <- plotPairsArches(
data = IMR90_DNAloops_pairs,
chrom = "chr21", chromstart = 27900000, chromend = 30700000,
assembly = "hg19",
fill = colorby("length",
palette = colorRampPalette(c("dodgerblue2", "firebrick2"))),
linecolor = "fill",
archHeight = IMR90_DNAloops_pairs$length / max(IMR90_DNAloops_pairs$length),
alpha = 1,
x = 0.25, y = 0.25, width = 7, height = 1.5,
just = c("left", "top"),
default.units = "inches"
)
And now since we have numbers mapped to colors, we can use[annoHeatmapLegend()](../../reference/annoHeatmapLegend.html)
with our arches
object to add a legend for the colorby
we performed:
annoHeatmapLegend(
plot = bedpePlot, fontcolor = "black",
x = 7.0, y = 0.25,
width = 0.10, height = 1, fontsize = 10
)
If users wish to map values to a color palette before passing them into a plotgardener
function, they can usemapColors
:
colors <- mapColors(vector = IMR90_DNAloops_pairs$length,
palette = colorRampPalette(c("dodgerblue2", "firebrick2")))
bedpePlot <- plotPairsArches(
data = IMR90_DNAloops_pairs,
chrom = "chr21", chromstart = 27900000, chromend = 30700000,
assembly = "hg19",
fill = colors,
linecolor = "fill",
archHeight = heights, alpha = 1,
x = 0.25, y = 0.25, width = 7, height = 1.5,
just = c("left", "top"),
default.units = "inches"
)
Session Info
sessionInfo()
#> R version 4.3.2 (2023-10-31)
#> Platform: x86_64-apple-darwin20 (64-bit)
#> Running under: macOS Sonoma 14.2.1
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> time zone: America/New_York
#> tzcode source: internal
#>
#> attached base packages:
#> [1] grid stats graphics grDevices utils datasets methods
#> [8] base
#>
#> other attached packages:
#> [1] plotgardenerData_1.8.0 plotgardener_1.8.2
#>
#> loaded via a namespace (and not attached):
#> [1] SummarizedExperiment_1.32.0 gtable_0.3.4
#> [3] rjson_0.2.21 xfun_0.43
#> [5] bslib_0.7.0 ggplot2_3.5.0
#> [7] plyranges_1.22.0 lattice_0.22-6
#> [9] Biobase_2.62.0 vctrs_0.6.5
#> [11] tools_4.3.2 bitops_1.0-7
#> [13] generics_0.1.3 yulab.utils_0.1.4
#> [15] parallel_4.3.2 stats4_4.3.2
#> [17] curl_5.2.1 tibble_3.2.1
#> [19] fansi_1.0.6 highr_0.10
#> [21] pkgconfig_2.0.3 Matrix_1.6-5
#> [23] data.table_1.15.2 ggplotify_0.1.2
#> [25] RColorBrewer_1.1-3 desc_1.4.3
#> [27] S4Vectors_0.40.2 lifecycle_1.0.4
#> [29] GenomeInfoDbData_1.2.11 compiler_4.3.2
#> [31] Rsamtools_2.18.0 Biostrings_2.70.3
#> [33] textshaping_0.3.7 munsell_0.5.0
#> [35] codetools_0.2-19 GenomeInfoDb_1.38.8
#> [37] htmltools_0.5.8 sass_0.4.9
#> [39] RCurl_1.98-1.14 yaml_2.3.8
#> [41] pillar_1.9.0 pkgdown_2.0.7
#> [43] crayon_1.5.2 jquerylib_0.1.4
#> [45] BiocParallel_1.36.0 DelayedArray_0.28.0
#> [47] cachem_1.0.8 abind_1.4-5
#> [49] tidyselect_1.2.1 digest_0.6.35
#> [51] restfulr_0.0.15 dplyr_1.1.4
#> [53] purrr_1.0.2 fastmap_1.1.1
#> [55] SparseArray_1.2.4 colorspace_2.1-0
#> [57] cli_3.6.2 magrittr_2.0.3
#> [59] S4Arrays_1.2.1 XML_3.99-0.16.1
#> [61] utf8_1.2.4 withr_3.0.0
#> [63] scales_1.3.0 rmarkdown_2.26
#> [65] XVector_0.42.0 matrixStats_1.2.0
#> [67] ragg_1.3.0 memoise_2.0.1
#> [69] evaluate_0.23 knitr_1.45
#> [71] BiocIO_1.12.0 GenomicRanges_1.54.1
#> [73] IRanges_2.36.0 rtracklayer_1.62.0
#> [75] gridGraphics_0.5-1 rlang_1.1.3
#> [77] Rcpp_1.0.12 glue_1.7.0
#> [79] BiocGenerics_0.48.1 rstudioapi_0.16.0
#> [81] jsonlite_1.8.8 strawr_0.0.91
#> [83] R6_2.5.1 MatrixGenerics_1.14.0
#> [85] GenomicAlignments_1.38.2 systemfonts_1.0.6
#> [87] fs_1.6.3 zlibbioc_1.48.2