This function compares the results from Gene Set Enrichment Analysis (GSEA) and Differential Abundance Analysis (DAA) to identify similarities and differences.
Arguments
- gsea_results
A data frame containing GSEA results from the pathway_gsea function
- daa_results
A data frame containing DAA results from the pathway_daa function
- plot_type
A single character string specifying the visualization type: "venn", "upset", or "scatter"
- p_threshold
A numeric value specifying the significance threshold. Must be in the range (0, 1].
Value
A list with two elements: plot (a ggplot2 object, or an
UpSetR object when plot_type = "upset" and UpSetR is installed)
and results (a named list with the overlap, GSEA-only, and
DAA-only pathway sets plus their counts). For plot_type = "scatter",
results$scatter_data contains the merged score/effect-size table,
including daa_log2_fold_change_aligned.
Details
Venn and UpSet plots compare significant pathway sets with unique pathway
IDs. Restrict inputs to the shared tested pathway universe for a method
comparison; an untested pathway is not a non-significant result. Preserve
each analysis's original multiple-testing adjustment. The scatter plot
compares a GSEA score with a DAA effect size and requires one row
per pathway in each input. If a result table contains multiple methods,
contrasts, or group pairs for the same pathway, filter it to a single
score/contrast context before using plot_type = "scatter".
For scatter plots, GSEA and DAA directions must be explicit. Preranked
GSEA positive NES values represent gsea_results$group1 versus
gsea_results$group2, while DAA log2_fold_change values
represent daa_results$group2 / daa_results$group1. The DAA effect
size is therefore aligned to the GSEA-positive direction before plotting.
For Venn and UpSet plots, if both inputs include group1 and
group2, each input must represent one comparable group pair. This
prevents pathways found in different biological contrasts from being counted
as method agreement. Direction metadata must be complete: an input may
provide both columns or neither, but not only one of them. When neither method
has significant pathways, Venn and UpSet requests return the same explicit
zero-count summary plot.
Examples
if (FALSE) { # \dontrun{
# Load example data
data(ko_abundance)
data(metadata)
# Prepare abundance data
abundance_data <- as.data.frame(ko_abundance)
rownames(abundance_data) <- abundance_data[, "#NAME"]
abundance_data <- abundance_data[, -1]
# Run the competitive camera test
gsea_results <- pathway_gsea(
abundance = abundance_data,
metadata = metadata,
group = "Environment",
pathway_type = "KEGG",
method = "camera"
)
# Test pathway abundance, not individual KO abundance.
pathway_abundance <- ko2kegg_abundance(data = ko_abundance)
daa_results <- pathway_daa(
abundance = pathway_abundance,
metadata = metadata,
group = "Environment",
daa_method = "LinDA"
)
common_ids <- intersect(gsea_results$pathway_id, daa_results$feature)
gsea_results <- gsea_results[gsea_results$pathway_id %in% common_ids, ]
daa_results <- daa_results[daa_results$feature %in% common_ids, ]
# Compare results
comparison <- compare_gsea_daa(
gsea_results = gsea_results,
daa_results = daa_results,
plot_type = "venn"
)
} # }