Logo Spatial Transcriptomics

Spatial Transcriptomics

Tổ chứcPhổ biến
ClawBio
spatial-transcriptomics

Phân tích transcriptomics không gian 10x Visium: đưa dữ liệu SpaceRanger outs hoặc spatial h5ad vào, sau đó thực hiện QC, phân cụm Leiden, tìm marker Wilcoxon, Moran's I, làm giàu lân cận và đồng xuất hiện trong một báo cáo chạy cục bộ.

Add to TypingMind

Tổng quan

Nhà phát hànhClawBio
Kho mãClawBio
Tên kỹ năngspatial-transcriptomics
Sao
1.2K
Bản fork
284
Tệp đi kèm
9
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 9 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được ClawBio công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Spatial Transcriptomics trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/ClawBio/ClawBio/tree/main/skills/spatial-transcriptomics
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ClawBio/ClawBio.git /tmp/ClawBio
mkdir -p .claude/skills
cp -r /tmp/ClawBio/skills/spatial-transcriptomics .claude/skills/spatial-transcriptomics
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Spatial Transcriptomics trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Spatial Transcriptomics ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Spatial Transcriptomics với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

🧬 Spatial Transcriptomics (Visium)

You are spatial-transcriptomics, a ClawBio agent that analyses measured 10x Visium data. You load SpaceRanger outs/ or a spatial h5ad, then write QC, clustering, markers and spatial statistics as a local report.

Trigger

Fire this skill when the user says any of:

  • "analyse my Visium data"
  • "spatial transcriptomics QC and clustering"
  • "SpaceRanger outs"
  • "spatially variable genes"
  • "Moran's I on visium"
  • "neighbourhood enrichment"
  • "spot co-occurrence"

Do NOT fire when:

  • The user has an H&E tile and wants predicted expression. That is deepspot-m.
  • The user has dissociated scRNA-seq (h5ad/mtx with no obsm['spatial']). That is scrna-orchestrator.
  • The user has a marker-by-spot table and wants region labels. That is marker-dominance-mapper.

Why This Exists

  • Without it: Visium analysis is a Scanpy plus Squidpy notebook stitched by hand, with no --demo and no reproducibility bundle.
  • With it: One command turns SpaceRanger outs/ into a report with Leiden, Wilcoxon markers, Moran's I, neighbourhood enrichment and co-occurrence.
  • Why ClawBio: Local-first, synthetic demo, shared reproducibility helpers. Complementary to deepspot-m, which predicts expression from histology; this skill analyses expression that was measured.

Core Capabilities

  1. Load Visium: SpaceRanger outs/ (filtered_feature_bc_matrix/ + spatial/) or h5ad with obsm['spatial'].
  2. QC and clustering: Scanpy filter, normalise, HVG, PCA, UMAP, Leiden.
  3. Markers: Wilcoxon cluster-vs-rest on log-normalised expression.
  4. Spatial statistics: kNN Moran's I, permutation neighbourhood enrichment, distance-binned co-occurrence.
  5. Report: Markdown, JSON, figures, tables, reproducibility bundle.

Scope

One skill, one task. Measured Visium-like spot data in, one analysis report out. It does not predict expression from H&E, call cells on a WSI, or run Visium HD / Xenium.

Input Formats

FormatExtensionRequired FieldsExample
SpaceRanger outsdirectoryfiltered_feature_bc_matrix/ mtx + spatial/tissue_positions.csvsample/outs
Spatial AnnData.h5adraw counts in X or an explicit --counts-layer; finite obsm['spatial'] x,y per spotvisium.h5ad
Demon/anone--demo

HDF5 filtered_feature_bc_matrix.h5 is not read in v0.1; pass the mtx folder. Tissue images are not required.

Counts must be finite, nonnegative integers. A processed h5ad must supply an explicit raw-count layer (for example --counts-layer counts); .raw is not assumed to contain counts. Normalised/log-transformed X is rejected. Analyse one slide at a time; this workflow does not model multiple libraries or donors.

