spatial-transcriptomics-tutorials-with-omicverse
БесплатноБез исполняемых скриптовНе проверенSpatial transcriptomics: Visium/HD, Stereo-seq, Slide-seq preprocessing (crop, rotate, cellpose), deconvolution (Tangram, cell2location, Starfysh), clustering…
Об этом скилле
Spatial Transcriptomics with OmicVerse
This skill covers spatial analysis workflows organized into three stages: Preprocessing, Deconvolution, and Downstream Analysis. Each stage includes the critical function calls, parameter guidance, and common pitfalls.
Defensive Validation: Always Check Spatial Coordinates First
Before ANY spatial operation, verify that spatial coordinates exist and are numeric:
# Required check before spatial analysis
assert 'spatial' in adata.obsm, \
"Missing adata.obsm['spatial']. Load with ov.io.spatial.read_visium() or set manually."
# Cast to float64 to prevent coordinate precision issues during rotation/cropping
adata.obsm['spatial'] = adata.obsm['spatial'].astype('float64')
Stage 1: Preprocessing
Crop, Rotate, and Align Coordinates
Load Visium data and manipulate spatial coordinates for region selection and alignment:
import scanpy as sc, omicverse as ov
ov.plot_set()
adata = sc.datasets.visium_sge(sample_id="V1_Breast_Cancer_Block_A_Section_1")
library_id = list(adata.uns['spatial'].keys())[0]
# Cast coordinates before manipulation
adata.obsm['spatial'] = adata.obsm['spatial'].astype('float64')
# Crop to region of interest
adata_crop = ov.space.crop_space_visium(adata, crop_loc=(0, 0), crop_area=(1000, 1000),
library_id=library_id, scale=1)
# Rotate and auto-align
adata_rot = ov.space.rotate_space_visium(adata, angle=45, library_id=library_id)
ov.space.map_spatial_auto(adata_rot, method='phase')
# For manual refinement: ov.space.map_spatial_manual(adata_rot, ...)
Visium HD Cell Segmentation
Segment Visium HD bins into cells using cellpose:
adata = ov.space.read_visium_10x(path="binned_outputs/square_002um/",
source_image_path="tissue_image.btf")
ov.pp.filter_genes(adata, min_cells=3)
ov.pp.filter_cells(adata, min_counts=1)
# H&E-based segmentation (in place, returns None: do not reassign adata);
# method="stardist" runs bin2cell's StarDist path instead of Cellpose
ov.space.visium_10x_hd_cellpose_he(adata, mpp=0.3, gpu=True, buffer=150)
# Expand labels to neighboring bins
ov.space.visium_10x_hd_cellpose_expand(adata, labels_key='labels_he',
expanded_labels_key='labels_he_expanded', max_bin_distance=4)
# Gene-expression-driven seeds
ov.space.visium_10x_hd_cellpose_gex(adata, obs_key="n_counts_adjusted", mpp=0.3, sigma=5)
# Merge labels and aggregate to cell-level
ov.space.salvage_secondary_labels(adata, primary_label='labels_he_expanded',
secondary_label='labels_gex', labels_key='labels_joint')
cdata = ov.space.bin2cell(adata, labels_key='labels_joint')
Image and transcript segmentation (ov.space.seg)
For a raw microscopy image (DAPI / H&E / IF) or an imaging-platform
transcript table (Xenium, CosMx, MERSCOPE), use ov.space.seg. Check that it
exists first (hasattr(ov.space, "seg")); older omicverse releases lack it.
ov.space.seg.methods() # backends, installed?, GPU?, input type
labels = ov.space.seg.segment("dapi.tif", method="cellpose", gpu=True) # tiled, seam-free
# method: "watershed" (no deps) | "cellpose" (v3/v4) | "stardist" | "sam" | "sam2"
# | "micro_sam" | "cellsam"; image_type="he" for H&E, diameter= in pixels
tx["cell"] = ov.space.seg.assign_transcripts(tx, labels, pixel_size=0.2125)
cdata = ov.space.seg.aggregate(tx, cell="cell", gene="feature_name", labels=labels,
pixel_size=0.2125) # cells x genes AnnData + polygons
# Transcript-only (Baysor CLI must be on PATH), optionally with the image labels as a prior
tx2 = ov.space.seg.segment_transcripts(tx, method="baysor", scale=8, prior="cell")
# Reference-free CellSPA metrics and a ranked comparison of several segmentations
res = {m: ov.space.seg.evaluate(lab, transcripts=tx.assign(
cell=ov.space.seg.assign_transcripts(tx, lab))) for m, lab in labels_by_method.items()}
ov.space.seg.compare(res)
- Coordinates:
pixel_size(µm per pixel),offset, or a 3x3transformmap transcript units to image pixels; get them from the platform's metadata. - Picking a method: in the Nat. Methods 2026 benchmark no method won
everywhere. SAM / SAM 2 led the unadjusted overall score and transcript QC,
Baysor ranked near the top once segmentation yield was accounted for, and
Cellpose and watershed ranked lower. Run 2-3 candidates and pick with
ov.space.seg.compareon your own data. sam/sam2fall back to CPU on Apple MPS; run them on a CUDA GPU.
Stage 2: Deconvolution
Critical API Reference: Method Selection
# CORRECT — Tangram: method passed to deconvolution() call
decov_obj = ov.space.Deconvolution(adata_sc=sc_adata, adata_sp=sp_adata,
celltype_key='Subset', result_dir='result/tangram')
decov_obj.preprocess_sc(max_cells=5000)
decov_o
Установить spatial-transcriptomics-tutorials-with-omicverse в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл spatial-transcriptomics-tutorials-with-omicverse?
Spatial transcriptomics: Visium/HD, Stereo-seq, Slide-seq preprocessing (crop, rotate, cellpose), deconvolution (Tangram, cell2location, Starfysh), clustering (GraphST, STAGATE), integration, trajectory, communication.
Как установить скилл spatial-transcriptomics-tutorials-with-omicverse?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл spatial-transcriptomics-tutorials-with-omicverse запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic