Skip to content

Commit

Permalink
heatmap output as ggplot object
Browse files Browse the repository at this point in the history
  • Loading branch information
pcastellanoescuder committed Nov 26, 2024
1 parent 21017ce commit 09bb015
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: POMA
Title: Tools for Omics Data Analysis
Version: 1.17.5
Version: 1.17.6
Authors@R:
c(person(given = "Pol",
family = "Castellano-Escuder",
Expand Down Expand Up @@ -50,6 +50,7 @@ Imports:
ggplot2,
ggrepel,
glmnet,
grid,
impute,
janitor,
limma,
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# POMA 1.17.5
# POMA 1.17.6

* Allow grouping variable selection in `PomaImpute`
* New documentation
Expand Down
18 changes: 13 additions & 5 deletions R/PomaHeatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#' @param sample_names Logical. Indicates if sample names should be displayed or not. Default is TRUE.
#' @param feature_names Logical. Indicates if feature names should be displayed or not. Default is FALSE.
#' @param show_legend Logical. Indicates if legend should be displayed or not. Default is TRUE.
#'
#'
#' @export
#'
#' @return A heatmap plot.
#' @return A `ggplot` object.
#' @author Pol Castellano-Escuder
#'
#' @examples
Expand All @@ -33,7 +33,7 @@ PomaHeatmap <- function(data,
covs = NULL,
sample_names = TRUE,
feature_names = FALSE,
show_legend = TRUE){
show_legend = TRUE) {

if(!is(data, "SummarizedExperiment")){
stop("data is not a SummarizedExperiment object. \nSee POMA::PomaCreateObject or SummarizedExperiment::SummarizedExperiment")
Expand All @@ -48,7 +48,7 @@ PomaHeatmap <- function(data,

heatmap_annotations <- ComplexHeatmap::HeatmapAnnotation(df = metadata, show_legend = show_legend)

suppressMessages(
poma_heatmap <- suppressMessages(
ComplexHeatmap::Heatmap(plot_data,
name = "Value",
top_annotation = heatmap_annotations,
Expand All @@ -57,13 +57,21 @@ PomaHeatmap <- function(data,
show_heatmap_legend = show_legend)
)
} else {
suppressMessages(
poma_heatmap <- suppressMessages(
ComplexHeatmap::Heatmap(plot_data,
name = "Value",
show_row_names = feature_names,
show_column_names = sample_names,
show_heatmap_legend = show_legend)
)
}

# Convert to ggplot
hm_grob <- grid::grid.grabExpr(ComplexHeatmap::draw(poma_heatmap))
poma_heatmap <- ggplot2::ggplot() +
ggplot2::annotation_custom(hm_grob, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf) +
ggplot2::theme_void()

return(poma_heatmap)
}

2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ output: github_document
| _BioC_ branch | Status | Version | Rank |
|- |- |- |- |
| [Release](http://bioconductor.org/packages/release/bioc/html/POMA.html) | [![Bioc release status](https://bioconductor.org/shields/build/release/bioc/POMA.svg)](https://bioconductor.org/checkResults/release/bioc-LATEST/POMA/) | [![BioC released version](https://img.shields.io/badge/release%20version-1.16.0-blue.svg)](https://www.bioconductor.org/packages/POMA) | [![Rank](http://www.bioconductor.org/shields/downloads/release/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |
| [Devel](http://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Bioc devel status](https://bioconductor.org/shields/build/devel/bioc/POMA.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/POMA/) | [![BioC devel version](https://img.shields.io/badge/devel%20version-1.17.5-blue.svg)](https://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Rank](http://www.bioconductor.org/shields/downloads/devel/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |
| [Devel](http://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Bioc devel status](https://bioconductor.org/shields/build/devel/bioc/POMA.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/POMA/) | [![BioC devel version](https://img.shields.io/badge/devel%20version-1.17.6-blue.svg)](https://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Rank](http://www.bioconductor.org/shields/downloads/devel/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |

<!-- badges: end -->

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/li
| *BioC* branch | Status | Version | Rank |
|-------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| [Release](http://bioconductor.org/packages/release/bioc/html/POMA.html) | [![Bioc release status](https://bioconductor.org/shields/build/release/bioc/POMA.svg)](https://bioconductor.org/checkResults/release/bioc-LATEST/POMA/) | [![BioC released version](https://img.shields.io/badge/release%20version-1.16.0-blue.svg)](https://www.bioconductor.org/packages/POMA) | [![Rank](http://www.bioconductor.org/shields/downloads/release/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |
| [Devel](http://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Bioc devel status](https://bioconductor.org/shields/build/devel/bioc/POMA.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/POMA/) | [![BioC devel version](https://img.shields.io/badge/devel%20version-1.17.5-blue.svg)](https://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Rank](http://www.bioconductor.org/shields/downloads/devel/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |
| [Devel](http://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Bioc devel status](https://bioconductor.org/shields/build/devel/bioc/POMA.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/POMA/) | [![BioC devel version](https://img.shields.io/badge/devel%20version-1.17.6-blue.svg)](https://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Rank](http://www.bioconductor.org/shields/downloads/devel/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |

<!-- badges: end -->

Expand Down
2 changes: 1 addition & 1 deletion man/PomaHeatmap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added tests/testthat/Rplots.pdf
Binary file not shown.
8 changes: 4 additions & 4 deletions tests/testthat/test-PomaHeatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
test_that("PomaHeatmap handles valid SummarizedExperiment objects", {
data <- create_mock_summarized_experiment()
heatmap_plot <- PomaHeatmap(data)
expect_is(heatmap_plot, "Heatmap")
expect_is(heatmap_plot, "ggplot")
})

test_that("PomaHeatmap stops with non-SummarizedExperiment objects", {
Expand All @@ -13,18 +13,18 @@ test_that("PomaHeatmap stops with non-SummarizedExperiment objects", {
test_that("PomaHeatmap handles covariates correctly", {
data <- create_mock_summarized_experiment()
heatmap_plot_with_covs <- PomaHeatmap(data, covs = c("group"))
expect_is(heatmap_plot_with_covs, "Heatmap")
expect_is(heatmap_plot_with_covs, "ggplot")
})

test_that("PomaHeatmap handles sample_names and feature_names parameters correctly", {
data <- create_mock_summarized_experiment()
heatmap_plot_with_names <- PomaHeatmap(data, sample_names = FALSE, feature_names = TRUE)
expect_is(heatmap_plot_with_names, "Heatmap")
expect_is(heatmap_plot_with_names, "ggplot")
})

test_that("PomaHeatmap handles show_legend parameter correctly", {
data <- create_mock_summarized_experiment()
heatmap_plot_no_legend <- PomaHeatmap(data, show_legend = FALSE)
expect_is(heatmap_plot_no_legend, "Heatmap")
expect_is(heatmap_plot_no_legend, "ggplot")
})

0 comments on commit 09bb015

Please sign in to comment.