run_bidirectional_enrichment: Run Gene Set Enrichment Analysis on Loadings

View source: R/genes.R

run_bidirectional_enrichmentR Documentation

Run Gene Set Enrichment Analysis on Loadings

Description

This function performs gene set enrichment analysis for both positive and negative loadings using the clusterProfiler package with gene sets obtained via msigdbr. It extracts the top topN genes in both directions for a specified component and then uses enricher for enrichment analysis. If any significant enrichment is detected (based on the adjusted p-value cutoff), a dotplot is displayed.

Usage

run_bidirectional_enrichment(
  loadings,
  comp,
  topN,
  species = "Homo sapiens",
  category = "H",
  pvalueCutoff = 0.05,
  doPlot = F
)

Arguments

loadings

A numeric matrix or data frame of gene loadings with genes as row names. Rows represent genes and columns represent different components.

comp

Numeric. The component number (row index) to analyze.

topN

Numeric. The number of top genes (from both positive and negative directions) to consider.

species

Character. The species to query from msigdbr. Default is "Homo sapiens".

category

Character. The gene set category to use (e.g., "H" for Hallmark). Default is "H".

pvalueCutoff

Numeric. The p-value cutoff to consider enrichment as significant. Default is 0.05.

Value

A list with two elements:

enrichedPos

An object of class enrichResult with enrichment results for positively loaded genes.

enrichedNeg

An object of class enrichResult with enrichment results for negatively loaded genes.

Examples

## Not run: 
  # Assuming results$loadings[[1]] is a numeric matrix with gene symbols as row names:
  loadings <- results$loadings[[1]]
  enrichmentResults <- run_bidirectional_enrichment(loadings, comp = 2, topN = 100)

## End(Not run)


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