jokergoo / InteractiveComplexHeatmap

Make Interactive Complex Heatmaps
https://jokergoo.github.io/InteractiveComplexHeatmap/
Other
126 stars 23 forks source link

`sub_layer_cell_fun` in heatmap lists #86

Closed tatiana-gelaf closed 2 years ago

tatiana-gelaf commented 2 years ago

Hello! One thing I'd like to be able to do is, given a list of heatmaps e.g heatmapA + heatmapB, have the sub_layer_cell_fun produce some overlay on heatmapA but not on heatmapB when a subheatmap is selected. Is there a mechanism (or hacky workaround) to achieve this? It seems like the function passed doesn't have a way to get information about which heatmap it's being applied to.

jokergoo commented 2 years ago

It is because I only considered one heatmap :)

I will check for multiple heatmaps.

jokergoo commented 2 years ago

Emm... sub_heatmap_layer_fun is specifically designed for one heatmap. For multiple heatmaps, The API might be changed a little bit...

jokergoo commented 2 years ago

In the new version, I've changed the arguments sub_heatmap_cell_fun/sub_heatmap_layer_fun to show_cell_fun/show_layer_fun.

Now cell_fun/layer_fun should be set in each heatmap, and show_cell_fun/show_layer_fun controls whether to show graphics made by them in the main heatmap panel.

To make this functionality more user-friendly, by default, if number of rows and columns is < 100 or the heatmap is in a special form (e.g. oncoPrint or UpSet plot), cell_fun/layer_fun is set to TRUE, which means, graphics made by them are drawn in the main heatmap panel, while if the matrix is large (nrow > 100 | ncol > 100), the cell_fun/layer_fun is not executed in the main heatmap panel while is only executed in the sub-heatmap panel.

library(ComplexHeatmap)
library(InteractiveComplexHeatmap)
set.seed(123)
mat1 = matrix(rnorm(101*10), nrow = 10)
mat2 = matrix(sample(letters[1:10], 100, replace = TRUE), 10)

ht_list = Heatmap(mat1, name = "mat_a", row_km = 2, column_km = 2,
    layer_fun = function(j, i, x, y, w, h, fill) {
        grid.text(round(pindex(mat1, i, j), 1), x, y, gp = gpar(fontsize = 6))
    }) +
    Heatmap(mat2, name = "mat_b", layer_fun = function(j, i, x, y, w, h, fill) {
        grid.text(pindex(mat2, i, j), x, y, gp = gpar(fontsize = 6))
    })
ht_list = draw(ht_list)

htShiny(ht_list)

Or explicitely:

htShiny(ht_list, show_cell_fun = FALSE)