Logo de Gseapy Gene Enrichment

Gseapy Gene Enrichment

Comunidade
jaechang-hits
gseapy-gene-enrichment

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.

Visão geral

Publicado porjaechang-hits
RepositórioSciAgent-Skills
Nome da habilidadegseapy-gene-enrichment
Estrelas
381
Forks
45
Arquivos incluídos
Somente instruções
LicençaMIT
Links
  • Instruções em Markdown

    Um arquivo SKILL.md que o modelo carrega sob demanda, consumindo tokens apenas quando uma solicitação é realmente relevante para a habilidade.

  • Funciona com qualquer LLM

    As habilidades de IA são escritas em Markdown simples, não em código específico de um provedor. Por isso, funcionam com GPT, Claude, Gemini, Grok ou um modelo local.

  • Sem arquivos extras

    Tudo de que o modelo precisa está nas instruções — sem arquivos extras para sincronizar.

  • Código aberto

    Publicada por jaechang-hits no GitHub. Leia os arquivos da habilidade antes de instalá-la.

Instalação

Instale a habilidade de IA Gseapy Gene Enrichment no TypingMind para usá-la com qualquer LLM ou adicione-a a outro agente que leia SKILL.md.

1

Instalar no TypingMind

O TypingMind instala uma habilidade diretamente da pasta dela no GitHub — lê o arquivo SKILL.md, reúne os arquivos de recursos em um pacote e armazena o resultado localmente.

  1. Abra o app e vá para Plugins → Habilidades.
  2. Escolha "Instalar do GitHub".
  3. Cole a URL abaixo, que aponta para a pasta da habilidade, e confirme.
    https://github.com/jaechang-hits/SciAgent-Skills/tree/main/skills/genomics-bioinformatics/rnaseq/gseapy-gene-enrichment
  4. Ative a habilidade em cada chat em que quiser disponibilizá-la.
Plugins → Habilidades → Adicionar habilidade → Via URL do GitHub. Depois, cole a URL da pasta e pressione Continuar.
2

Instalar em outro agente

Qualquer agente que leia o formato Agent Skills pode usar esta habilidade — copie a pasta para o diretório de habilidades desse agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/jaechang-hits/SciAgent-Skills.git /tmp/SciAgent-Skills
mkdir -p .claude/skills
cp -r /tmp/SciAgent-Skills/skills/genomics-bioinformatics/rnaseq/gseapy-gene-enrichment .claude/skills/gseapy-gene-enrichment
Reinicie Claude Code após copiar para que a nova habilidade seja reconhecida.

Use no TypingMind

Ative Gseapy Gene Enrichment em qualquer chat do TypingMind e o modelo cuida do resto. O nome e a descrição da habilidade ficam no prompt do sistema e, assim que uma solicitação relevante aparece, o modelo carrega as instruções completas automaticamente — sem precisar de acionamento manual e sem consumir tokens até que ela seja realmente usada.

O modelo carrega Gseapy Gene Enrichment automaticamente assim que uma solicitação é relevante para essa habilidade.

Funciona com qualquer modelo de IA

Habilidades de IA são instruções em Markdown simples, não código específico de um provedor. Por isso, Gseapy Gene Enrichment não fica vinculada ao modelo para o qual foi criada. Instale-a uma vez no TypingMind e use-a com GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama ou um modelo local executado por conta própria — tudo com suas próprias chaves de API.

  • Carregada apenas quando necessário

    O prompt do sistema contém apenas o nome e a descrição. As instruções são buscadas na primeira solicitação relevante, então uma habilidade sem uso não gera custo.

  • Troque de modelo durante a conversa

    Como a habilidade é composta de instruções, não de código, trocar de modelo não afeta seu funcionamento — o próximo modelo lê o mesmo arquivo SKILL.md.

Instruções da habilidade

Este é o conteúdo de SKILL.md que o modelo carrega. Leia antes de instalar — uma habilidade é um conjunto de instruções que seu modelo seguirá.

GSEApy — Gene Set Enrichment Analysis in Python

Overview

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.

When to Use

  • Interpreting DESeq2 or edgeR differential expression results at pathway/GO-term level
  • Running fast ORA (over-representation analysis) against Enrichr's 200+ databases including GO, KEGG, and MSigDB Hallmarks
  • Performing GSEA prerank analysis on a log2-fold-change-ranked gene list without an expression matrix
  • Identifying enriched pathways in scRNA-seq cluster marker genes
  • Generating publication-ready enrichment dot plots and GSEA running-score plots
  • Use GSEA Java application for the official GUI-based analysis with full GSEA desktop interface
  • Use fgsea (R) as an alternative with fast permutation-based p-values; GSEApy is preferred for Python-native pipelines
  • Use omics-plotting SKILL after DE and for publication-quality plots of gsea results

Prerequisites

  • Python packages: gseapy, pandas, matplotlib
  • Internet access: enrich module queries the Enrichr API (requires connection)
