sechm 1.2.0
The sechm package is a wrapper around the ComplexHeatmap package to facilitate the creation of annotated heatmaps from objects of the Bioconductor class SummarizedExperiment (and extensions thereof).
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("sechm")
To showcase the main functions, we will use an example object which contains (a subset of) RNAseq of mouse hippocampi after Forskolin-induced long-term potentiation:
suppressPackageStartupMessages({
library(SummarizedExperiment)
library(sechm)
})
data("Chen2017", package="sechm")
SE <- Chen2017
This is taken from Chen et al., 2017.
The sechm
function simplifies the generation of heatmaps from
SummarizedExperiment
. It minimally requires, as input, a
SummarizedExperiment
object and a set of genes (or features, i.e. rows of
sechm
) to plot:
g <- c("Egr1", "Nr4a1", "Fos", "Egr2", "Sgk1", "Arc", "Dusp1", "Fosb", "Sik1")
sechm(SE, genes=g)
# with row scaling:
sechm(SE, genes=g, do.scale=TRUE)
The assay can be selected, and any rowData
or colData
columns can be
specified as annotation:
rowData(SE)$meanLogCPM <- rowMeans(assays(SE)$logcpm)
sechm(SE, genes=g, assayName="logFC", top_annotation=c("Condition","Time"), left_annotation=c("meanLogCPM"))
Column names are ommitted by default, but can be displayed:
sechm(SE, genes=g, do.scale=TRUE, show_colnames=TRUE)
Since sechm
uses the
ComplexHeatmap
engine for plotting, any argument of ComplexHeatmap::Heatmap
can be passed:
sechm(SE, genes=g, do.scale=TRUE, row_title="My genes")
When plotting a lot of rows, by default row names are not shown (can be
overriden), but specific genes can be highlighted with the mark
argument:
sechm(SE, genes=row.names(SE), mark=g, do.scale=TRUE, top_annotation=c("Condition","Time"))
We can also add gaps using the same columns:
sechm(SE, genes=g, do.scale=TRUE, top_annotation="Time", gaps_at="Condition")
By default, rows are sorted using the MDS angle method (can be altered with
the sort.method
argument); this can be disabled with:
# reverts to clustering:
sechm(SE, genes=row.names(SE), do.scale=TRUE, sortRowsOn=NULL)
# no reordering:
sechm(SE, genes=row.names(SE), do.scale=TRUE, sortRowsOn=NULL,
cluster_rows=FALSE)
It is also possible to combine sorting with clusters using the toporder
argument, or using gaps:.
# we first cluster rows, and save the clusters in the rowData:
rowData(SE)$cluster <- as.character(kmeans(t(scale(t(assay(SE)))),5)$cluster)
sechm(SE, genes=head(row.names(SE),30), do.scale=TRUE, toporder="cluster",
left_annotation="cluster", show_rownames=FALSE)
sechm(SE, genes=head(row.names(SE),30), do.scale=TRUE, gaps_row="cluster",
show_rownames=FALSE)
sechm
tries to guess whether the data plotted are centered around zero, and
adjusts the scale accordingly (this can be disable with breaks=FALSE
). It
also performs a quantile capping to avoid extreme values taking most of the
color scale, which is especially relevant when plotting for instance
fold-changes. This can be controlled with the breaks
argument. Consider the
three following examples:
library(ComplexHeatmap)
## Loading required package: grid
## ========================================
## ComplexHeatmap version 2.10.0
## Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
## Github page: https://github.com/jokergoo/ComplexHeatmap
## Documentation: http://jokergoo.github.io/ComplexHeatmap-reference
##
## If you use it in published research, please cite:
## Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional
## genomic data. Bioinformatics 2016.
##
## The new InteractiveComplexHeatmap package can directly export static
## complex heatmaps into an interactive Shiny app with zero effort. Have a try!
##
## This message can be suppressed by:
## suppressPackageStartupMessages(library(ComplexHeatmap))
## ========================================
g2 <- c(g,"Gm14288",tail(row.names(SE)))
draw(
sechm(SE, genes=g2, assayName="logFC", breaks=1, column_title="breaks=1") +
sechm(SE, genes=g2, assayName="logFC", breaks=0.995,
column_title="breaks=0.995", name="logFC(2)") +
sechm(SE, genes=g2, assayName="logFC", breaks=0.985,
column_title="breaks=0.985", name="logFC(3)"),
merge_legends=TRUE)
With breaks=1
, the scale is made symmetric, but not quantile capping is
performed. In this way, most of the colorscale is taken by the difference
between one datapoint (first gene) and the rest, making it difficult to
distinguish patterns in the genes at the bottom. Instead, with breaks=0.985
,
the color scale is linear up until the 0.985 quantile of the data, and ordinal
after this. This reduces our capacity to distinguish variations between the
extreme values, but enables us to visualize the others better.
Manual breaks can also be defined. The colors themselves can be passed as follows:
# not run
sechm(SE, genes=g2, hmcols=viridisLite::cividis(10))
Annotation colors can be passed with the anno_colors
argument, but the
simplest is to store them in the object’s metadata:
metadata(SE)$anno_colors
## $Time
## 30 60 120 <NA>
## "#90EE90FF" "#65BE61FF" "#3A9034FF" "#006400FF"
##
## $Condition
## Control Forskolin
## "lightgrey" "Darkred"
metadata(SE)$anno_colors$Condition <- c(Control="white", Forskolin="black")
sechm(SE, genes=g2, top_annotation="Condition")
Heatmap colors can be passed on in the same way:
metadata(SE)$hmcols <- c("darkred","white","darkblue")
sechm(SE, g, do.scale = TRUE)
Finally, it is also possible to set colors as package-wide options:
setSechmOption("hmcols", value=c("white","grey","black"))
sechm(SE, g, do.scale = TRUE)
At the moment, the following arguments can be set as global options:
assayName
, hmcols
, anno_columns
, anno_rows
, anno_colors
, gaps_at
,
breaks
.
To remove the predefined colors:
resetAllSechmOptions()
metadata(SE)$hmcols <- NULL
metadata(SE)$anno_colors <- NULL
In order of priority, the arguments in the function call trump the object’s metadata, which trumps the global options.
Because sechm
produces a Heatmap
object from
ComplexHeatmap, it
is possible to combine them:
sechm(SE, genes=g) + sechm(SE, genes=g)
## Warning: Heatmap/annotation names are duplicated: logFC
However, doing so involves manual work to ensure that the labels and colors are
nice and coherent, and that the rows names match. As a convenience, we provide
the crossHm
function to handle these issues. crossHm
works with a list of
SummarizedExperiment
objects:
# we build another SE object and introduce some variation in it:
SE2 <- SE
assays(SE2)$logcpm <- jitter(assays(SE2)$logcpm, factor=1000)
crossHm(list(SE1=SE, SE2=SE2), g, do.scale = TRUE,
top_annotation=c("Condition","Time"))
Scaling is applied to the datasets separately. A unique color scale can be enforced:
crossHm(list(SE1=SE, SE2=SE2), g, do.scale = TRUE,
top_annotation=c("Condition","Time"), uniqueScale = TRUE)
## R version 4.1.1 (2021-08-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.3 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.14-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.14-bioc/R/lib/libRlapack.so
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] grid stats4 stats graphics grDevices utils datasets
## [8] methods base
##
## other attached packages:
## [1] ComplexHeatmap_2.10.0 sechm_1.2.0
## [3] SummarizedExperiment_1.24.0 Biobase_2.54.0
## [5] GenomicRanges_1.46.0 GenomeInfoDb_1.30.0
## [7] IRanges_2.28.0 S4Vectors_0.32.0
## [9] BiocGenerics_0.40.0 MatrixGenerics_1.6.0
## [11] matrixStats_0.61.0 BiocStyle_2.22.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.7 lattice_0.20-45 circlize_0.4.13
## [4] png_0.1-7 digest_0.6.28 foreach_1.5.1
## [7] V8_3.4.2 R6_2.5.1 evaluate_0.14
## [10] highr_0.9 GlobalOptions_0.1.2 zlibbioc_1.40.0
## [13] rlang_0.4.12 curl_4.3.2 jquerylib_0.1.4
## [16] magick_2.7.3 GetoptLong_1.0.5 Matrix_1.3-4
## [19] rmarkdown_2.11 randomcoloR_1.1.0.1 Rtsne_0.15
## [22] stringr_1.4.0 RCurl_1.98-1.5 munsell_0.5.0
## [25] DelayedArray_0.20.0 compiler_4.1.1 xfun_0.27
## [28] shape_1.4.6 htmltools_0.5.2 GenomeInfoDbData_1.2.7
## [31] bookdown_0.24 seriation_1.3.1 codetools_0.2-18
## [34] crayon_1.4.1 bitops_1.0-7 jsonlite_1.7.2
## [37] lifecycle_1.0.1 registry_0.5-1 magrittr_2.0.1
## [40] scales_1.1.1 stringi_1.7.5 XVector_0.34.0
## [43] doParallel_1.0.16 bslib_0.3.1 rjson_0.2.20
## [46] RColorBrewer_1.1-2 iterators_1.0.13 tools_4.1.1
## [49] parallel_4.1.1 fastmap_1.1.0 yaml_2.2.1
## [52] clue_0.3-60 colorspace_2.0-2 cluster_2.1.2
## [55] BiocManager_1.30.16 TSP_1.1-11 knitr_1.36
## [58] sass_0.4.0