sc-velocity-prep
Load when generating spliced / unspliced layers from Cell Ranger BAM, FASTQ, STARsolo output, or velocyto loom — the prerequisite for sc-velocity. Skip when AnnData already has spliced+unspliced layers (use sc-velocity); any non-velocity preprocessing (use sc-preprocessing).
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 161
- Forks
- 27
01 前言 Front Matter
- name
- sc-velocity-prep
- tags
- [ "singlecell", "scrna", "velocity-prep", "velocyto", "starsolo", "spliced-unspliced" ]
- trigger
- RNA velocity prep, prepare spliced unspliced layers, velocyto, starsolo velocyto, velocity-ready AnnData
- description
- Load when generating spliced / unspliced layers from Cell Ranger BAM, FASTQ, STARsolo output, or velocyto loom — the prerequisite for sc-velocity. Skip when AnnData already has spliced+unspliced layers (use sc-velocity); any non-velocity preprocessing (use sc-preprocessing).
02 资源文件 8
- 参考文档checklist.md4.3 KB
- 参考文档references/methodology.md8.1 KB
- 参考文档references/output_contract.md3.1 KB
- 参考文档references/parameters.md1.3 KB
- 参考文档references/r_visualization.md288 B
- 脚本sc_velocity_prep.py32.0 KB
- 脚本tests/test_sc_velocity_prep.py3.5 KB
- 参考文档workflow.md22.8 KB
03 SKILL.md 正文
sc-velocity-prep
Use from a step
This is CLI_ONLY: it runs external preparation tools or imports their files.
from skills._sdk.notebook import run_cli
run_cli("sc-velocity-prep", "--input", "data/velocity.loom",
"--base-h5ad", "data/clustered.h5ad",
inputs=["data/velocity.loom", "data/clustered.h5ad"])
The demo splits PBMC3k counts into fixed 82% spliced, 14% unspliced and
4% ambiguous layers. It checks packaging, not velocity biology or external
tool installation. There is no _api.py for this skill.
When to use
The user has raw Cell Ranger output (BAM + barcodes), STARsolo output,
or paired FASTQs and needs an AnnData with layers["spliced"] /
layers["unspliced"] (and optional layers["ambiguous"]) before
running sc-velocity. Two backends:
velocyto(default) — runsvelocyto runagainst a Cell Ranger BAM using a GTF. Produces a.loomand reads it back into AnnData.starsolo— re-runs alignment from FASTQ via STARsolo with the Velocyto solo subworkflow, or loads existing STARsolo Velocyto output directly when detected.
--base-h5ad lets you merge the velocity layers into an
already-processed AnnData (preserves obs / obsm / clustering).
For velocity estimation itself use sc-velocity. For non-velocity
scRNA preprocessing use sc-preprocessing.
Inputs & Outputs
Inputs
- Input kinds:
file,directory - Modalities: scrna
- File types:
.loom,.fastq,.fq - FASTQ structure: valid first record;
pairedlayout - Directory layouts (any):
paired-fastq,cellranger-output,starsolo-velocity
Outputs
tables/top_velocity_genes.csvtables/velocity_layer_summary.csvfigures/velocity_gene_balance.pngfigures/velocity_layer_fraction.pngfigures/velocity_layer_summary.pngfigures/velocity_top_genes_stacked.pngprocessed.h5advelocity_input.h5adfigures/manifest.json,figure_data/manifest.json, plot-data CSV filesreproducibility/commands.sh,reproducibility/requirements.txt- Conditional backend artifacts under
artifacts/; imported loom/STARsolo inputs do not create new BAM files. report.mdresult.json- Processed AnnData —
spliced,unsplicedlayers;ambiguousonly when supplied by the source
Flow
- Resolve
--input(Cell Ranger dir / STARsolo dir / FASTQ /.loom). - For
velocyto: locate BAM + barcodes, validate--gtf(or auto-pick fromresources/singlecell/references/gtf/), runvelocyto run, load.loom. - For
starsolo: detect existing STARsolo Velocyto output and load directly, OR re-run STARsolo Velocyto with--reference+--chemistry+ auto-detected--whitelist. - Optionally merge layers into
--base-h5ad. - Compute layer totals (
tables/velocity_layer_summary.csv) and top-gene balance. - Save
processed.h5ad, tables, figures,report.md,result.json.
Gotchas
- BAM-backed velocyto needs a GTF.
sc_velocity_prep.pyraisesValueError("BAM-backed velocyto preparation requires a GTF file. Pass--gtf /abs/path/to/genes.gtf, or keep one underresources/singlecell/references/gtf/. ..."). Auto-detection only fires if a project-local GTF lives at the recommended path. - FASTQ-backed STARsolo needs a STAR index AND explicit chemistry.
sc_velocity_prep.pyraisesValueError("FASTQ-backed STARsolo velocity preparation requires a STAR genome directory. ...")if--referenceis missing and nothing's atresources/singlecell/references/starsolo/.sc_velocity_prep.pyraisesValueError("FASTQ-backed STARsolo velocity preparation requires an explicit--chemistry.")when--chemistry autois left as the default — STARsolo cannot infer 10x v2 vs v3 vs v4 from FASTQ alone. - STARsolo whitelist is auto-guessed; missing → hard fail.
sc_velocity_prep.pyraisesValueError("Could not infer a compatible STARsolo whitelist. Pass--whitelist /abs/path/to/3M-february-2018.txt, or keep the whitelist underresources/singlecell/references/whitelists/. ..."). The guesser uses the reference path + chemistry; a non-standard reference layout breaks it. - STARsolo Velocyto matrix loader has a fallback for index-name quirks.
sc_velocity_prep.pyis documented as "with a local fallback for index-name quirks";_load_starsolo_velocyto_dir_saferaisesFileNotFoundError(f"Could not locate STARsolo Velocyto matrices under: {path}")when nothing matches even with the fallback. Common when STARsolo finished partial / was killed mid-run. --inputmandatory unless--demo(parser.error, exit code 2).sc_velocity_prep.pycallsparser.error("--input required when not using --demo"). Once provided,mainraisesFileNotFoundError(f"Input path not found: {input_path}")for a missing path.--methodchoices are exactlyvelocyto/starsolo.sc_velocity_prep.pydeclares the choices via argparse;kb-pythonis mentioned in upstream-prep docstrings but is not a valid--methodvalue here. Use the dedicated kb-python tooling outside OmicsClaw if you need that path.sc_velocity_prep.py:maindefaults to eight threads. Reference directories named in error messages are suggestions, not shipped assets. Verify thevelocytocommand can import before a long BAM run; migration preflight foundundefined symbol: __log10_finitein the installed copy despite its presence on PATH.sc_velocity_prep.py:mainwrites a new.rawsnapshot and records.Xas raw counts even when--base-h5adcontains normalized.X._lib/upstream.py:merge_velocity_layersalso replaceslayers["counts"]with the velocity input's counts (the sum of its available splicing layers for imported data). Inspect this existing contract mismatch before treating the merged object's.Xor.rawas counts; the spliced/unspliced layers remain separate.
Key CLI
# Demo (proportional PBMC3k layers; no velocyto / STARsolo)
python skills/singlecell/scrna/sc-velocity-prep/sc_velocity_prep.py --demo --output /tmp/sc_velo_prep_demo
# velocyto from a Cell Ranger run (BAM-backed)
python skills/singlecell/scrna/sc-velocity-prep/sc_velocity_prep.py \
--input /data/cellranger_run/ --output results/ \
--method velocyto --gtf /refs/Homo_sapiens.GRCh38.gtf
# Load existing STARsolo Velocyto output directly
python skills/singlecell/scrna/sc-velocity-prep/sc_velocity_prep.py \
--input /data/starsolo_run/ --output results/ \
--method starsolo
# Re-run STARsolo from FASTQ (chemistry must be explicit)
python skills/singlecell/scrna/sc-velocity-prep/sc_velocity_prep.py \
--input /data/fastqs/ --output results/ \
--method starsolo --reference /refs/star_index --chemistry 10xv3
# Merge velocity layers into an existing processed AnnData
python skills/singlecell/scrna/sc-velocity-prep/sc_velocity_prep.py \
--input /data/cellranger_run/ --output results/ \
--method velocyto --gtf /refs/Homo_sapiens.GRCh38.gtf \
--base-h5ad /path/to/clustered.h5ad
See also
references/parameters.md— every CLI flag, per-backend tunablesreferences/methodology.md— when velocyto vs STARsolo wins; whitelist conventionsreferences/output_contract.md—layers["spliced"]/layers["unspliced"]/layers["ambiguous"]schema- Adjacent skills:
sc-count/sc-multi-count(upstream — produce the Cell Ranger / STARsolo output this skill consumes),sc-velocity(downstream — consumeslayers["spliced"]+layers["unspliced"]),sc-clustering(parallel — pass clustered output as--base-h5adto keep clusters when adding velocity layers)
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, seaborn
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).