bash
pip install gseapy

# Verify
python -c "import gseapy; print(gseapy.__version__)"
# 1.1.3

Pre-flight Interview

Settle these with the user before writing any analysis code.

yaml
decisions:
  - id: D1
    param: analysis_mode
    kind: required
    source: upstream
    ask: "Test only the genes that passed a significance cut (ORA), or the whole ranked list without a cut (GSEA prerank)?"
    default: "prerank when the upstream stage yields a full ranking; ORA when it yields a gene list"

  - id: D2
    param: organism
    kind: derived
    source: upstream
    ask: "Which species are these genes from?"
    default: "carried from the upstream dataset"

  - id: D3
    param: gene_sets
    kind: required
    source: user
    depends_on: [D2]
    ask: "Which collections should the genes be tested against - GO terms, pathways, disease or perturbation signatures?"
    default: null

  - id: D4
    param: rnk
    kind: optional
    source: user
    depends_on: [D1]
    ask: "What should order the genes - effect size, signed significance, or the test statistic?"
    default: "log2FoldChange"
    skip_if: "ORA mode - ranking is not used"

  - id: D5
    param: cutoff
    kind: optional
    source: user
    ask: "How strong must a term's evidence be before it is reported?"
    default: 0.05

  - id: D6
    param: min_size, max_size
    kind: optional_conditional
    source: user
    ask: "Should very small or very broad gene sets be excluded as uninformative?"
    default: "15-500 genes"

  - id: D7
    param: permutation_num
    kind: optional_conditional
    source: user
    ask: "More permutations give finer p-values at proportionally more runtime - is the default enough?"
    default: 1000

  - id: D8
    param: weighted_score_type
    kind: optional
    source: user
    ask: "Should GSEA use the standard weighted enrichment score, or a different weighting for this ranking?"
    default: 1

  - id: D9
    param: seed, threads
    kind: never_ask
    source: data
    reason: "A fixed seed and available CPU cores affect reproducibility and runtime, not the enrichment model."
    default: "seed fixed, threads min(4, available_cores)"

Two orderings matter here. D3 hangs on D2 because Enrichr's libraries are species-specific — the catalog itself changes with the organism. D4 hangs on D1 because a ranking metric only exists in prerank mode; under ORA the question has no answer, which is what skip_if records.

Quick Start

python
import 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"]])

Workflow

Step 1: Over-Representation Analysis with Enrichr (ORA)

Test a gene list against pathway databases via the Enrichr API.

python
import 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"]])

Step 2: List Available Gene Set Databases

Discover the 200+ databases available through Enrichr.

python
import 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)}")

Step 3: GSEA Prerank — Ranked Gene List Analysis

Run GSEA on a log2 fold-change ranked gene list from differential expression.

python
import 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))

Step 4: Plot GSEA Running Score

The running enrichment-score curve is GSEApy-specific — draw it with gseaplot. (omics-plotting covers the GSEA bar/dot summary plots instead, see Step 5.)

python
from gseapy import gseaplot

# pre_res: prerank result from Step 3
top_term = pre_res.res2d.sort_values("NES", ascending=False).index[0]
gseaplot(
    rank_metric=pre_res.ranking,
    term=top_term,
    **pre_res.results[top_term],
    ofname="figures/gsea_running_score.png",
)
print(f"Saved figures/gsea_running_score.png ({top_term})")

Step 5: Enrichment Dot Plot for Multiple Terms

Run ORA, then read skills/data-visualization/omics-plotting/SKILL.md and follow its "GSEA dot plot" recipe on the exported table (→ figures/enrichment_dotplot.png). Map GSEApy's Overlap column to the recipe's GeneRatio.

python
import gseapy as gp

# enr.results is the enrichment table: Term, Overlap, Adjusted P-value, Genes, ...
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,
)
enr.results.to_csv("enrichment.csv", index=False)
print(f"ORA terms: {len(enr.results)} -> enrichment.csv")
# Render with the omics-plotting SKILL (`skills/data-visualization/omics-plotting/SKILL.md`) "GSEA dot plot" recipe.

Step 6: Integrate with DESeq2 / scanpy Output

Use GSEApy directly on differential expression results.

python
import 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"]])

Key Parameters

ParameterDefaultRange/OptionsEffect
gene_sets (enrichr)requiredstring or listDatabase 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.050–1Adjusted p-value cutoff for filtering results
rnk (prerank)requiredpd.SeriesGene → score mapping; sorted descending (log2FC recommended)
permutation_num (prerank)1000100–10000Permutations for p-value estimation; 1000 for publication
min_size (prerank)155–50Minimum gene set size; filters small/poorly characterized sets
max_size (prerank)500100–2000Maximum gene set size; filters very large generic sets
threads (prerank)41–64CPU threads for permutation
seed (prerank)NoneintegerRandom seed for reproducibility
weighted_score_type (prerank)10, 1, 1.5GSEA weighting; 1 = standard weighted GSEA