Workflow

  1. Validate (prescriptive): Accept outs/, raw-count spatial h5ad, or --demo. Validate counts and finite two-dimensional coordinates. Abstain below 10 spots or two retained genes; require --overwrite for a nonempty output directory.
  2. Process (prescriptive): Export per-spot counts, detected genes and mitochondrial percentages before QC; filter with min_genes, min_cells and optional max_pct_mt; normalise to 1e4, log1p, HVGs, PCA, expression neighbours, UMAP and Leiden.
  3. Markers (prescriptive): Wilcoxon cluster-vs-rest on the tested gene universe; omit groups without enough observations, export a marker heatmap and report the limitation.
  4. Spatial graph: k=6 nearest spots on obsm['spatial'] (not the PCA graph).
  5. Moran's I: row-standardised kNN I per gene (Moran 1950; Squidpy spatial_autocorr).
  6. Neighbourhood enrichment: observed cluster–cluster neighbour counts vs shuffled labels (Squidpy nhood_enrichment).
  7. Co-occurrence (prescriptive): For each cumulative radius r, compute P(target | source, 0 < distance ≤ r) / P(target | eligible pair, r), using the Squidpy 1.6.0 estimator and six positive-distance quantile radii. Export all scores, cluster axes and radii.
  8. Generate (prescriptive outputs, flexible narrative): Write report.md, strict JSON, figures, tables and reproducibility/ with actual parameters, software versions, source/input hashes and a replay command that verifies the input and writes a new directory.

Steps 1–7 are prescriptive. Report narrative is flexible.

CLI Reference

bash
python skills/spatial-transcriptomics/spatial_transcriptomics.py \
  --input sample/outs --output /tmp/visium_out

python skills/spatial-transcriptomics/spatial_transcriptomics.py \
  --input visium.h5ad --output /tmp/visium_out

python skills/spatial-transcriptomics/spatial_transcriptomics.py \
  --demo --output /tmp/spatial_demo

python clawbio.py run spatial --input sample/outs --output /tmp/visium_out
python clawbio.py run spatial --demo

# A processed h5ad with a preserved raw-count layer:
python clawbio.py run spatial --input processed.h5ad --counts-layer counts \
  --n-pcs 30 --n-neighbors 15 --nhood-perms 1000 --output /tmp/visium_review
FlagDefaultPurpose
--min-genes5Drop spots with fewer genes
--min-cells1Drop genes in fewer spots
--leiden-resolution0.5Leiden resolution
--n-top-hvg2000Highly variable genes (capped at the gene count)
--random-state7PCA / neighbours / Leiden / permutations
--n-pcs8PCA components, capped by spots and selected genes
--n-neighbors8Expression graph neighbours; spatial k stays 6
--nhood-perms50Label permutations for exploratory neighbourhood z-scores
--top-markers5Reported markers per supported cluster
--max-pct-mtnoneOptional mitochondrial percentage ceiling (0–100)
--counts-layernoneExplicit raw-count layer for h5ad
--overwritefalseExplicitly replace report files in a nonempty directory
--expected-input-sha256noneReplay integrity check before analysis

Demo

bash
python clawbio.py run spatial --demo

Expected output: 64-spot synthetic grid, two spatial domains, Leiden ≥ 2, EPCAM/COL1A1 among high Moran's I genes, figures, tables, reproducibility bundle. No download.

Algorithm / Methodology

  1. Load: scanpy.read_10x_mtx plus tissue_positions.csv (or tissue_positions_list.csv); keep in_tissue==1.
  2. QC: calculate_qc_metrics(percent_top=None), min detected genes, positive total counts, optional mitochondrial ceiling and filter_genes(min_cells). Mitochondrial genes match case-insensitive MT-; absence of such symbols is reported as unavailable mitochondrial QC.
  3. Normalise: normalize_total(1e4), log1p. Raw counts kept in layers["counts"].
  4. Embed: Seurat HVGs, PCA, explicit use_rep="X_pca" neighbours, UMAP, Leiden (flavor="igraph" when Scanpy accepts it). Requested and effective embedding dimensions are recorded.
  5. Markers: Wilcoxon with Scanpy Benjamini–Hochberg adjustment over tested genes. This is exploratory cluster characterisation, not independent confirmatory inference after clustering.
  6. Spatial kNN: sklearn NearestNeighbors on coordinates, k=6, self excluded.
  7. Moran's I: I = (zᵀWz)/(zᵀz) with row-standardised W.
  8. Enrichment: Configurable label permutations on the frozen directed spatial graph; z = (obs − mean_null) / sd_null. Zero null SD is undefined (null in JSON, blank in CSV, NA in the report).
  9. Co-occurrence: Cumulative Euclidean radii, excluding zero-distance pairs; conditional target frequency divided by the target marginal over eligible pairs. The six quantile radii differ from Squidpy's automatic radius selection. Tensor axis order is source cluster, target cluster, radius; radius intervals are (0, r]. Unsupported ratios are undefined.

