sc-standardize-input
Load when an external single-cell h5ad/h5/loom/mtx needs to be canonicalised onto the OmicsClaw AnnData contract before downstream scRNA skills run. Skip when data already came from sc-count (already canonical); bulk RNA-seq (use bulkrna-qc); spatial (use spatial-preprocess).
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 161
- Forks
- 27
01 前言 Front Matter
- name
- sc-standardize-input
- tags
- [ "singlecell", "scrna", "input", "standardization", "anndata" ]
- trigger
- standardize AnnData, fix scRNA input, canonicalize single-cell input, prepare AnnData, input contract
- description
- Load when an external single-cell h5ad/h5/loom/mtx needs to be canonicalised onto the OmicsClaw AnnData contract before downstream scRNA skills run. Skip when data already came from sc-count (already canonical); bulk RNA-seq (use bulkrna-qc); spatial (use spatial-preprocess).
02 资源文件 8
- 脚本_api.py2.7 KB
- 脚本examples/example_step.py830 B
- 参考文档references/methodology.md3.1 KB
- 参考文档references/output_contract.md548 B
- 参考文档references/parameters.md237 B
- 参考文档references/r_visualization.md341 B
- 脚本sc_standardize_input.py16.2 KB
- 脚本tests/test_standardize_api.py1.1 KB
03 SKILL.md 正文
sc-standardize-input
When to use
The user has a single-cell expression file from outside OmicsClaw (a public
.h5ad, a 10X mtx directory, a .loom, etc.) and needs the canonical
AnnData contract every downstream scRNA skill assumes: raw counts in
layers["counts"] and adata.raw, harmonised feature names, and a
uns["omicsclaw_matrix_contract"] provenance record. Run this once before
sc-qc / sc-preprocessing / etc.
Use from a step
standardizer = load_skill("sc-standardize-input")
adata = standardizer.standardize(read_input("external.h5ad"), species="human")
write_output(adata, "intermediate/adata_standardized.h5ad")
standardize returns a new AnnData. It does not filter, normalize or
cluster. A runnable PBMC example is in examples/example_step.py.
API
<!-- api:begin generated from _api.py; regenerate with run.py api <skill dir> --write -->
standardize(adata, *, species: str='auto')
Return a canonical copy with count-like X, layers['counts'] and raw.
Select counts from layers['counts'], aligned raw or X, in that order; harmonize feature names and record the matrix and input contracts.
:param adata: AnnData with at least one count-like expression matrix. :param species: 'auto' uses infer_species; 'human' or 'mouse' overrides it. :returns: A new AnnData. run_info reports the selected matrix and warnings. :raises ValueError: The species is invalid or no count-like matrix is present.
infer_species(adata) -> str
Infer human or mouse from feature names, defaulting to human.
:param adata: AnnData whose feature names or gene-symbol metadata are examined. :returns: The species hint used by standardize(species="auto").
run_info(adata, *, keep: bool=True) -> dict
Read standardization diagnostics stored as JSON in adata.uns.
:param adata: The AnnData returned by standardize. :param keep: False removes these diagnostics after reading; default True. :returns: A dictionary, or an empty dictionary before standardize runs.
<!-- api:end -->
Methods and parameters
species="auto" uses the existing gene-name heuristic; use human or
mouse when the organism is known. infer_species exposes that heuristic.
Counts are selected from layers["counts"], aligned raw, then X.
run_info reports the chosen source and any warnings. This method has no
random state or optional backend.
Inputs & Outputs
Inputs
- Input kinds:
file,directory - Modalities: scrna
- File types:
.h5ad,.h5,.loom,.csv,.tsv
Outputs
processed.h5adreport.mdresult.json- Processed AnnData (
saves_h5ad) — addslayers:counts
Flow
- Load via the shared multi-format single-cell loader.
- Pre-flight: validate non-empty input; auto-detect species from gene name case (UPPER → human, Title → mouse).
- Pick the best count-like matrix among
layers["counts"],adata.raw, andadata.X(orchestrated bycanonicalize_singlecell_adatainskills/singlecell/_lib/adata_utils.py, which calls thematrix_looks_count_likeheuristic at_lib/adata_utils.py). - Harmonise feature names (Ensembl ↔ symbol, deduplicate).
- Persist
uns["omicsclaw_input_contract"]+uns["omicsclaw_matrix_contract"]. - Save
processed.h5ad; emitreport.md+result.json.
Gotchas
--r-enhancedis accepted but produces no R plots.sc_standardize_input.pydeclares the flag for CLI consistency; this skill is input canonicalisation, not visualisation. Pass it freely, but expect no R Enhanced figures.- Count-source selection uses a count-like heuristic, not file provenance.
Check
run_info(adata)["expression_source"]andwarnings, or the CLI'sresult.json["summary"], before downstream normalization. - Species auto-detect is gene-case-based. UPPER-case symbols → human, Title-case → mouse. Non-standard gene-name conventions (Ensembl IDs only, lowercase) silently fall through to the
autodefault. Pass--species humanor--species mouseexplicitly when working with non-symbol matrices. - No filtering, no normalisation, no clustering. Even if
result.jsonlooks complete, the output is still raw counts in canonical form — runsc-qcandsc-preprocessingnext.
Key CLI
# Demo (built-in PBMC3K)
python skills/singlecell/scrna/sc-standardize-input/sc_standardize_input.py --demo --output /tmp/sc_std_demo
# Real run with species hint
python skills/singlecell/scrna/sc-standardize-input/sc_standardize_input.py \
--input external.h5ad --output results/ --species mouse
See also
references/parameters.md— every CLI flag and tuning hintreferences/methodology.md— count-source heuristic, species detection logicreferences/output_contract.md— exactprocessed.h5ad+result.jsonshape- Adjacent skills:
sc-count(FASTQ → AnnData; skip standardisation when used),sc-qc(next step),sc-preprocessing(full normalise+cluster pipeline)
Dependencies
Python packages this skill's script needs. They are not installed for you — check before a long run.
anndata, matplotlib, numpy, pandas, scanpy, scipy
04 同仓库更多 Skills
demo-skill
A fixture skill for the skill environment tests. Use it for nothing else.
fake-domains
Test fixture for the golden deployment in tests/entry. Load never; it has no script.
replace-me-skill
Load when copying this directory to bootstrap a new OmicsClaw skill. Skip when an existing skill already covers the request.
spatial-velocity
Load when estimating RNA velocity on a spatial AnnData with `layers["spliced"]` + `layers["unspliced"]` via scVelo (stochastic / deterministic / dynamical) or veloVI (deep generative). Skip when input lacks the spliced/unspliced layers (must be quantified upstream by velocyto / kb-python / STARsolo); non-spatial scRNA velocity (use sc-velocity).
spatial-trajectory
Load when inferring pseudotime / lineage trajectories on a preprocessed spatial AnnData via DPT (default — diffusion pseudotime), CellRank (terminal-state + fate-probability), or Palantir (waypoint branch probabilities). Skip when the data has spliced/unspliced layers and you want velocity-driven dynamics (use spatial-velocity); non-spatial scRNA pseudotime (use sc-pseudotime).
spatial-statistics
Load when running spatial autocorrelation / hotspot / co-occurrence / neighbourhood-enrichment / Ripley K stats on a clustered spatial AnnData via squidpy. Skip when ranking spatially variable genes (use spatial-genes); tissue domain detection (use spatial-domains).