Common Recipes

Recipe 1: Compare Enrichment Between Two Conditions

python
import 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}")

Recipe 2: Batch Prerank for Multiple Comparisons

python
import 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")

Expected Outputs

OutputFormatDescription
enr.resultsDataFrameORA results: Term, P-value, Adjusted P-value, Combined Score, Genes
pre_res.res2dDataFramePrerank results: Term, ES, NES, NOM p-val, FDR q-val, Gene %
gsea_results/*.csvCSVSaved enrichment tables per database
gsea_results/*.pdfPDFGSEA running-score plots (one per gene set)
enrichment_dotplot.pngPNGDot plot of top enriched terms
gseaplot outputPNG/PDFRunning enrichment score + ranked list plot

Troubleshooting

ProblemCauseSolution
ConnectionError in enrichrNo internet or Enrichr API downCheck https://maayanlab.cloud/Enrichr/; use local gene sets with gene_sets="path/to/gmt"
No significant terms returnedGene list too small or wrong gene ID formatUse ≥10 genes; ensure HGNC symbols (not Ensembl IDs); convert with pyensembl
Prerank returns all NES ≈ 0Ranked list not sorted or too few genesVerify rnk is sorted descending; check min_size ≤ gene set sizes
KeyError in gene setGene set name misspelledUse gp.get_library_name() to get exact database names
Low NES with FDR > 0.25Signal is weak or permutation count too lowIncrease permutation_num to 1000; check raw p-values in NOM p-val
GSEA plot shows flat lineGene set has no intersection with ranked listCheck gene naming; confirm gene set species matches data
Memory error during prerankLarge expression matrix + high permutationsReduce permutation_num; use prerank instead of gsea when possible
Enrichr results differ from Java GSEADifferent gene set versionsSpecify exact database version string from gp.get_library_name()

References

Perguntas frequentes

O que a habilidade de IA Gseapy Gene Enrichment faz?

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.

Por que usar Gseapy Gene Enrichment no TypingMind?

Porque basta instalar uma vez para usar com qualquer modelo. A habilidade Gseapy Gene Enrichment é escrita em Markdown simples, e não em código específico de um provedor, então a mesma habilidade funciona com GPT-5, Claude, Gemini, Grok ou um modelo local — e é possível trocar de modelo no meio do chat sem que ela deixe de funcionar. No TypingMind, você usa suas próprias chaves de API e paga diretamente aos provedores, em vez de pagar uma assinatura por licença de usuário. Suas habilidades e chats permanecem no seu próprio armazenamento.

Como instalar Gseapy Gene Enrichment no TypingMind?

Abra Plugins → Habilidades → Instalar do GitHub no TypingMind e cole https://github.com/jaechang-hits/SciAgent-Skills/tree/main/skills/genomics-bioinformatics/rnaseq/gseapy-gene-enrichment. O TypingMind lê o arquivo SKILL.md e instala a habilidade para que possa ser ativada em cada chat.

Quais modelos de IA podem usar Gseapy Gene Enrichment?

Qualquer modelo conectado no TypingMind. As habilidades de IA são instruções em Markdown simples, e não código específico de um provedor. Assim, GPT, Claude, Gemini, Grok e modelos locais podem carregar esta habilidade quando uma solicitação corresponder a ela.

Quantos modelos de IA posso usar com Gseapy Gene Enrichment?

Quantos quiser. Desde que o modelo ofereça suporte a habilidades, é possível usar Gseapy Gene Enrichment com ele — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e outros — tudo no TypingMind com suas próprias chaves de API.

A habilidade de IA Gseapy Gene Enrichment é gratuita?

Sim. A habilidade é publicada no GitHub por jaechang-hits sob a licença MIT. O pagamento é feito apenas ao seu provedor de IA pelos tokens usados.

O que são habilidades de IA?

Uma habilidade de IA é um conjunto reutilizável de instruções que ensina um modelo de IA a realizar uma tarefa específica. Ela segue o formato aberto Agent Skills: um arquivo SKILL.md com nome e descrição, além de scripts, templates ou arquivos de referência de que o modelo possa precisar. O modelo lê as instruções apenas quando sua solicitação corresponde à habilidade, então uma habilidade instalada não gera custos até ser usada.

Qual é a diferença entre habilidades de IA e plugins ou servidores MCP?

Um plugin ou servidor MCP oferece ao modelo novas ferramentas que ele pode acionar — código que é executado em algum lugar e retorna um resultado. Já uma habilidade de IA dá ao modelo o conhecimento e as orientações de que ele precisa: como abordar uma tarefa, quais etapas seguir e como deve ser um bom resultado. As habilidades são escritas em Markdown simples, por isso não precisam de servidor, chave de API nem ambiente de execução, e funcionam com qualquer modelo.

Ver lista completa

Crie seu próprio espaço de trabalho com IA agora

Inscreva-se na nossa newsletter para receber avisos sobre novos recursos e futuros sorteios 👇