
Bixverse implementation of the fgsea algorithm
calc_fgsea.RdRust-based version of the fgsea simple and multi-level algorithm. Initially, the simple method is run. For low p-values, the multi-level method is used to estimate lower p-values than possible just based on the permutations, see Korotkevich, et al.
Usage
calc_fgsea(
stats,
pathways,
nperm = 1000L,
gsea_params = params_gsea(),
seed = 123L
)Arguments
- stats
Named numeric vector. The gene level statistic.
- pathways
List. A named list with each element containing the genes for this pathway.
- nperm
Integer. Number of permutation tests. Defaults to
1000L.- gsea_params
List. The GSEA parameters, see
params_gsea()wrapper function. This function generates a list containing:min_size - Integer. Minimum size for the gene sets.
max_size - Integer. Maximum size for the gene sets.
gsea_param - Float. The GSEA parameter. Defaults to
1.0.sample_size - Integer. Number of samples to iterate through for the multi-level implementation of fgsea.
eps - Float. Boundary for calculating the p-value. Used for the multi- level implementation of fgsea.
- seed
Random seed for reproducibility.
Value
A data.table with the results from the GSEA with the following columns:
es - Float. The enrichment score for this pathway.
nes - Float. The normalised enrichment score for this pathway.
pvals - Float. The p-value for this pathway.
n_more_extreme - Integer. Number of permutation that had more extreme enrichment scores than the actual.
size - Integer. The size of the pathway.
pathway_name - Character. The name of the pathway.
leading_edge - List of character vectors with the leading edge genes.
fdr - Float. The adjusted pval.
Examples
# fgsea with the multi-level refinement of low p-values
set.seed(42L)
stats <- stats::setNames(rnorm(500), sprintf("gene_%03i", 1:500))
stats[1:20] <- stats[1:20] + 2
pathways <- list(
up_set = sprintf("gene_%03i", 1:20),
random_set = sprintf("gene_%03i", 200:240)
)
res <- calc_fgsea(stats, pathways, nperm = 1000L)
res[, c("pathway_name", "es", "pvals")]
#> pathway_name es pvals
#> <char> <num> <num>
#> 1: up_set 0.9045609 1.026119e-12
#> 2: random_set -0.2135723 8.426667e-01