The ComplexHeatmapPlot is a panel class for creating a Panel that displays an assay of a SummarizedExperiment object as a Heatmap
with features as rows and samples and columns, respectively.
It provides slots and methods for specifying the features of interest, which assay to display in the main heatmap, any transformations to perform on the data, and which metadata variables to display as row and column heatmap annotations.
ComplexHeatmapPlot slot overview
The following slots control the rows that are used:
CustomRows
, a logical scalar indicating whether the custom list of rows should be used. IfFALSE
, the incoming selection is used instead. Defaults toTRUE
.CustomRowsText
, string containing newline-separated row names. This specifies which rows of the SummarizedExperiment object are to be shown in the heatmap. IfNA
, defaults to the first row name of the SummarizedExperiment.
The following slots control the metadata variables that are used:
ColumnData
, a character vector specifying columns of thecolData
to show ascolumnAnnotation
. Defaults tocharacter(0)
.RowData
, a character vector specifying columns of therowData
to show asrowAnnotation
. Defaults tocharacter(0)
.ShowColumnSelection
, a logical vector indicating whether the column selection should be shown as an extra annotation bar. Defaults toTRUE
.OrderColumnSelection
, a logical vector indicating whether the column selection should be used to order columns in the heatmap. Defaults toTRUE
.
The following slots control the choice of assay values:
Assay
, string specifying the name of the assay to use for obtaining expression values. Defaults to"logcounts"
ingetPanelDefault
, falling back to the first valid assay name (see.cacheCommonInfo
below).
The following slots control the clustering of rows:
ClusterRows
, a logical scalar indicating whether rows should be clustered by their assay values. Defaults toFALSE
.ClusterRowsDistance
, string specifying a distance measure to use. This can be any one of"euclidean"
,"maximum"
,"manhattan"
,"canberra"
,"binary"
,"minkowski"
,"pearson"
,"spearman"
, or"kendall"
. Defaults to"spearman"
.ClusterRowsMethod
, string specifying a linkage method to use. This can be any one of"ward.D"
,"ward.D2"
,"single"
,"complete"
,"average"
,"mcquitty"
,"median"
, or"centroid"
. Defaults to"ward.D2"
.
The following control transformations applied to rows:
AssayCenterRows
is a logical scalar indicating whether assay values should be centered for each row.AssayScaleRows
is a logical scalar indicating whether assay values should be scaled for each row. This transformation is only applicable ifAssayCenterRows
isTRUE
.
The following slots control the color scale:
CustomBounds
is logical scale indicating whether the color scale should be constrained by an upper and/or a lower bounds.LowerBound
is a numerical value setting the lower bound of the color scale; orNA
to disable the lower bound whenCustomBounds
isTRUE
.UpperBound
is a numerical value setting the lower bound of the color scale; orNA
to disable the upper bound whenCustomBounds
isTRUE
.DivergentColormap
is a character scalar indicating a 3-color divergent colormap to use whenAssayCenterRows
isTRUE
.
The following slots refer to general plotting parameters:
ShowDimNames
, a character vector specifying the dimensions for which to display names. This can contain zero or more of"Rows"
and"Columns"
. Defaults to"Rows"
.NamesRowFontSize
, a numerical value setting the font size of the row names.NamesColumnFontSize
, a numerical value setting the font size of the column names.LegendPosition
, string specifying the position of the legend on the plot. Defaults to"Bottom"
ingetPanelDefault
but can also be"Right"
.LegendDirection
, string specifying the orientation of the legend on the plot for continuous covariates. Defaults to"Horizontal"
ingetPanelDefault
but can also be"Vertical"
.
The following slots control some aspects of the user interface:
DataBoxOpen
, a logical scalar indicating whether the data parameter box should be open. Defaults toFALSE
.VisualBoxOpen
, a logical scalar indicating whether the visual parameter box should be open. Defaults toFALSE
.
In addition, this class inherits all slots from its parent Panel class.
Constructor
ComplexHeatmapPlot(...)
creates an instance of a ComplexHeatmapPlot class, where any slot and its value can be passed to ...
as a named argument.
Supported methods
In the following code snippets, x
is an instance of a ComplexHeatmapPlot class.
Refer to the documentation for each method for more details on the remaining arguments.
For setting up data values:
.cacheCommonInfo(x)
adds a"ComplexHeatmapPlot"
entry containingvalid.assay.names
, a character vector of valid (i.e., non-empty) assay names;discrete.assay.names
, a character vector of valid assay names with discrete atomic values;continuous.assay.names
, a character vector of valid assay names with continuous atomic values;valid.colData.names
, a character vector of names of columns incolData
that are valid;discrete.colData.names
, a character vector of names for columns incolData
with discrete atomic values;continuous.colData.names
, a character vector of names of columns incolData
with continuous atomic values;valid.rowData.names
, a character vector of names of columns inrowData
that are valid;discrete.rowData.names
, a character vector of names for columns inrowData
with discrete atomic values;continuous.rowData.names
, a character vector of names of columns inrowData
with continuous atomic values. Valid assay names are defined as those that are non-empty, i.e., not""
; valid columns incolData
androwData
are defined as those that contain atomic values. This will also call the equivalent Panel method..refineParameters(x, se)
replaces anyNA
value in"Assay"
with the first valid assay name; andNA
value in"CustomRowsText"
with the first row name. This will also call the equivalent Panel method for further refinements tox
. If no valid column metadata fields are available,NULL
is returned instead.
For defining the interface:
.defineInterface(x, se, select_info)
defines the user interface for manipulating all slots described above and in the parent classes. TODO It will also create a data parameter box that can respond to specialized.defineDataInterface
, and a visual parameter box and a selection parameter box both specific to theComplexHeatmapPlot
panel. This will override the Panel method..defineDataInterface(x, se, select_info)
returns a list of interface elements for manipulating all slots described above..defineOutput(x)
returns a UI element for a brushable plot..panelColor(x)
will return the specified default color for this panel class..hideInterface(x, field)
returns a logical scalar indicating whether the interface element corresponding tofield
should be hidden. This returnsTRUE
for the selection history ("SelectionHistory"
), otherwise it dispatches to the Panel method.
For generating the output:
.generateOutput(x, se, all_memory, all_contents)
returns a list containingplot
, a Heatmap object;commands
, a list of character vector containing the R commands required to generatecontents
andplot
; andcontents
andvarname
, both set toNULL
as this is not a transmitting panel..exportOutput(x, se, all_memory, all_contents)
will create a PDF file containing the current plot, and return a string containing the path to that PDF. This assumes that theplot
field returned by.generateOutput
is a Heatmap object.
For monitoring reactive expressions:
.createObservers(x, se, input, session, pObjects, rObjects)
sets up observers for all slots described above and in the parent classes. This will also call the equivalent Panel method..renderOutput(x, se, output, pObjects, rObjects)
will add a rendered plot element tooutput
. The reactive expression will add the contents of the plot topObjects$contents
and the relevant commands topObjects$commands
. This will also call the equivalent Panel method to render the panel information text boxes.
For defining the panel name:
.fullName(x)
will return"Complex heatmap"
.
For documentation:
.definePanelTour(x)
returns an data.frame containing a panel-specific tour.
See also
Panel, for the immediate parent class.
Examples
#################
# For end-users #
#################
x <- ComplexHeatmapPlot()
x[["ShowDimNames"]]
#> [1] "Rows"
x[["ShowDimNames"]] <- c("Rows", "Columns")
##################
# For developers #
##################
library(scater)
sce <- mockSCE()
sce <- logNormCounts(sce)
old_cd <- colData(sce)
colData(sce) <- NULL
# Spits out a NULL and a warning if there is nothing to plot.
sce0 <- .cacheCommonInfo(x, sce)
.refineParameters(x, sce0)
#> Panel object of class ComplexHeatmapPlot
#> Get or set individual parameters with ‘[[’
#> Available parameters:
#> Assay: logcounts
#> AssayCenterRows: FALSE
#> AssayScaleRows: FALSE
#> ClusterRows: FALSE
#> ClusterRowsDistance: spearman
#> ClusterRowsMethod: ward.D2
#> ColumnData:
#> ColumnSelectionDynamicSource: FALSE
#> ColumnSelectionRestrict: FALSE
#> ColumnSelectionSource: ---
#> CustomBounds: FALSE
#> CustomRows: TRUE
#> CustomRowsText: Gene_0001
#> DataBoxOpen: FALSE
#> DivergentColormap: purple < black < yellow
#> LegendDirection: Horizontal
#> LegendPosition: Bottom
#> LowerBound: NA
#> NamesColumnFontSize: 10
#> NamesRowFontSize: 10
#> OrderColumnSelection: TRUE
#> PanelHeight: 500
#> PanelId: NA
#> PanelWidth: 4
#> RowData:
#> RowSelectionDynamicSource: FALSE
#> RowSelectionSource: ---
#> SelectionBoxOpen: FALSE
#> ShowColumnSelection: TRUE
#> ShowDimNames: Rows Columns
#> UpperBound: NA
#> VersionInfo: list of length 1
#> VisualBoxOpen: FALSE
#> VisualChoices: Annotations
# Replaces the default with something sensible.
colData(sce) <- old_cd
sce0 <- .cacheCommonInfo(x, sce)
.refineParameters(x, sce0)
#> Panel object of class ComplexHeatmapPlot
#> Get or set individual parameters with ‘[[’
#> Available parameters:
#> Assay: logcounts
#> AssayCenterRows: FALSE
#> AssayScaleRows: FALSE
#> ClusterRows: FALSE
#> ClusterRowsDistance: spearman
#> ClusterRowsMethod: ward.D2
#> ColumnData:
#> ColumnSelectionDynamicSource: FALSE
#> ColumnSelectionRestrict: FALSE
#> ColumnSelectionSource: ---
#> CustomBounds: FALSE
#> CustomRows: TRUE
#> CustomRowsText: Gene_0001
#> DataBoxOpen: FALSE
#> DivergentColormap: purple < black < yellow
#> LegendDirection: Horizontal
#> LegendPosition: Bottom
#> LowerBound: NA
#> NamesColumnFontSize: 10
#> NamesRowFontSize: 10
#> OrderColumnSelection: TRUE
#> PanelHeight: 500
#> PanelId: NA
#> PanelWidth: 4
#> RowData:
#> RowSelectionDynamicSource: FALSE
#> RowSelectionSource: ---
#> SelectionBoxOpen: FALSE
#> ShowColumnSelection: TRUE
#> ShowDimNames: Rows Columns
#> UpperBound: NA
#> VersionInfo: list of length 1
#> VisualBoxOpen: FALSE
#> VisualChoices: Annotations