一键导入
gseapy
Gene set enrichment analysis (GSEA, Enrichr, over-representation). Invoke when query mentions enrichment, pathway analysis, GO analysis, GSEA, or gene set.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Gene set enrichment analysis (GSEA, Enrichr, over-representation). Invoke when query mentions enrichment, pathway analysis, GO analysis, GSEA, or gene set.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Invoke after experiment-runner completes an investigation's query bundle. Evaluates all claims in current_investigation.json and produces an investigation-level adjudication. Writes claim_scores.json.
Invoke after investigation-decomposition. Runs all queries in an investigation bundle using shared data preparation. Writes code and results.
Invoke after main agent writes L2 assessment. Reads epistemic state (L1/L2), patterns, and investigations to recommend next action. Writes strategy_recommendation.json.
Invoke before running experiments for an investigation. Reads current_investigation.json and task_packet.json, writes current_investigation_requirements.json with shared data preparation and per-query requirements.
Gene ID conversion and annotation. Invoke when you need to map between any gene identifier formats.
Phylogenetic analysis: multiple sequence alignment (MAFFT), tree building (IQ-TREE, FastTree), tree metrics (treeness, branch lengths, patristic distances). Invoke when query involves phylogenetic trees, evolutionary analysis, sequence alignment, treeness, or tree statistics.
基于 SOC 职业分类
| name | gseapy |
| description | Gene set enrichment analysis (GSEA, Enrichr, over-representation). Invoke when query mentions enrichment, pathway analysis, GO analysis, GSEA, or gene set. |
Python wrapper for GSEA and Enrichr-style enrichment analysis.
| Function | Input | When to Use |
|---|---|---|
gseapy.enrichr() | Gene list (names only) | Over-representation analysis. You have a set of significant genes. |
gseapy.prerank() | Ranked gene list (name + score) | Pre-ranked GSEA. You have ALL genes with a ranking metric (e.g., log2FC, -log10p × sign). |
gseapy.gsea() | Expression matrix + phenotype labels | Full GSEA. You have raw expression data + sample groups. |
Critical: enrichr() and prerank() answer DIFFERENT questions. Do not confuse them.
Use when you have a list of significant genes (e.g., DE genes with padj < 0.05).
import gseapy as gp
# Input: a plain list of gene symbols
gene_list = ["BRCA1", "TP53", "CDK2", "MYC", "EGFR"]
enr = gp.enrichr(
gene_list=gene_list,
gene_sets='GO_Biological_Process_2021', # or multiple: ['KEGG_2021_Human', 'GO_BP_2021']
organism='human',
outdir=None, # set path to save results
cutoff=0.05
)
# Results
enr.results # DataFrame with Term, Overlap, P-value, Adjusted P-value, Genes
significant = enr.results[enr.results['Adjusted P-value'] < 0.05]
# List all available libraries
gp.get_library_name(organism='human')
# Commonly used:
'GO_Biological_Process_2021'
'GO_Molecular_Function_2021'
'GO_Cellular_Component_2021'
'KEGG_2021_Human'
'Reactome_2022'
'MSigDB_Hallmark_2020'
'WikiPathways_2019_Human'
Use when you have all genes ranked by a metric (not just significant ones).
import pandas as pd
import gseapy as gp
# Input: DataFrame or Series with gene names as index, ranking metric as values
# Common ranking: -log10(pvalue) * sign(log2FC)
import numpy as np
rnk = pd.DataFrame({
'gene': results.index,
'score': -np.log10(results['pvalue']) * np.sign(results['log2FoldChange'])
}).dropna()
pre_res = gp.prerank(
rnk=rnk,
gene_sets='GO_Biological_Process_2021',
min_size=15,
max_size=500,
permutation_num=1000,
outdir=None,
seed=42
)
# Results
pre_res.res2d # DataFrame with es, nes, pval, fdr
significant = pre_res.res2d[pre_res.res2d['fdr'] < 0.25] # GSEA uses FDR < 0.25 convention
# Option 1: signed -log10(p)
rnk['score'] = -np.log10(rnk['pvalue']) * np.sign(rnk['log2FoldChange'])
# Option 2: log2FC directly (simpler but less sensitive)
rnk['score'] = rnk['log2FoldChange']
# Option 3: t-statistic or Wald statistic from DE analysis
rnk['score'] = rnk['stat']
Important: Remove NaN/Inf values and duplicate genes before running.
rnk = rnk.replace([np.inf, -np.inf], np.nan).dropna()
rnk = rnk.drop_duplicates(subset='gene')
Use when you have raw expression data and sample labels.
# Input: genes × samples expression matrix
gs_res = gp.gsea(
data=expression_df, # genes × samples
gene_sets='KEGG_2021_Human',
cls=class_vector, # phenotype labels, e.g., ['control','control','treated','treated']
min_size=15,
max_size=500,
permutation_num=1000,
outdir=None
)
# If you have a .gmt file in the data directory
enr = gp.enrichr(gene_list=genes, gene_sets='path/to/geneset.gmt')
pre_res = gp.prerank(rnk=rnk, gene_sets='path/to/geneset.gmt')
enrichr() vs prerank() confusion: enrichr() takes a gene LIST (just names). prerank() takes a RANKED list (names + scores). Using the wrong one gives meaningless results.
Gene symbol format: GSEApy expects standard gene symbols (e.g., "TP53", not "ENSG00000141510"). Convert Ensembl IDs first using mygene (invoke /mygene skill).
enrichr() needs internet: enrichr() queries the Enrichr web API. If it fails, check network. Alternative: use local .gmt files with prerank().
prerank() input format: Must be a DataFrame with exactly 2 columns (gene, score) or a Series with gene names as index. NOT a full DE results table.
# WRONG: passing full results
gp.prerank(rnk=results, ...)
# RIGHT: extract gene + score only
rnk = results[['log2FoldChange']].dropna()
gp.prerank(rnk=rnk, ...)
Duplicate genes: prerank() will fail or give wrong results with duplicate gene names. Always deduplicate:
rnk = rnk[~rnk.index.duplicated(keep='first')]
FDR threshold for GSEA: Convention is FDR < 0.25 (not 0.05). This is because GSEA is inherently more conservative.
min_size / max_size: Filter gene sets by size. Very small (<15) or very large (>500) gene sets are usually uninformative.