Install any skill in seconds. Free to start, no credit card required.
Get Started Free →GSEA and over-representation analysis (ORA) for RNA-seq and proteomics. Wraps Enrichr for ORA against MSigDB, KEGG, GO, and 200+ databases; runs preranked GSEA on ranked DE gene lists. Outputs enrichment tables and running-score plots. Use after DESeq2 or edgeR for pathway-level interpretation.
.claude/skills/jaechang-hits-gseapy-gene-enrichment/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✗→✓ | ▲ Improved | 117% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 566% | 0% |
| case-19 | ✗→✓ | ▲ Improved | 403% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 175% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 185% | 0% |
GSEApy provides Python implementations of GSEA and over-representation analysis (ORA) for interpreting gene expression changes at the pathway level. The enrich module queries the Enrichr API to test a gene list against 200+ databases (GO, KEGG, MSigDB Hallmarks, Reactome, WikiPathways). The prerank and gsea modules run the GSEA algorithm on a pre-ranked gene list or expression matrix — computing normalized enrichment scores (NES) and FDR values for each gene set. GSEApy integrates directly with pandas DataFrames from DESeq2 or scanpy differential expression output, making it the standard Python tool for pathway analysis in RNA-seq workflows.
gseapy, pandas, matplotlibenrich module queries the Enrichr API (requires connection)bashpip install gseapy # Verify python -c "import gseapy; print(gseapy.__version__)" # 1.1.3
pythonimport gseapy as gp # ORA: test a gene list against GO Biological Process gene_list = ["TP53", "BRCA1", "CDK2", "CCND1", "MYC", "EGFR", "KRAS", "PTEN"] enr = gp.enrichr(gene_list=gene_list, gene_sets=["GO_Biological_Process_2023"], organism="human", outdir=None) print(enr.results.head(5)[["Term", "P-value", "Adjusted P-value", "Genes"]])
Test a gene list against pathway databases via the Enrichr API.
pythonimport gseapy as gp import pandas as pd # Gene list from DESeq2 (significant upregulated genes) sig_genes = ["TP53", "BRCA1", "CDK2", "CCND1", "MYC", "EGFR", "KRAS", "PTEN", "RB1", "AKT1", "PIK3CA", "MDM2"] # Run ORA against multiple databases enr = gp.enrichr( gene_list=sig_genes, gene_sets=[ "GO_Biological_Process_2023", "KEGG_2021_Human", "MSigDB_Hallmark_2020", "Reactome_2022", ], organism="human", outdir="enrichr_results/", cutoff=0.05, ) # Display top results results = enr.results print(f"Enriched terms: {len(results[results['Adjusted P-value'] < 0.05])}") print(results[results["Adjusted P-value"] < 0.05].sort_values("Adjusted P-value") .head(10)[["Gene_set", "Term", "Adjusted P-value", "Combined Score"]])
Discover the 200+ databases available through Enrichr.
pythonimport gseapy as gp # List all available gene set libraries libraries = gp.get_library_name(organism="human") print(f"Available databases: {len(libraries)}") print("Selected databases:") for lib in sorted(libraries): if any(kw in lib for kw in ["GO_Bio", "KEGG", "Hallmark", "Reactome"]): print(f" {lib}") # Mouse databases mouse_libs = gp.get_library_name(organism="mouse") print(f"\nMouse databases: {len(mouse_libs)}")
Run GSEA on a log2 fold-change ranked gene list from differential expression.
pythonimport gseapy as gp import pandas as pd import numpy as np # Load DESeq2 results (or create example ranked list) # deseq_results = pd.read_csv("deseq2_results.tsv", sep="\t", index_col=0) # ranked = deseq_results["log2FoldChange"].dropna().sort_values(ascending=False) # Example ranked gene list (gene → log2FC) np.random.seed(42) gene_names = [f"GENE_{i}" for i in range(1000)] log2fc = np.random.normal(0, 2, 1000) ranked = pd.Series(log2fc, index=gene_names).sort_values(ascending=False) # Run preranked GSEA against MSigDB Hallmarks pre_res = gp.prerank( rnk=ranked, gene_sets="MSigDB_Hallmark_2020", threads=4, min_size=15, max_size=500, permutation_num=1000, outdir="gsea_results/prerank/", seed=42, verbose=True, ) # View results res_df = pre_res.res2d sig = res_df[res_df["FDR q-val"] < 0.25] print(f"Significant gene sets (FDR < 0.25): {len(sig)}") print(sig.sort_values("NES", ascending=False)[["Term", "NES", "NOM p-val", "FDR q-val"]].head(10))
Visualize the enrichment score curve for a specific gene set.
pythonimport gseapy as gp from gseapy.plot import gseaplot import matplotlib.pyplot as plt # Re-use pre_res from Step 3 (or load saved results) # Select the top enriched gene set top_term = pre_res.res2d.sort_values("NES", ascending=False).index[0] print(f"Top enriched gene set: {top_term}") # Plot running enrichment score ax = gseaplot( rank_metric=pre_res.ranking, term=top_term, **pre_res.results[top_term], ofname="gsea_results/top_geneset_enrichment.pdf", ) plt.tight_layout() plt.savefig("gsea_enrichment_plot.png", dpi=150) print("Saved: gsea_enrichment_plot.png")
Generate a dot plot showing enrichment significance and gene ratio across top pathways.
pythonimport gseapy as gp import matplotlib.pyplot as plt from gseapy.plot import dotplot # Run ORA and plot results enr = gp.enrichr( gene_list=["TP53", "BRCA1", "CDK2", "CCND1", "MYC", "EGFR", "KRAS", "PTEN", "RB1", "AKT1", "PIK3CA", "MDM2", "BCL2", "CDKN1A", "E2F1", "CCNE1"], gene_sets=["KEGG_2021_Human"], organism="human", outdir=None, cutoff=0.05, ) # Dot plot: x=gene ratio, size=-log10(p), color=adjusted p-value ax = dotplot( enr.results, column="Adjusted P-value", x="Gene_set", title="KEGG Enrichment", cmap="viridis_r", size=10, top_term=15, figsize=(6, 8), ofname="enrichment_dotplot.pdf", ) plt.tight_layout() plt.savefig("enrichment_dotplot.png", dpi=150, bbox_inches="tight") print("Saved: enrichment_dotplot.png")
Use GSEApy directly on differential expression results.
pythonimport gseapy as gp import pandas as pd # From DESeq2 output loaded into Python # deseq_df = pd.read_csv("deseq2_results.tsv", sep="\t", index_col=0) # deseq_df = deseq_df.dropna(subset=["log2FoldChange", "padj"]) # Simulate DESeq2 output import numpy as np np.random.seed(0) n = 500 deseq_df = pd.DataFrame({ "log2FoldChange": np.random.normal(0, 1.5, n), "padj": np.random.uniform(0, 1, n), }, index=[f"GENE{i}" for i in range(n)]) # Significant up/down gene lists for ORA up_genes = deseq_df[(deseq_df["padj"] < 0.05) & (deseq_df["log2FoldChange"] > 1)].index.tolist() dn_genes = deseq_df[(deseq_df["padj"] < 0.05) & (deseq_df["log2FoldChange"] < -1)].index.tolist() print(f"Upregulated: {len(up_genes)}, Downregulated: {len(dn_genes)}") # ORA on upregulated genes if up_genes: enr_up = gp.enrichr(gene_list=up_genes, gene_sets=["GO_Biological_Process_2023", "KEGG_2021_Human"], organism="human", outdir=None) sig_up = enr_up.results[enr_up.results["Adjusted P-value"] < 0.05] print(f"Enriched terms (upregulated): {len(sig_up)}") print(sig_up.sort_values("Adjusted P-value").head(5)[["Term", "Adjusted P-value"]]) # Preranked GSEA on full ranked list ranked = deseq_df["log2FoldChange"].sort_values(ascending=False) pre = gp.prerank(rnk=ranked, gene_sets="MSigDB_Hallmark_2020", threads=4, permutation_num=500, outdir="gsea_out/", seed=42) print(pre.res2d[pre.res2d["FDR q-val"] < 0.25].sort_values("NES", ascending=False) .head(5)[["Term", "NES", "FDR q-val"]])
| Parameter | Default | Range/Options | Effect | |-----------|---------|---------------|--------| | gene_sets (enrichr) | required | string or list | Database name(s) from Enrichr; use gp.get_library_name() to list | | organism (enrichr) | "human" | "human", "mouse", "fly", "fish", "worm", "yeast" | Species for gene set lookup | | cutoff (enrichr) | 0.05 | 0–1 | Adjusted p-value cutoff for filtering results | | rnk (prerank) | required | pd.Series | Gene → score mapping; sorted descending (log2FC recommended) | | permutation_num (prerank) | 1000 | 100–10000 | Permutations for p-value estimation; 1000 for publication | | min_size (prerank) | 15 | 5–50 | Minimum gene set size; filters small/poorly characterized sets | | max_size (prerank) | 500 | 100–2000 | Maximum gene set size; filters very large generic sets | | threads (prerank) | 4 | 1–64 | CPU threads for permutation | | seed (prerank) | None | integer | Random seed for reproducibility | | weighted_score_type (prerank) | 1 | 0, 1, 1.5 | GSEA weighting; 1 = standard weighted GSEA |
pythonimport gseapy as gp import pandas as pd conditions = { "treated_vs_ctrl": ["TP53", "BRCA1", "CDK2", "CCND1", "MYC"], "treated2_vs_ctrl": ["EGFR", "KRAS", "PTEN", "RB1", "AKT1"], } results = {} for label, genes in conditions.items(): enr = gp.enrichr(gene_list=genes, gene_sets=["MSigDB_Hallmark_2020"], organism="human", outdir=None) sig = enr.results[enr.results["Adjusted P-value"] < 0.05] results[label] = set(sig["Term"]) print(f"{label}: {len(sig)} significant Hallmark terms") # Overlap shared = results["treated_vs_ctrl"] & results["treated2_vs_ctrl"] print(f"Shared terms: {shared}")
pythonimport gseapy as gp import pandas as pd from pathlib import Path # Load multiple DESeq2 result files comparisons = { "treat_vs_ctrl": "deseq_treat_vs_ctrl.tsv", "drug_vs_ctrl": "deseq_drug_vs_ctrl.tsv", } for name, file in comparisons.items(): # df = pd.read_csv(file, sep="\t", index_col=0) # ranked = df["log2FoldChange"].dropna().sort_values(ascending=False) # Example: generate synthetic ranked list import numpy as np ranked = pd.Series(np.random.normal(0, 1, 800), index=[f"G{i}" for i in range(800)]).sort_values(ascending=False) pre = gp.prerank( rnk=ranked, gene_sets=["MSigDB_Hallmark_2020", "KEGG_2021_Human"], threads=4, permutation_num=500, outdir=f"gsea_results/{name}/", seed=42, ) sig = pre.res2d[pre.res2d["FDR q-val"] < 0.25] print(f"{name}: {len(sig)} significant gene sets") pre.res2d.to_csv(f"gsea_results/{name}/all_results.tsv", sep="\t")
| Output | Format | Description | |--------|--------|-------------| | enr.results | DataFrame | ORA results: Term, P-value, Adjusted P-value, Combined Score, Genes | | pre_res.res2d | DataFrame | Prerank results: Term, ES, NES, NOM p-val, FDR q-val, Gene % | | gsea_results/*.csv | CSV | Saved enrichment tables per database | | gsea_results/*.pdf | PDF | GSEA running-score plots (one per gene set) | | enrichment_dotplot.png | PNG | Dot plot of top enriched terms | | gseaplot output | PNG/PDF | Running enrichment score + ranked list plot |
| Problem | Cause | Solution | |---------|-------|----------| | ConnectionError in enrichr | No internet or Enrichr API down | Check https://maayanlab.cloud/Enrichr/; use local gene sets with gene_sets="path/to/gmt" | | No significant terms returned | Gene list too small or wrong gene ID format | Use ≥10 genes; ensure HGNC symbols (not Ensembl IDs); convert with pyensembl | | Prerank returns all NES ≈ 0 | Ranked list not sorted or too few genes | Verify rnk is sorted descending; check min_size ≤ gene set sizes | | KeyError in gene set | Gene set name misspelled | Use gp.get_library_name() to get exact database names | | Low NES with FDR > 0.25 | Signal is weak or permutation count too low | Increase permutation_num to 1000; check raw p-values in NOM p-val | | GSEA plot shows flat line | Gene set has no intersection with ranked list | Check gene naming; confirm gene set species matches data | | Memory error during prerank | Large expression matrix + high permutations | Reduce permutation_num; use prerank instead of gsea when possible | | Enrichr results differ from Java GSEA | Different gene set versions | Specify exact database version string from gp.get_library_name() |
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 11,128 | 33,821 | +204% | 1 | 1 | 0% | 2,090 | 5,757 | +175% | 0 | 0 | — |
case-02 | pass→pass | 11,168 | 6,481 | -42% | 1 | 1 | 0% | 1,999 | 5,700 | +185% | 0 | 0 | — |
case-03 | pass→pass | 13,353 | 6,531 | -51% | 1 | 1 | 0% | 2,424 | 5,715 | +136% | 0 | 0 | — |
case-04 | fail→pass | 14,233 | 6,399 | -55% | 1 | 1 | 0% | 2,673 | 5,808 | +117% | 0 | 0 | — |
case-05 | fail→fail | 14,123 | 8,851 | -37% | 1 | 1 | 0% | 2,559 | 6,263 | +145% | 0 | 0 | — |
case-06 | pass→pass | 13,938 | 9,280 | -33% | 1 | 1 | 0% | 2,386 | 6,113 | +156% | 0 | 0 | — |
case-07 | pass→pass | 9,990 | 7,065 | -29% | 1 | 1 | 0% | 1,920 | 5,936 | +209% | 0 | 0 | — |
case-08 | pass→pass | 14,487 | 10,445 | -28% | 1 | 1 | 0% | 2,559 | 6,387 | +150% | 0 | 0 | — |
case-09 | pass→pass | 13,923 | 10,568 | -24% | 1 | 1 | 0% | 2,341 | 6,465 | +176% | 0 | 0 | — |
case-10 | pass→pass | 9,018 | 4,266 | -53% | 1 | 1 | 0% | 1,508 | 5,257 | +249% | 0 | 0 | — |
case-11 | pass→pass | 9,063 | 8,324 | -8% | 1 | 1 | 0% | 1,765 | 6,388 | +262% | 0 | 0 | — |
case-12 | pass→pass | 8,553 | 6,206 | -27% | 1 | 1 | 0% | 1,707 | 5,792 | +239% | 0 | 0 | — |
case-13 | fail→pass | 5,196 | 5,364 | +3% | 1 | 1 | 0% | 827 | 5,510 | +566% | 0 | 0 | — |
case-14 | fail→fail | 5,792 | 4,542 | -22% | 1 | 1 | 0% | 965 | 5,402 | +460% | 0 | 0 | — |
case-15 | pass→pass | 4,203 | 3,533 | -16% | 1 | 1 | 0% | 694 | 5,189 | +648% | 0 | 0 | — |
case-16 | pass→pass | 4,677 | 2,034 | -57% | 1 | 1 | 0% | 702 | 4,876 | +595% | 0 | 0 | — |
case-17 | pass→pass | 9,786 | 7,652 | -22% | 1 | 1 | 0% | 1,867 | 6,055 | +224% | 0 | 0 | — |
case-18 | pass→pass | 18,459 | 21,753 | +18% | 1 | 1 | 0% | 2,978 | 7,902 | +165% | 0 | 0 | — |
case-19 | fail→pass | 6,647 | 3,882 | -42% | 1 | 1 | 0% | 1,035 | 5,203 | +403% | 0 | 0 | — |
case-20 | pass→pass | 12,299 | 11,647 | -5% | 1 | 1 | 0% | 2,146 | 6,482 | +202% | 0 | 0 | — |
case-21 | pass→pass | 5,780 | 4,967 | -14% | 1 | 1 | 0% | 1,080 | 5,398 | +400% | 0 | 0 | — |
case-22 | pass→pass | 11,932 | 11,347 | -5% | 1 | 1 | 0% | 2,086 | 6,718 | +222% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +14 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.