Scatac preprocessing

From TianGzlab/OmicsClaw · View interactive version

Scatac preprocessing is an AI agent skill from the GitHub repository TianGzlab/OmicsClaw. Load when preprocessing a single-cell ATAC peak × cell AnnData via Signac-style TF-IDF + LSI + Leiden, producing a clustered UMAP-ready object. Skip when input is fragments; BAM (peak calling not implemented here); scRNA preprocessing (use sc-preprocessing).

How to use this skill

Skill file

scatac-preprocessing

Use from a step

from skills._sdk.notebook import load_skill, read_input, write_output

atac = load_skill("scatac-preprocessing")
adata = read_input("data/peaks.h5", reader=atac.read_10x_peaks)
adata = atac.preprocess(adata, random_state=0)
write_output(adata, "intermediate/accessibility.h5ad")
write_output(atac.cluster_summary(adata), "tables/clusters.csv")

For H5AD use read_input without a reader. The API returns a copy and does

not write files. examples/example_step.py recovers three planted groups

from load_demo("atac_synthetic"); that tests computation, not biological validity.

When to use

The user has a cell × peak scATAC AnnData (raw-count-like accessibility

matrix in .X) and wants the standard "filter → TF-IDF → LSI → graph →

UMAP → Leiden" pipeline in one shot. Currently a single backend:

tfidf_lsi (Signac-style). The skill stops at clustered UMAP — no

fragment QC, no peak calling, no motif / gene-activity scoring, no

multi-sample integration. For scRNA preprocessing use sc-preprocessing.

Inputs & Outputs

Inputs

Outputs

Flow

  1. Read cell × peak counts. The 10x reader uses gex_only=False and keeps Peaks in multiome inputs; other CLI formats use smart_load.
  2. Validate .X is present, non-empty, non-negative.
  3. Compute per-cell n_peaks_by_counts / total_counts; filter cells by --min-peaks and peaks by --min-cells.
  4. Retain the globally most accessible peaks up to --n-top-peaks.
  5. Run Signac-style TF-IDF (--tfidf-scale-factor); truncated-SVD LSI to --n-lsi components.
  6. Build neighbour graph (--n-neighbors), UMAP, Leiden (--leiden-resolution).
  7. Save processed.h5ad, tables, figures, report.md, result.json.

Gotchas

Key CLI

# Demo (built-in synthetic scATAC)
python skills/singlecell/scatac/scatac-preprocessing/scatac_preprocessing.py --demo --output /tmp/scatac_demo

# Standard run on a 10x scATAC h5
python skills/singlecell/scatac/scatac-preprocessing/scatac_preprocessing.py \
  --input atac_peaks.h5 --output results/

# Tune QC + feature budget
python skills/singlecell/scatac/scatac-preprocessing/scatac_preprocessing.py \
  --input atac_peaks.h5ad --output results/ \
  --min-peaks 300 --min-cells 10 --n-top-peaks 20000

# Tune latent space + clustering
python skills/singlecell/scatac/scatac-preprocessing/scatac_preprocessing.py \
  --input atac_peaks.h5ad --output results/ \
  --n-lsi 40 --n-neighbors 20 --leiden-resolution 1.0

API

<!-- api:begin generated from _api.py; regenerate with run.py api <skill dir> --write -->

`preprocess(adata, *, min_peaks=200, min_cells=5, n_top_peaks=10000, tfidf_scale_factor=10000.0, n_lsi=30, n_neighbors=15, leiden_resolution=0.8, random_state=0)`

Return a filtered copy of .X accessibility counts with TF-IDF, LSI and Leiden.

Cells need min_peaks detected peaks; peaks need min_cells cells. Keep at

most n_top_peaks, ranked by total counts. Counts remain in layers['counts']

and .raw on retained peaks; .X becomes log1p TF-IDF. LSI uses scaled SVD

components, excluding the first component from the neighbor graph. UMAP

and Leiden use that graph. All stochastic operations use random_state.

No file is written and the input is not modified.

`read_10x_peaks(path)`

Read 10x H5 or MTX peak counts; pass it as reader= to read_input.

Use gex_only=False, then keep Peaks when feature_types is present. No

gene-expression filtering is applied to a peak-only matrix lacking it.

`qc_metrics_table(adata)`

Return cell identifiers and the QC metrics computed before top-peak selection.

`peak_summary(adata, *, n_top=50)`

Return retained peaks ranked by total counts and number of cells.

`lsi_variance_table(adata)`

Return variance ratios and their cumulative sum for every fitted LSI component.

`cluster_summary(adata, *, cluster_key='leiden')`

Return cell counts and percentages for labels in obs[cluster_key].

`umap_figure(adata, *, cluster_key='leiden')`

Return a cluster-colored Figure from obsm['X_umap']; do not write a file.

`run_info(adata, *, keep: bool=True)`

Return TF-IDF/LSI parameters; keep=False removes the run record.

<!-- api:end -->

See also

Dependencies

Python packages this skill's script needs. They are not installed for you — check before a long run.

anndata, igraph, matplotlib, numpy, pandas, scanpy, scikit-learn, scipy, seaborn

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.