Skip to content

Commit

Permalink
fix introduced bug
Browse files Browse the repository at this point in the history
  • Loading branch information
stemangiola committed Jan 26, 2025
1 parent 47c3027 commit 6b8d8d4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method("+",InputHeatmap)
S3method("+",tidyHeatmap_additive)
export(add_bar)
export(add_line)
export(add_point)
Expand Down Expand Up @@ -31,6 +32,7 @@ import(grDevices)
import(tidyr)
importFrom(ComplexHeatmap,Heatmap)
importFrom(ComplexHeatmap,HeatmapAnnotation)
importFrom(ComplexHeatmap,add_heatmap)
importFrom(ComplexHeatmap,anno_barplot)
importFrom(ComplexHeatmap,anno_block)
importFrom(ComplexHeatmap,anno_lines)
Expand Down
43 changes: 42 additions & 1 deletion R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,56 @@ setMethod("show", "InputHeatmap", function(object){
show()
})

# == title
# Class for Concatenating Heatmaps and Annotations
#
# == detail
# This class is a super class for `Heatmap-class`, `HeatmapList-class` and
# `HeatmapAnnotation-class` classes. It is only designed for ``+`` generic
# method and the ``\%v\%v`` method so that above three classes can be appended to each other.
#
tidyHeatmap_additive = setClass("tidyHeatmap_additive")

setClass(
"tidyHeatmap_additive",
contains = "HeatmapList"
)

#' @rdname plot_arithmetic
#'
#' @importFrom ComplexHeatmap add_heatmap
#'
#' @export
#' @references Mangiola, S. and Papenfuss, A.T., 2020. "tidyHeatmap: an R package for
#' modular heatmap production based on tidy principles." Journal of Open Source Software.
#' doi:10.21105/joss.02472.
#' @source [Mangiola and Papenfuss., 2020](https://joss.theoj.org/papers/10.21105/joss.02472)
"+.InputHeatmap" <- function(e1, e2) {

as_ComplexHeatmap(e1) + as_ComplexHeatmap(e2)
p = add_heatmap(as_ComplexHeatmap(e1), as_ComplexHeatmap(e2))

p = as(p, "tidyHeatmap_additive")

p

}




#' @rdname plot_arithmetic next
#'
#' @importFrom ComplexHeatmap add_heatmap
#'
#' @export
#' @references Mangiola, S. and Papenfuss, A.T., 2020. "tidyHeatmap: an R package for
#' modular heatmap production based on tidy principles." Journal of Open Source Software.
#' doi:10.21105/joss.02472.
#' @source [Mangiola and Papenfuss., 2020](https://joss.theoj.org/papers/10.21105/joss.02472)
"+.tidyHeatmap_additive" <- function(e1, e2) {

add_heatmap(e1, as_ComplexHeatmap(e2))

}

#' Creates a `InputHeatmap` object from `tbl_df` on evaluation creates a `ComplexHeatmap`
Expand Down
5 changes: 2 additions & 3 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -759,9 +759,8 @@ get_top_left_annotation = function(.data_, .column, .row, .abundance, annotation
# If it is a list of colors
else
if (is(.x, "factor")) {
color_vector <- palette_annotation$discrete[[.y]] %>% set_names(levels(.x))
color_vector[!is.na(names(color_vector))]

palette_annotation$discrete[[.y]] |> _[seq_len(length(levels(.x)))] %>% set_names(levels(.x))

} else {
colorRampPalette(palette_annotation$discrete[[.y]])(length(unique(.x))) %>% set_names(unique(.x))
}
Expand Down
Binary file modified tests/testthat/Rplots.pdf
Binary file not shown.

0 comments on commit 6b8d8d4

Please sign in to comment.