| pathway_gsea | R Documentation |
This function performs Gene Set Enrichment Analysis (GSEA) on PICRUSt2 predicted functional data to identify enriched pathways between different conditions.
pathway_gsea(
abundance,
metadata,
group,
pathway_type = "KEGG",
method = "camera",
covariates = NULL,
contrast = NULL,
inter.gene.cor = 0.01,
rank_method = "signal2noise",
nperm = 1000,
min_size = 5,
max_size = 500,
p_adjust_method = "BH",
seed = 42,
go_category = "all",
organism = "ko",
p.adjust = NULL,
comparison = NULL,
transformation = c("voom", "logCPM"),
gene_sets = NULL
)
abundance |
A data frame containing gene/enzyme abundance data, with
feature IDs in row names and samples as columns. Data frames may also
provide a leading non-numeric feature ID column (for example |
metadata |
A data frame containing sample metadata. After sample alignment, all retained samples must have non-missing, non-empty values in the grouping column. |
group |
A character string specifying the column name in metadata that contains the grouping variable |
pathway_type |
A single character string specifying the pathway type: "KEGG", "MetaCyc", or "GO" |
method |
A single character string specifying the GSEA method:
|
covariates |
A character vector specifying column names in metadata to use as covariates
for adjustment. Only supported when method is "camera" or "fry"; supplying
covariates with preranked methods is an error because those methods use a
precomputed rank vector rather than a design matrix. Default is NULL (no covariates).
Covariate values must be complete for all aligned samples; rows with
missing model variables are rejected rather than being silently dropped
by |
contrast |
For "camera" or "fry" methods, specify the coefficient
or contrast to test. Supplying |
inter.gene.cor |
Numeric value specifying the inter-gene correlation for camera method. Default is 0.01. Use NA to estimate correlation from data for each gene set. |
rank_method |
A single character string specifying the ranking statistic for preranked methods (fgsea, GSEA, clusterProfiler): "signal2noise", "t_test", "log2_ratio", or "diff_abundance" |
nperm |
An integer specifying the number of permutations (for clusterProfiler method only). The fgsea method uses adaptive multilevel splitting and does not require a fixed permutation count. |
min_size |
An integer specifying the minimum gene set size |
max_size |
An integer specifying the maximum gene set size |
p_adjust_method |
A character string specifying the p-value adjustment method |
seed |
An integer specifying the random seed for reproducibility |
go_category |
A single character string specifying GO category to use.
"all" (default) uses all categories present in the reference data.
Valid categories are determined by the reference data (currently MF and CC).
See |
organism |
Deprecated and has no effect. The KEGG and GO
reference data bundled with ggpicrust2 are KO-based
(organism-independent), so gene sets are returned in KO space
regardless of this argument. Retained only for signature
compatibility; passing any value other than the default
|
p.adjust |
Deprecated alias for |
comparison |
For preranked methods only ( |
transformation |
Transformation for camera/fry: |
gene_sets |
Optional named list of feature identifiers for explicitly
defined gene sets. When supplied, replaces the bundled sets for all methods;
size filtering and multiple-testing adjustment still apply. Identifiers must
match the normalized abundance row names. |
Method Selection:
The camera method (default):
Uses an inter-gene correlation adjustment (default 0.01)
It supports covariate adjustment through the design matrix
It performs a competitive test (genes in set vs. genes not in set)
The fry method is a fast alternative that:
Performs a self-contained test (are genes in the set differentially expressed?)
Is computationally very efficient for large numbers of gene sets
Also supports covariate adjustment
Preranked methods use a ranked-feature null rather than camera's competitive
model with a correlation adjustment. The hypotheses and input assumptions
differ; neither method is universally calibrated for predicted abundances.
For these methods, positive ES/NES values indicate gene-set enrichment near
the top of the ranked list. With comparison = c(group1, group2), the
top of the list corresponds to features higher in group1; reverse
comparison to reverse the biological direction.
Covariate Adjustment:
When using method = "camera" or method = "fry", you can adjust for
confounding variables by specifying them in the covariates parameter.
This is particularly important in microbiome studies where factors like age, sex,
BMI, and batch effects can influence results.
A data frame containing GSEA results with columns:
pathway_id: Pathway identifier
pathway_name: Pathway name/description
size: Number of genes in the pathway
direction: Direction of enrichment ("Up" or "Down", for camera/fry)
pvalue: Raw p-value
p.adjust: Adjusted p-value (FDR)
method: The method used for analysis
For fgsea/clusterProfiler methods, additional columns include ES, NES,
leading_edge, group1, and group2. Positive ES/NES values are in the
group1 versus group2 direction. For camera/fry methods,
limma does not return NES; ggpicrust2 retains a legacy NES column
containing a signed -log10(pvalue) score for visualization
compatibility and labels it with score_type and
score_label.
Wu, D., & Smyth, G. K. (2012). Camera: a competitive gene set test accounting for inter-gene correlation. Nucleic Acids Research, 40(17), e133.
Wu, D., Lim, E., Vaillant, F., Asselin-Labat, M. L., Visvader, J. E., & Smyth, G. K. (2010). ROAST: rotation gene set tests for complex microarray experiments. Bioinformatics, 26(17), 2176-2182.
## Not run:
# 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]
# Method 1: Using camera (recommended) - accounts for inter-gene correlations
gsea_results <- pathway_gsea(
abundance = abundance_data,
metadata = metadata,
group = "Environment",
pathway_type = "KEGG",
method = "camera"
)
# Method 2: Using camera with covariate adjustment
gsea_results_adj <- pathway_gsea(
abundance = abundance_data,
metadata = metadata,
group = "Environment",
covariates = "Mouse_Sex",
pathway_type = "KEGG",
method = "camera"
)
# Method 3: Using fry for fast self-contained testing
gsea_results_fry <- pathway_gsea(
abundance = abundance_data,
metadata = metadata,
group = "Environment",
pathway_type = "KEGG",
method = "fry"
)
# Method 4: A different null, using a prespecified preranked comparison
gsea_results_fgsea <- pathway_gsea(
abundance = abundance_data,
metadata = metadata,
group = "Environment",
pathway_type = "KEGG",
method = "fgsea",
comparison = c("Pro-survival", "Pro-inflammatory"),
seed = 42
)
# Visualize results
visualize_gsea(gsea_results, plot_type = "enrichment_plot", n_pathways = 10)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.