OmicVerse Single-Cell Differential Expression
Goal
Turn notebook-style OmicVerse DEG analysis into a compact execution spine for condition-vs-condition comparisons inside selected cell types. Keep this skill focused on DEG only; differential abundance and compositional analysis are a separate job with a different input contract and backend surface.
Quick Workflow
- Inspect the input
AnnData, the condition column, the cell-type column, and whether raw counts are available in adata.raw or adata.layers["counts"].
- Choose a DEG backend before running anything:
wilcoxon or t-test for the scanpy rank-gene path, memento-de for the count-aware memento path.
- Subset to the required cell types with
celltype_key and celltype_group; leave celltype_group=None only when you really want all cell types pooled into one DEG run.
- Run
DEG.run(...) with an explicit max_cells policy and method-specific kwargs when using memento.
- Collect results with
get_results(), then verify the expected statistical columns and expression-percentage columns before saving or plotting.
Interface Summary
ov.single.DEG(adata, condition, ctrl_group, test_group, method='wilcoxon', use_raw=None) initializes the wrapper.
method branches are wilcoxon, t-test, and memento-de.
use_raw=None auto-detects adata.raw; if raw exists, the wrapper copies adata.raw.X into a fresh object and uses that matrix for DEG.
DEG.run(celltype_key, celltype_group=None, max_cells=100000, **kwargs) subsets by cell type and dispatches to the selected backend.
wilcoxon and t-test normalize and log-transform only when the active matrix still looks integer-valued.
memento-de expects count-like input; if X is not integer-valued, the wrapper first looks for adata.layers["counts"] and otherwise tries count recovery from log-normalized values.
- memento-specific kwargs are passed through
run(...); the notebook used capture_rate, num_cpus, and num_boot.
DEG.get_results() returns a DEG table and augments it with baseMean, pct_ctrl, pct_test, and pct_diff.
Stage Selection
- Use
method='wilcoxon' when you want the notebook's fast nonparametric path on one or more selected cell types.
- Use
method='t-test' only when a t-test is acceptable for the data distribution and normalization state.
- Use
method='memento-de' when the user explicitly wants memento's differential-mean path or needs the extra branch-specific kwargs.
- Keep
celltype_group explicit for targeted comparisons such as one lineage or cluster; set it to None only when a pooled all-cell-type DEG run is actually intended.
- Treat violin plots as optional reporting after DEG, not as part of the reusable execution contract.
Input Contract
- Start from an
AnnData object with a condition column in obs.
- Provide control and test labels that exist in that condition column.
- Provide a cell-type column for
celltype_key.
- Prefer preserving raw counts in
adata.raw or adata.layers["counts"], especially for memento-de.
- Expect the wrapper to coerce dense matrices to CSR internally.
Minimal Execution Patterns
import omicverse as ov
deg = ov.single.DEG(
adata,
condition="condition",
ctrl_group="Control",
test_group="Salmonella",
method="wilcoxon",
)
deg.run(
celltype_key="cell_label",
celltype_group=["TA"],
max_cells=100000,
)
res = deg.get_results()
deg = ov.single.DEG(
adata,
condition="condition",
ctrl_group="Control",
test_group="Salmonella",
method="memento-de",
use_raw=False,
)
deg.run(
celltype_key="cell_label",
celltype_group=["TA"],
capture_rate=0.07,
num_cpus=12,
num_boot=5000,
)
res = deg.get_results()
Constraints
- Do not merge DEG and DCT into one skill at execution time; they are independently triggerable and use different backends.
- Do not assume the notebook's example cell type or example genes are universal defaults.
- Do not leave
method implicit; branch choice changes both the statistical engine and the data expectations.
- Do not claim that
memento-de ran on raw counts unless you actually confirmed raw counts, a counts layer, or successful count recovery.
- Keep smoke and acceptance commands shell-agnostic. Do not rely on
zsh-specific syntax, shell startup files, or shell-only features when a direct ${PYTHON} script.py command is enough.
- Do not put local paths or environment names into the reusable instructions.
Validation
- Check that the selected control and test labels both remain after subsetting.
- Check that
DEG.run(...) used the intended cell-type subset.
- For
wilcoxon and t-test, check that the result table contains at least log2FC, pvalue, padj, qvalue, baseMean, pct_ctrl, pct_test, and pct_diff.
- For
memento-de, check that the result table still gains baseMean, pct_ctrl, pct_test, and pct_diff after get_results().
- If the dataset is large, say whether
max_cells caused downsampling.
- If only a bounded smoke path was run, say so explicitly.
Resource Map
- Use the branch selection notes when choosing the DEG backend or deciding whether all cell types should be pooled.
- Use the source grounding notes when you need the live signatures, defaults, or branch-specific behavior.
- Use the notebook map when tracing which tutorial cells became which reusable instruction.
- Use the compatibility notes when notebook prose and current runtime behavior diverge.
1---2name: omicverse-single-cell-differential-expression3description: Run OmicVerse single-cell differential expression analysis as a reusable, triggerable skill. Use when comparing conditions inside one or more cell types in AnnData, choosing between Wilcoxon, t-test, and memento backends, or adapting a related notebook into a repeatable DEG workflow.4---56# OmicVerse Single-Cell Differential Expression78## Goal910Turn notebook-style OmicVerse DEG analysis into a compact execution spine for condition-vs-condition comparisons inside selected cell types. Keep this skill focused on DEG only; differential abundance and compositional analysis are a separate job with a different input contract and backend surface.1112## Quick Workflow13141. Inspect the input `AnnData`, the condition column, the cell-type column, and whether raw counts are available in `adata.raw` or `adata.layers["counts"]`.152. Choose a DEG backend before running anything: `wilcoxon` or `t-test` for the scanpy rank-gene path, `memento-de` for the count-aware memento path.163. Subset to the required cell types with `celltype_key` and `celltype_group`; leave `celltype_group=None` only when you really want all cell types pooled into one DEG run.174. Run `DEG.run(...)` with an explicit `max_cells` policy and method-specific kwargs when using memento.185. Collect results with `get_results()`, then verify the expected statistical columns and expression-percentage columns before saving or plotting.1920## Interface Summary2122- `ov.single.DEG(adata, condition, ctrl_group, test_group, method='wilcoxon', use_raw=None)` initializes the wrapper.23- `method` branches are `wilcoxon`, `t-test`, and `memento-de`.24- `use_raw=None` auto-detects `adata.raw`; if raw exists, the wrapper copies `adata.raw.X` into a fresh object and uses that matrix for DEG.25- `DEG.run(celltype_key, celltype_group=None, max_cells=100000, **kwargs)` subsets by cell type and dispatches to the selected backend.26- `wilcoxon` and `t-test` normalize and log-transform only when the active matrix still looks integer-valued.27- `memento-de` expects count-like input; if `X` is not integer-valued, the wrapper first looks for `adata.layers["counts"]` and otherwise tries count recovery from log-normalized values.28- memento-specific kwargs are passed through `run(...)`; the notebook used `capture_rate`, `num_cpus`, and `num_boot`.29- `DEG.get_results()` returns a DEG table and augments it with `baseMean`, `pct_ctrl`, `pct_test`, and `pct_diff`.3031## Stage Selection3233- Use `method='wilcoxon'` when you want the notebook's fast nonparametric path on one or more selected cell types.34- Use `method='t-test'` only when a t-test is acceptable for the data distribution and normalization state.35- Use `method='memento-de'` when the user explicitly wants memento's differential-mean path or needs the extra branch-specific kwargs.36- Keep `celltype_group` explicit for targeted comparisons such as one lineage or cluster; set it to `None` only when a pooled all-cell-type DEG run is actually intended.37- Treat violin plots as optional reporting after DEG, not as part of the reusable execution contract.3839## Input Contract4041- Start from an `AnnData` object with a condition column in `obs`.42- Provide control and test labels that exist in that condition column.43- Provide a cell-type column for `celltype_key`.44- Prefer preserving raw counts in `adata.raw` or `adata.layers["counts"]`, especially for `memento-de`.45- Expect the wrapper to coerce dense matrices to CSR internally.4647## Minimal Execution Patterns4849```python50import omicverse as ov5152deg = ov.single.DEG(53 adata,54 condition="condition",55 ctrl_group="Control",56 test_group="Salmonella",57 method="wilcoxon",58)59deg.run(60 celltype_key="cell_label",61 celltype_group=["TA"],62 max_cells=100000,63)64res = deg.get_results()65```6667```python68deg = ov.single.DEG(69 adata,70 condition="condition",71 ctrl_group="Control",72 test_group="Salmonella",73 method="memento-de",74 use_raw=False,75)76deg.run(77 celltype_key="cell_label",78 celltype_group=["TA"],79 capture_rate=0.07,80 num_cpus=12,81 num_boot=5000,82)83res = deg.get_results()84```8586## Constraints8788- Do not merge DEG and DCT into one skill at execution time; they are independently triggerable and use different backends.89- Do not assume the notebook's example cell type or example genes are universal defaults.90- Do not leave `method` implicit; branch choice changes both the statistical engine and the data expectations.91- Do not claim that `memento-de` ran on raw counts unless you actually confirmed raw counts, a `counts` layer, or successful count recovery.92- Keep smoke and acceptance commands shell-agnostic. Do not rely on `zsh`-specific syntax, shell startup files, or shell-only features when a direct `${PYTHON} script.py` command is enough.93- Do not put local paths or environment names into the reusable instructions.9495## Validation9697- Check that the selected control and test labels both remain after subsetting.98- Check that `DEG.run(...)` used the intended cell-type subset.99- For `wilcoxon` and `t-test`, check that the result table contains at least `log2FC`, `pvalue`, `padj`, `qvalue`, `baseMean`, `pct_ctrl`, `pct_test`, and `pct_diff`.100- For `memento-de`, check that the result table still gains `baseMean`, `pct_ctrl`, `pct_test`, and `pct_diff` after `get_results()`.101- If the dataset is large, say whether `max_cells` caused downsampling.102- If only a bounded smoke path was run, say so explicitly.103104## Resource Map105106- Use the branch selection notes when choosing the DEG backend or deciding whether all cell types should be pooled.107- Use the source grounding notes when you need the live signatures, defaults, or branch-specific behavior.108- Use the notebook map when tracing which tutorial cells became which reusable instruction.109- Use the compatibility notes when notebook prose and current runtime behavior diverge.