This function creates a heatmap of the predicted functional pathway abundance data. The function first makes the abundance data relative, then converts the abundance data to a long format and orders the samples based on the environment information. The heatmap is then created using the `ggplot2` library. The color palette, appearance and the color bar of the heatmap can be customized using the `scale_fill_gradientn`, `theme` and `guides` functions respectively.

Arguments

abundance

A matrix or data frame of pathway abundance data, where columns correspond to samples and rows correspond to pathways.

metadata

A data frame of metadata, where each row corresponds to a sample and each column corresponds to a metadata variable.

group

A character string specifying the column name in the metadata data frame that contains the group variable.

Value

A ggplot heatmap object. The output is a ggplot object representing the heatmap of the predicted functional pathway abundance data. The heatmap visualizes the z score of pathways in different samples.

Examples

# \donttest{
library(ggpicrust2)
library(ggh4x)
#> Loading required package: ggplot2
library(dplyr)
library(tidyr)
#> 
#> Attaching package: ‘tidyr’
#> The following object is masked from ‘package:magrittr’:
#> 
#>     extract
library(tibble)
library(magrittr)
# Create example functional pathway abundance data
kegg_abundance_example <- matrix(rnorm(30), nrow = 3, ncol = 10)
colnames(kegg_abundance_example) <- paste0("Sample", 1:10)
rownames(kegg_abundance_example) <- c("PathwayA", "PathwayB", "PathwayC")

# Create example metadata
# Please ensure the sample IDs in the metadata have the column name "sample_name"
metadata_example <- data.frame(sample_name = colnames(kegg_abundance_example),
                               group = factor(rep(c("Control", "Treatment"), each = 5)))

# Create a heatmap
pathway_heatmap(kegg_abundance_example, metadata_example, "group")
#> The Sample Names in order from left to right are:
#> Sample1, Sample2, Sample3, Sample4, Sample5, Sample6, Sample7, Sample8, Sample9, Sample10
#> The Group Levels in order from left to right are:
#> 1, 1, 1, 1, 1, 2, 2, 2, 2, 2

# Use real dataset
data("metacyc_abundance")
data("metadata")
metacyc_daa_results_df <- pathway_daa(abundance = metacyc_abundance %>%
column_to_rownames("pathway"),
metadata = metadata, group = "Environment", daa_method = "LinDA")
#> Sample names extracted.
#> Identifying matching columns in metadata...
#> Matching columns identified: sample_name . This is important for ensuring data consistency.
#> Using all columns in abundance.
#> Converting abundance to a matrix...
#> Reordering metadata...
#> Converting metadata to a matrix and data frame...
#> Extracting group information...
#> Running LinDA analysis...
#> Performing LinDA analysis...
#> 0  features are filtered!
#> The filtered data has  50  samples and  316  features will be tested!
#> Pseudo-count approach is used.
#> Fit linear models ...
#> Completed.
#> Processing LinDA results...
#> LinDA analysis is complete.
annotated_metacyc_daa_results_df <- pathway_annotation(pathway = "MetaCyc",
daa_results_df = metacyc_daa_results_df, ko_to_kegg = FALSE)
#> Starting pathway annotation...
#> DAA results data frame is not null. Proceeding...
#> KO to KEGG is set to FALSE. Proceeding with standard workflow...
#> Loading MetaCyc reference data...
#> Returning DAA results data frame...
feature_with_p_0.05 <- metacyc_daa_results_df %>% filter(p_adjust < 0.05)
pathway_heatmap(abundance = metacyc_abundance %>%
right_join(annotated_metacyc_daa_results_df %>%
select(all_of(c("feature","description"))), by = c("pathway" = "feature")) %>%
filter(pathway %in% feature_with_p_0.05$feature) %>%
select(-"pathway") %>%
column_to_rownames("description"), metadata = metadata, group = "Environment")
#> The Sample Names in order from left to right are:
#> SRR11393740, SRR11393741, SRR11393742, SRR11393743, SRR11393744, SRR11393745, SRR11393746, SRR11393747, SRR11393748, SRR11393749, SRR11393750, SRR11393751, SRR11393752, SRR11393753, SRR11393764, SRR11393765, SRR11393766, SRR11393767, SRR11393768, SRR11393769, SRR11393775, SRR11393776, SRR11393777, SRR11393778, SRR11393779, SRR11393730, SRR11393731, SRR11393732, SRR11393733, SRR11393734, SRR11393735, SRR11393736, SRR11393737, SRR11393738, SRR11393739, SRR11393754, SRR11393755, SRR11393756, SRR11393757, SRR11393758, SRR11393759, SRR11393760, SRR11393761, SRR11393762, SRR11393763, SRR11393770, SRR11393771, SRR11393772, SRR11393773, SRR11393774
#> The Group Levels in order from left to right are:
#> Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-inflammatory, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival, Pro-survival

# }