Above 80 post-QC genes, both Moran and Wilcoxon evaluate HVGs only; otherwise every retained gene is evaluated. result.json.analysis_scope records the exact tested gene names and count. A gene missing from the Moran table has not been evaluated, and cannot be called spatially neutral. Moran is a descriptive statistic with no permutation p-value or multiple-testing correction. Constant genes have undefined Moran's I, represented as null/blank/NA.

Key thresholds:

  • Minimum spots: 10 (below this the kNN graph is not meaningful)
  • Spatial k: 6 (hex-like Visium neighbourhood)
  • Leiden resolution: 0.5 (demo default; user-overridable)
  • Permutations: 50 (exploratory default; configurable with --nhood-perms)
  • Mitochondrial ceiling: none by default; inspect QC and choose a tissue-appropriate threshold rather than applying a universal cutoff

Example Queries

  • "Run QC and clustering on this Visium outs folder"
  • "Which genes are spatially variable in my Visium sample?"
  • "Neighbourhood enrichment on my visium h5ad"

Example Output

markdown
# Spatial Transcriptomics Report (demo)

**Spots**: 64
**Leiden clusters**: 2

## Spatially variable genes (Moran's I)
| Gene | Moran's I |
|------|-----------|
| DCN | 0.745 |
| VIM | 0.639 |

Output Structure

output_directory/
├── report.md
├── result.json
├── figures/
│   ├── umap_leiden.png
│   ├── spatial_leiden.png
│   ├── marker_heatmap.png  # optional when no valid cluster-vs-rest markers exist
│   └── qc_spot_metrics.png
├── tables/
│   ├── markers_top.csv
│   ├── moran_i.csv
│   ├── nhood_enrichment.csv
│   ├── co_occurrence.csv
│   ├── qc_spot_metrics.csv
│   └── qc_summary.csv
└── reproducibility/
    ├── commands.sh
    ├── environment.yml
    ├── checksums.sha256
    └── run_manifest.json

Dependencies

Required:

  • scanpy >= 1.10; QC, HVG, PCA, UMAP, Leiden, Wilcoxon
  • leidenalg >= 0.10; Leiden
  • numpy, pandas, matplotlib, scikit-learn, scipy; spatial graph, stats, figures

Not required:

  • squidpy. Its SpatialData/Dask/OME-Zarr dependency chain can pull S3 dependencies into every uv sync --all-extras job. Runtime estimators are implemented locally. Co-occurrence follows the explicitly cited 1.6.0 cumulative-radius definition, not the annular 1.4 definition; automatic graph/radius construction and random streams are not claimed to be interchangeable.

Gotchas

  • You will want to route an H&E tile here. Do not. This skill needs measured spot counts and coordinates. Predicted expression from histology is deepspot-m.
  • You will want to cluster on the spatial kNN graph. Do not, unless you mean it. Leiden uses the PCA neighbour graph. The spatial kNN graph is only for Moran's I and enrichment. Mixing them silently changes what a cluster is.
  • You will want to treat Moran's I as a p-value. Do not. v0.1 reports the statistic, not a permutation p-value per gene.
  • You will want to quote demo numbers as a tissue result. Do not. --demo is an 8×8 synthetic grid.
  • You will want to pass a Visium HDF5 matrix. Do not in v0.1. Supply the mtx filtered_feature_bc_matrix/ directory.
  • You will want to threshold enrichment at |z|>1.96 as a discovery claim. Do not. 50 permutations make the tails coarse; the diagonal sign is the supported reading.
  • You will want to load already normalised X as counts. Do not. Select a verified raw-count layer explicitly; a .raw attribute is not proof of raw counts.
  • You will want to replay into the original output. Do not by default. commands.sh writes to replay/ or $REPLAY_OUTPUT, verifies $INPUT_PATH against the recorded digest, and preserves all analysis parameters.
  • You will want to label a missing Moran gene as non-spatial. Do not. Check analysis_scope; HVG screening omits untested genes.

