run_bidirectional_fgsea_from_loadings: Run Bidirectional fgsea Analysis from Gene Loadings

View source: R/genes.R

run_bidirectional_fgsea_from_loadingsR Documentation

Run Bidirectional fgsea Analysis from Gene Loadings

Description

This function performs a bidirectional Gene Set Enrichment Analysis (GSEA) using the fgsea package on a ranked gene loadings vector. It retrieves gene sets using msigdbr for a specified species and category, executes fgsea (either using fgseaMultilevel or fgsea based on the selected method), and optionally generates plots for the top enriched pathways.

Usage

run_bidirectional_fgsea_from_loadings(
  loadings,
  comp = 1,
  topN = 6,
  species = "Homo sapiens",
  category = "H",
  subcategory = NULL,
  pvalueCutoff = 0.05,
  doPlot = FALSE,
  nperm = 1000,
  method = "multilevel"
)

Arguments

topN

Integer specifying the number of top pathways to plot for each direction (default: 6).

species

Character string indicating the species for which to retrieve gene sets (default: "Homo sapiens").

category

Character string representing the gene set category from msigdbr (default: "H").

pvalueCutoff

Numeric value for the adjusted p-value cutoff to determine significant pathways (default: 0.05).

doPlot

Logical flag indicating whether to generate plots for the top pathways (default: FALSE).

nperm

Integer specifying the number of permutations for the fgsea function (default: 1000).

method

Character string specifying the fgsea method to use; "multilevel" for fgseaMultilevel, or any other value to use the standard fgsea function (default: "multilevel").

loadings_vector

A named numeric vector of gene loadings. The names must correspond to gene symbols.

Value

A list containing:

gsea_results

A data frame with the full results from the GSEA analysis.

pos_results

A data frame with significantly enriched pathways having positive Normalized Enrichment Scores (NES).

neg_results

A data frame with significantly enriched pathways having negative NES.

Examples

## Not run: 
  # Create a named vector of gene loadings
  loadings <- c(GeneA = 1.2, GeneB = -0.8, GeneC = 2.3)
  
  # Run the bidirectional fgsea analysis
  result <- run_bidirectional_fgsea_from_loadings(loadings)

## End(Not run)


eisascience/scCustFx documentation built on June 2, 2025, 3:59 a.m.