R/jamba-heatmap-order.R
heatmap_column_order.Rd
Return Heatmap column order from ComplexHeatmap heatmap object
heatmap_column_order(hm)
Heatmap
or HeatmapList
object as defined by the
Bioconductor package via ComplexHeatmap::Heatmap()
.
output depends upon the heatmap:
When heatmap columns are grouped using column_split
, and
when the data matrix contains colnames,
returns a character
vector of colnames in the order they
appear in the heatmap. When there are no colnames, integer
column index values are returned. If the heatmap has column labels,
they are returned as vector names.
When columns are grouped using column_split
, it returns a
list
of vectors as described above. The list
is named using the column_title
labels only when there is
an equal number of column labels.
This function is a helpful utility to return the fully
qualified list of colnames in a ComplexHeatmap::Heatmap
object.
The core intention is for the output to be usable with the
original data matrix used in the heatmap. Therefore, the
vector values are colnames()
when present, or integer
column index values when there are no colnames()
. If heatmap
column_labels
are defined, they are returned as names()
.
Note that names()
are assigned inside try()
to allow the
case where column_labels
, or column_title
labels cannot be
coerced to character
values, for example using gridtext
for markdown formatting.
Other jam heatmap functions:
cell_fun_label()
,
heatmap_row_order()
if (check_pkg_installed("ComplexHeatmap")) {
set.seed(123);
mat <- matrix(rnorm(18 * 24),
ncol=24);
rownames(mat) <- paste0("row", seq_len(18))
colnames(mat) <- paste0("column", seq_len(24))
# obtaining row order first causes a warning message
hm1 <- ComplexHeatmap::Heatmap(mat);
# best practice is to draw() and store output in an object
# to ensure the row orders are absolutely fixed
hm1_drawn <- ComplexHeatmap::draw(hm1);
heatmap_row_order(hm1_drawn)
heatmap_column_order(hm1_drawn)
}
#> column15 column1 column17 column6 column9 column23 column14
#> "column15" "column1" "column17" "column6" "column9" "column23" "column14"
#> column10 column4 column11 column7 column18 column12 column21
#> "column10" "column4" "column11" "column7" "column18" "column12" "column21"
#> column19 column24 column13 column8 column16 column5 column2
#> "column19" "column24" "column13" "column8" "column16" "column5" "column2"
#> column3 column22 column20
#> "column3" "column22" "column20"