spatial-raw-processing
Use from a step
This is CLI_ONLY: ST-Pipeline consumes FASTQ files, barcode coordinates and
reference indexes. It is not an in-memory analysis function.
from skills._sdk.notebook import run_cli
output = run_cli("spatial-raw-processing", "--input", "data/run_bundle.json",
inputs=["data/run_bundle.json", "data/R1.fastq.gz",
"data/R2.fastq.gz", "data/barcodes.tsv"])
Record the reference index version in the module README. The executable
example uses synthetic upstream outputs and does not run ST-Pipeline.
When to use
The user has paired-end spatial-transcriptomics FASTQ files (read1 =
spatial barcode + UMI, read2 = cDNA) plus a STAR genome index, and
wants the standard ST-Pipeline run that produces a raw_counts.h5ad
with one row per spatial spot. Single backend: st_pipeline (calls
run_stpipeline from skills/spatial/_lib/stpipeline_adapter.py).
After this skill, chain to spatial-preprocess for QC + normalisation.
For non-spatial scRNA FASTQ use sc-fastq-qc. For bulk RNA-seq read
QC use bulkrna-read-qc.
Inputs & Outputs
Inputs
- Input kinds:
file,directory - Modalities: visium, slideseq
- File types:
.fastq,.fq,.json,.yaml,.yml - FASTQ structure: valid first record;
pairedlayout - Directory layouts (any):
paired-fastq
Outputs
tables/gene_qc.csvtables/raw_gene_qc.csvtables/raw_processing_run_summary.csvtables/raw_processing_spatial_points.csvtables/raw_spot_qc.csvtables/raw_top_genes.csvtables/run_summary.csvtables/saturation_curve.csvtables/spatial_coordinates.csvtables/spot_qc.csvtables/stage_summary.csvtables/top_genes.csvfigures/raw_detected_genes_spatial.pngfigures/raw_spot_qc_histograms.pngfigures/raw_top_genes_barplot.pngfigures/raw_total_counts_spatial.pngfigures/st_pipeline_saturation_curve.pngfigures/st_pipeline_stage_attrition.pngomicsclaw_stpipeline_run.jsonraw_counts.h5adst_pipeline.stderr.txtst_pipeline.stdout.txtreport.mdresult.json- Processed AnnData (
saves_h5ad) — addsobs:barcode,x_array,y_array;obsm:spatial
Flow
- Parse args (or load bundle JSON / YAML from positional
--input). _apply_effective_defaultsfills missing parameter values (threads, trimming, UMI ranges, etc.)._validate_real_run_bundle: checkread1/read2/ids/ref-mapexist and are well-typed; reject duplicate read1=read2; verify FASTQ extension.- Call
run_stpipeline(...)which shells out to ST-Pipeline (requires thestpipelinebinary on PATH or--stpipeline-repo+--bin-path). - Wrap the resulting count matrix into AnnData with
X = raw_counts,layers["counts"],raw = raw_counts_snapshot. - Save
raw_counts.h5adandresult.json. Print "next: spatial-preprocess on raw_counts.h5ad".
Gotchas
- All input failures raise typed exceptions wrapped in
SystemExit(1).spatial_raw_processing.pycatchesDataError/DependencyError/ParameterError/ProcessingErrorand re-raises asSystemExit(1). The originating raises live in_validate_real_run_bundle— it raisesParameterError(f"Missing required parameter: {key}")for missingread1/read2/ids; raisesDataError(...)for non-existent files; raisesDataError("Resolved read1/read2 inputs must be FASTQ files.")for non-FASTQ extensions; raisesParameterErrorfor read1==read2; raisesDataErrorfor missing / wrong-type STAR index dir; raisesDataErroronly when--ref-annotationwas provided but the path is missing or not a file (the param itself is optional — omitting it doesn't raise). --read1/--read2/--ids/--ref-mapare all required for real runs (not enforced by argparserequired=True, validated later). Missing any →ParameterError. Demo mode skips this validation entirely.- The output filename is always
raw_counts.h5ad(spatial_raw_processing.py). It's not configurable — the contract is consumed byspatial-preprocess. Multiple runs to the same--outputwill overwrite. - QC tables and figures are written.
tables/spot_qc.csvandfigures/raw_total_counts_spatial.pngdescribe the count matrix; upstream stage and saturation plots depend on available pipeline metrics. - Demo mode skips ST-Pipeline entirely.
spatial_raw_processing.pycallscreate_demo_upstream_outputs(...)to fabricate a syntheticraw_counts.h5ad. Useful for plumbing checks; does NOT exercise the FASTQ → matrix code path. --platformis a metadata label only._build_parserdocuments it as "Label recorded in outputs"; ST-Pipeline doesn't branch on it. Common values:visium,visium_hd,slideseq, custom strings.
Key CLI
# Demo (synthetic raw_counts.h5ad — does NOT run ST-Pipeline)
python skills/spatial/spatial-raw-processing/spatial_raw_processing.py --demo --output /tmp/spatial_raw_demo
# Real run with explicit args
python skills/spatial/spatial-raw-processing/spatial_raw_processing.py \
--read1 sample_R1.fastq.gz --read2 sample_R2.fastq.gz \
--ids barcodes.tsv \
--ref-map /refs/star_index_human \
--ref-annotation /refs/genes.gtf \
--exp-name visium_001 --platform visium \
--threads 16 \
--output results/
# Real run from bundle JSON
python skills/spatial/spatial-raw-processing/spatial_raw_processing.py \
--input run_bundle.json --output results/
# Slide-seq with custom UMI range
python skills/spatial/spatial-raw-processing/spatial_raw_processing.py \
--read1 R1.fq.gz --read2 R2.fq.gz --ids barcodes.tsv \
--ref-map /refs/star_index --platform slideseq \
--umi-start-position 1 --umi-end-position 8 \
--output results/
See also
references/parameters.md— every CLI flag, ST-Pipeline option mappingreferences/methodology.md— when ST-Pipeline wins vs Space Ranger; barcode-ID formatreferences/output_contract.md—raw_counts.h5adschema- Adjacent skills:
spatial-preprocess(downstream — required next step; consumesraw_counts.h5ad),bulkrna-read-qc/sc-fastq-qc(parallel — non-spatial FASTQ paths)
Dependencies
Python packages this skill's script needs. They are not installed for you — check before a long run.
anndata, matplotlib, numpy, pandas, PyYAML, scipy, seaborn