一键导入
pydeseq2
Differential expression analysis for RNA-seq count data. Invoke when query mentions DESeq2, differential expression, DE genes, or RNA-seq comparison.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Differential expression analysis for RNA-seq count data. Invoke when query mentions DESeq2, differential expression, DE genes, or RNA-seq comparison.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
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.
Gene set enrichment analysis (GSEA, Enrichr, over-representation). Invoke when query mentions enrichment, pathway analysis, GO analysis, GSEA, or gene set.
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.
| name | pydeseq2 |
| description | Differential expression analysis for RNA-seq count data. Invoke when query mentions DESeq2, differential expression, DE genes, or RNA-seq comparison. |
Python implementation of DESeq2 for differential expression analysis with bulk RNA-seq data.
import pandas as pd
from pydeseq2.dds import DeseqDataSet
from pydeseq2.ds import DeseqStats
# 1. Load data — counts must be samples × genes (transpose if needed)
counts_df = pd.read_csv("counts.csv", index_col=0).T
metadata = pd.read_csv("metadata.csv", index_col=0)
# 2. Filter low-count genes
genes_to_keep = counts_df.columns[counts_df.sum(axis=0) >= 10]
counts_df = counts_df[genes_to_keep]
# 3. Fit DESeq2
dds = DeseqDataSet(
counts=counts_df,
metadata=metadata,
design="~condition",
refit_cooks=True
)
dds.deseq2()
# 4. Statistical testing
ds = DeseqStats(dds, contrast=["condition", "treated", "control"])
ds.summary()
# 5. Results
results = ds.results_df
significant = results[results.padj < 0.05]
# Single factor
design = "~condition"
# Multi-factor (batch correction)
design = "~batch + condition"
# Continuous covariate
design = "~age + condition"
# Interaction
design = "~group + condition + group:condition"
Rule: put adjustment variables (batch, age) BEFORE the variable of interest.
Format: [variable, test_level, reference_level]
# treated vs control
ds = DeseqStats(dds, contrast=["condition", "treated", "control"])
# Multiple comparisons
for treatment in ["A", "B", "C"]:
ds = DeseqStats(dds, contrast=["condition", treatment, "control"])
ds.summary()
| Column | Meaning |
|---|---|
baseMean | Mean normalized count across samples |
log2FoldChange | Log2 fold change between conditions |
lfcSE | Standard error of LFC |
stat | Wald test statistic |
pvalue | Raw p-value |
padj | BH-adjusted p-value (use this for significance) |
ds.lfc_shrink() # apeGLM shrinkage
Use shrunk LFC for visualization and ranking only. P-values are unchanged.
Data orientation: Count matrices often load as genes × samples. You MUST transpose to samples × genes with .T.
Index mismatch: Sample names in counts and metadata must match exactly.
common = counts_df.index.intersection(metadata.index)
counts_df = counts_df.loc[common]
metadata = metadata.loc[common]
Non-integer counts: PyDESeq2 requires raw counts. Do NOT pass TPM, FPKM, or normalized values.
Design not full rank: Happens when variables are confounded. Check with:
pd.crosstab(metadata.condition, metadata.batch)
Continuous covariates: Ensure numeric type:
metadata["age"] = pd.to_numeric(metadata["age"])
Use padj, not pvalue: Always filter by adjusted p-value for multiple testing correction.
# Significant genes
sig = results[results.padj < 0.05]
# With effect size filter
sig_large = results[(results.padj < 0.05) & (abs(results.log2FoldChange) > 1)]
# Up/down regulated
up = sig[sig.log2FoldChange > 0]
down = sig[sig.log2FoldChange < 0]