GreenleafLab / ArchR

ArchR : Analysis of Regulatory Chromatin in R (www.ArchRProject.com)
MIT License
387 stars 140 forks source link

Troubles in the tutorial with plotEnrichHeatmap followed by ComplexHeatmap::draw #2226

Open alekseybelikov opened 4 weeks ago

alekseybelikov commented 4 weeks ago

Attach your log file ArchR-plotEnrichHeatmap-32564018f95d-Date-2024-10-25_Time-20-25-52.634833.log

Describe the bug

1) Wherever there is plotEnrichHeatmap function followed by ComplexHeatmap::draw functtion, e.g.

heatmapEM <- plotEnrichHeatmap(enrichMotifs)
ComplexHeatmap::draw(heatmapEM, heatmap_legend_side = "bot", annotation_legend_side = "bot")

the following error occurs:

Error in grid.Call.graphics(C_downvppath, name$path, name$name, strict): Viewport 'Norm. Enrichment -log10(P-adj) [0-Max]_heatmap_body_1_1' was not found

2) The same error occurs if instead of

ComplexHeatmap::draw(heatmapEM, heatmap_legend_side = "bot", annotation_legend_side = "bot")

a simple draw(heatmapEM) is used.

3) Interestingly, draw works with no issues after plotMarkerHeatmap

heatmapPeaks <- plotMarkerHeatmap(
  seMarker = markersPeaks, 
  cutOff = "FDR <= 0.1 & Log2FC >= 0.5",
  transpose = TRUE
)

draw(heatmapPeaks)

To Reproduce Reproduced multiple times in the tutorial, e.g

heatmapEncode <- plotEnrichHeatmap(enrichEncode, n = 7, transpose = TRUE)
ComplexHeatmap::draw(heatmapEncode, heatmap_legend_side = "bot", annotation_legend_side = "bot")
heatmapATAC <- plotEnrichHeatmap(enrichATAC, n = 7, transpose = TRUE)
ComplexHeatmap::draw(heatmapATAC, heatmap_legend_side = "bot", annotation_legend_side = "bot")
heatmapCodex <- plotEnrichHeatmap(enrichCodex, n = 7, transpose = TRUE)
ComplexHeatmap::draw(heatmapCodex, heatmap_legend_side = "bot", annotation_legend_side = "bot")
heatmapRegions <- plotEnrichHeatmap(enrichRegions, n = 7, transpose = TRUE)
ComplexHeatmap::draw(heatmapRegions, heatmap_legend_side = "bot", annotation_legend_side = "bot")

Expected behavior No error and the heatmap plotted

Workaround With the help of Claude I was able to devise a painful workaround:

# extract matrix from an existing heatmap object:
mat <- heatmapEM@ht_list[[1]]@matrix

# Create new heatmap with simplified parameters
new_heatmap <- Heatmap(
    matrix = mat,
    name = "Norm. Enrichment",
    # Use a simple blue color scheme
    col = colorRamp2(c(0, 0.5, 1), c("#E6E7E8", "#6156D2", "#000000")),
    # Basic clustering
    cluster_columns = TRUE,
    cluster_rows = TRUE,
    # Column settings
    column_names_rot = 90,
    column_names_gp = gpar(fontsize = 10),
    # Legend settings
    heatmap_legend_param = list(
        title = "Norm. Enrichment",
        direction = "horizontal",
        legend_width = unit(4, "cm")
    ),
    # Add some padding
    bottom_annotation = NULL,
    show_row_names = TRUE,
    row_names_gp = gpar(fontsize = 5),
    # Add borders for better visibility
    rect_gp = gpar(col = "white", lwd = 0.5)
)

draw(new_heatmap)

It worked.

But this is really not what I want to do for every heatmap.

rcorces commented 4 weeks ago

Hi @alekseybelikov! Thanks for using ArchR! Lately, it has been very challenging for me to keep up with maintenance of this package and all of my other responsibilities as a PI. I have not been responding to issue posts and I have not been pushing updates to the software. We are actively searching to hire a computational biologist to continue to develop and maintain ArchR and related tools. If you know someone who might be a good fit, please let us know! In the meantime, your issue will likely go without a reply. Most issues with ArchR right not relate to compatibility. Try reverting to R 4.1 and Bioconductor 3.15. Newer versions of Seurat and Matrix also are causing issues. Sorry for not being able to provide active support for this package at this time.