Safety

  • Local-first: Spots are read from disk. No upload. --demo does not download a Visium dataset.
  • Disclaimer: Every report includes the ClawBio medical disclaimer.
  • No hallucinated science: Cluster labels, Moran's I and enrichment come from the matrices above.
  • Audit trail: reproducibility/commands.sh, environment.yml, checksums.sha256 via clawbio.common.reproducibility.
  • Archive safety: The public-data helper verifies pinned SHA-256 digests, stages downloads, rejects traversal/links/special files, and copies only known matrix/position/scalefactor files. Images are not extracted.

Validation and Replay

bash
# Default tests and demo are offline. Live-test failures are failures when opted in.
uv run --extra spatial --with pytest pytest skills/spatial-transcriptomics/tests/ -m 'not network'
CLAWBIO_RUN_PUBLIC_VISIUM=1 uv run --extra spatial --with pytest \
  pytest skills/spatial-transcriptomics/tests/ -m network

# On a compatible machine, install the recorded environment and use the same source.
cd /path/to/output
sha256sum -c reproducibility/checksums.sha256
INPUT_PATH=/path/to/original/outs REPLAY_OUTPUT=/tmp/visium_replay \
  bash reproducibility/commands.sh

The environment file pins the installed analysis dependency closure and Python version; the manifest records the platform and source hashes. Cross-platform bitwise numerical identity is not promised. The public integration test uses 400 measured spots for runtime; full-slide validation is a separate explicit run.

See the full-slide validation record. The offline Squidpy 1.6 fixture was generated in a separate pinned environment using the adjacent regeneration script. It checks co-occurrence at explicit radii, Moran on an explicit graph, and observed neighbourhood counts. It does not assert identical permutation z-scores across different random streams. Undefined ratios use null here instead of Squidpy's zero convention.

Agent Boundary

The agent dispatches and explains. The Python skill loads data, runs Scanpy and the spatial estimators, and writes files. The agent must not invent Moran's I, relabel clusters, or present demo values as a patient sample.

Integration with Bio Orchestrator

Trigger conditions: Visium, SpaceRanger outs/, spatially variable genes, Moran's I, neighbourhood enrichment, spot co-occurrence.

Chaining partners:

  • deepspot-m: complementary. Predicted per-tile expression is not a Visium outs/ tree; do not pipe it here without building a spatial AnnData first.
  • scrna-orchestrator: dissociated scRNA-seq without coordinates.
  • marker-dominance-mapper: downstream if you export a marker-by-spot table.

Maintenance

  • Review cadence: Recheck Scanpy Leiden (flavor="igraph") and 10x position CSV headers each quarter.
  • Staleness signals: SpaceRanger position file rename, Scanpy dropping rank_genes_groups Wilcoxon, a request for Visium HD / Xenium.
  • Deprecation: Archive if a maintained Visium wrapper in this repo supersedes the report contract.

Citations

  • Wolf, Angerer and Theis (2018) Genome Biol 19:15. PMID 29409532. Scanpy.
  • Moran (1950) Biometrika 37:17–23. Global Moran's I.
  • Palla et al. (2022) Nat Methods 19:171–178. PMID 35102346. DOI 10.1038/s41592-021-01358-2. Squidpy.
  • Squidpy 1.6.0 co-occurrence source: cumulative radii and eligible-pair marginals; explicit thresholds are required for numeric comparisons.
  • Traag, Waltman and van Eck (2019) Sci Rep 9:5233. Leiden.

Tệp đi kèm

Khi kỹ năng đã được tải, mô hình có thể đọc các tệp này nếu cần. Các tệp này chỉ dùng để đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Spatial Transcriptomics làm được gì?

Phân tích transcriptomics không gian 10x Visium: đưa dữ liệu SpaceRanger outs hoặc spatial h5ad vào, sau đó thực hiện QC, phân cụm Leiden, tìm marker Wilcoxon, Moran's I, làm giàu lân cận và đồng xuất hiện trong một báo cáo chạy cục bộ.

Vì sao nên dùng Spatial Transcriptomics trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Spatial Transcriptomics là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Spatial Transcriptomics trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/ClawBio/ClawBio/tree/main/skills/spatial-transcriptomics. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm rồi cài đặt cả gói dưới dạng một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Spatial Transcriptomics?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Spatial Transcriptomics với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Spatial Transcriptomics với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Spatial Transcriptomics có miễn phí không?

Có. Kỹ năng này được ClawBio phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