sc-multi-count
Load when merging multiple single-sample scRNA-seq count matrices (one per sample-from-sc-count) into a single downstream-ready AnnData with sample labels. Skip when input is one already-merged AnnData (use sc-standardize-input); FASTQ→counts on each sample (use sc-count).
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 161
- Forks
- 27
01 前言 Front Matter
- name
- sc-multi-count
- tags
- [ "singlecell", "scrna", "multi-sample", "merge", "aggregation" ]
- trigger
- merge count matrices, multi-sample count, aggregate samples, combine count outputs, cellranger aggr alternative
- description
- Load when merging multiple single-sample scRNA-seq count matrices (one per sample-from-sc-count) into a single downstream-ready AnnData with sample labels. Skip when input is one already-merged AnnData (use sc-standardize-input); FASTQ→counts on each sample (use sc-count).
02 资源文件 10
- 脚本_api.py4.1 KB
- 脚本examples/example_step.py874 B
- 参考文档OPERATOR.json351 B
- 参考文档references/methodology.md3.4 KB
- 参考文档references/output_contract.md1.1 KB
- 参考文档references/parameters.md605 B
- 参考文档references/r_visualization.md374 B
- 脚本sc_multi_count.py17.8 KB
- 脚本tests/test_multi_count_api.py1.3 KB
- 脚本tests/test_sc_multi_count.py3.8 KB
03 SKILL.md 正文
sc-multi-count
Use from a step
from skills._sdk.notebook import load_skill, read_input, write_output
merge = load_skill("sc-multi-count")
samples = [read_input("data/sample_a.h5ad"), read_input("data/sample_b.h5ad")]
adata = merge.merge_samples(samples, sample_ids=["sample_a", "sample_b"])
write_output(adata, "intermediate/merged.h5ad")
write_output(merge.per_sample_summary(adata), "tables/samples.csv")
The API returns objects and does not write files. Existing sample labels are
kept even when sample_ids supplies different barcode prefixes. See
examples/example_step.py for a count-conservation check using two halves
of PBMC3k; those halves are demonstration samples, not biological replicates.
When to use
The user has run sc-count (or another counting backend) on multiple
samples separately and now needs them merged into one AnnData with a
canonical sample-label column for downstream batch-aware analysis.
This only joins matrices; it does not perform Cell Ranger's depth
normalization or recount reads.
Inputs & Outputs
Inputs
- Two or more AnnData objects with raw count-like values in
.X; the CLI takes repeated--inputH5AD paths. Features are aligned by name.
Outputs
tables/barcode_metrics.csvtables/per_sample_summary.csvfigures/barcode_rank.pngfigures/count_complexity_scatter.pngfigures/count_distributions.pngfigures/sample_composition.pngprocessed.h5adstandardized_input.h5adreport.mdresult.jsonfigures/manifest.json,figure_data/manifest.jsonand copies of the two tablesreproducibility/commands.sh,reproducibility/requirements.txt- The returned AnnData has sample labels,
layers["counts"]and a count snapshot in.raw.
Flow
- Collect per-sample AnnData paths from each
--input <path>flag (action="append"); paired--sample-id <id>flags assign sample labels. - Load and tag samples, preserving an existing
obs["sample_id"]. - Join features and cells, zero-fill absent features, then record the count contract.
- Write merged AnnData; emit per-sample / per-barcode summary tables.
- Render barcode-rank + composition figures.
- Emit
report.md+result.json.
Gotchas
--inputisaction="append"— repeat the flag, do not comma-split.sc_multi_count.pydeclares--inputwithaction="append". Pass--input s1.h5ad --input s2.h5ad --input s3.h5ad; a single comma-separated value (--input s1.h5ad,s2.h5ad) is treated as one literal path that does not exist and triggersFileNotFoundError. No directory expansion.- At least two
--inputpaths are required.sc_multi_count.pycallsparser.error("At least two --input paths required when not using --demo.")if you pass zero or one. For a single-sample run you don't need this skill — just use the upstreamsc-countoutput directly. - Missing input file → hard fail.
sc_multi_count.pyraisesFileNotFoundErrorwhen any individual--inputpath does not resolve. In batch pipelines, a single mistyped sample name aborts the whole merge — pre-flight your file list. --r-enhancedis accepted but produces no R plots. This skill emits Python figures only; the flag exists for CLI consistency.- No within-sample re-counting. This is a stitching skill — it stacks already-canonical AnnData objects. If a per-sample input has a non-canonical matrix layout, run
sc-standardize-inputon each before this; otherwise the merged contract may surface incoherent per-cell metrics downstream. _api.py:merge_samplesdoes not validate integer counts. It labels.Xand its copies as raw counts; passing normalized data gives a misleading matrix contract._api.py:merge_sampleskeeps existing sample labels.--sample-idchanges barcode prefixes but does not replace an existingsample_idcolumn; checktables/per_sample_summary.csv.sc_multi_count.py:_demo_adataignores--sample-idin demo mode. Its labels staysample_Aandsample_B.
Key CLI
# Demo (two halves of PBMC3k raw counts)
python skills/singlecell/scrna/sc-multi-count/sc_multi_count.py --demo --output /tmp/sc_multi_demo
# Three samples — repeat --input per file
python skills/singlecell/scrna/sc-multi-count/sc_multi_count.py \
--input s1.h5ad --input s2.h5ad --input s3.h5ad \
--output results/
# With explicit per-sample labels (paired with --input order)
python skills/singlecell/scrna/sc-multi-count/sc_multi_count.py \
--input s1.h5ad --sample-id ctrl_a \
--input s2.h5ad --sample-id ctrl_b \
--input s3.h5ad --sample-id treat_a \
--output results/
API
<!-- api:begin generated from _api.py; regenerate with run.py api <skill dir> --write -->
merge_samples(adatas, *, sample_ids=None, sample_key='sample_id', join='outer')
Merge .X counts, align features and return a standardized copy.
Inputs are not modified. Missing features in an outer join become zeros. Existing sample labels are kept; sample_ids supplies missing labels and, when given, prefixes each input's barcodes. With no IDs, existing barcodes are kept and duplicate names get numeric suffixes; missing sample labels become sample_1, sample_2, etc. Like the CLI, this does not test whether .X holds integer counts. Standardize external inputs before merging them.
barcode_metrics(adata, *, sample_key='sample_id')
Return per-barcode .X counts and detected features, sorted by total counts.
per_sample_summary(adata, *, sample_key='sample_id')
Return cell counts, median counts/features and summed UMIs for each sample.
sample_composition_figure(adata, *, sample_key='sample_id')
Return a Figure showing each sample's cell count; do not write it.
run_info(adata, *, keep: bool=True)
Return merge diagnostics; keep=False removes the run record.
<!-- api:end -->
See also
references/parameters.md— every CLI flag and tuning hintreferences/methodology.md— sample-label derivation, contract harmonisation rulesreferences/output_contract.md— mergedobsschema, table layout- Adjacent skills:
sc-count(upstream — produces single-sample AnnData inputs),sc-standardize-input(per-sample contract canonicaliser, run before this when inputs are external),sc-batch-integration(downstream — corrects batch effects in the merged AnnData)
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).