Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

bio-spatial-transcriptomics-spatial-domains

БесплатноЗапускает вложенные скриптыНе проверен

Identify spatial domains and tissue regions in spatial transcriptomics data using Squidpy and Scanpy. Cluster spots considering both expression and spatial…

FridrichMethodот FridrichMethod★ 17 звёзд на GitHub

Об этом скилле

Version Compatibility

Reference examples tested with: matplotlib 3.8+, numpy 1.26+, pandas 2.2+, scanpy 1.10+, scikit-learn 1.4+, scipy 1.12+, squidpy 1.3+

Before using code patterns, verify installed versions match. If versions differ:

  • Python: pip show <package> then help(module.function) to check signatures

If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.

Spatial Domain Detection

"Identify tissue domains in my spatial data" → Cluster spots/cells considering both gene expression and physical proximity to define anatomically coherent spatial domains.

  • Python: squidpy.gr.spatial_neighbors() → Leiden clustering with spatial graph, or BayesSpace/SpaGCN

Identify spatial domains and tissue regions by combining expression and spatial information.

Required Imports

import squidpy as sq
import scanpy as sc
import numpy as np
import matplotlib.pyplot as plt

Standard Clustering (Expression Only)

Goal: Cluster spots based purely on gene expression, ignoring spatial location.

Approach: Build an expression-based neighbor graph, then apply Leiden community detection.

# Standard Leiden clustering (ignores spatial context)
sc.pp.neighbors(adata, n_neighbors=15, n_pcs=30)
sc.tl.leiden(adata, resolution=0.5, key_added='leiden')

# Visualize on tissue
sq.pl.spatial_scatter(adata, color='leiden', size=1.3)

Spatial-Aware Clustering with Squidpy

Goal: Cluster spots using only spatial proximity to identify contiguous tissue regions.

Approach: Build a spatial neighbor graph, then run Leiden clustering on the spatial graph.

# Build spatial neighbors
sq.gr.spatial_neighbors(adata, coord_type='generic', n_neighs=6)

# Run Leiden on spatial graph
sc.tl.leiden(adata, resolution=0.5, key_added='spatial_leiden', neighbors_key='spatial_neighbors')

sq.pl.spatial_scatter(adata, color='spatial_leiden', size=1.3)

Combined Expression + Spatial Graph

Goal: Integrate both expression similarity and spatial proximity for domain detection.

Approach: Build separate expression and spatial graphs, normalize each, then combine as a weighted average for clustering.

from scipy.sparse import csr_matrix
from sklearn.preprocessing import normalize

# Build both graphs
sq.gr.spatial_neighbors(adata, coord_type='generic', n_neighs=6)
sc.pp.neighbors(adata, n_neighbors=15, n_pcs=30)

# Combine graphs (weighted average)
spatial_weight = 0.3
spatial_conn = adata.obsp['spatial_connectivities']
expr_conn = adata.obsp['connectivities']

# Normalize
spatial_norm = normalize(spatial_conn, norm='l1', axis=1)
expr_norm = normalize(expr_conn, norm='l1', axis=1)

# Combine
combined = spatial_weight * spatial_norm + (1 - spatial_weight) * expr_norm
adata.obsp['combined_connectivities'] = csr_matrix(combined)

# Cluster on combined graph
sc.tl.leiden(adata, resolution=0.5, key_added='combined_leiden', adjacency=adata.obsp['combined_connectivities'])

BayesSpace (R Integration)

# BayesSpace provides spatial smoothing for domain detection
# Run in R, then import results

# R code (run separately):
# library(BayesSpace)
# sce <- readRDS("sce.rds")
# sce <- spatialPreprocess(sce, platform="Visium")
# sce <- spatialCluster(sce, q=7, nrep=10000)
# saveRDS(sce, "sce_bayesspace.rds")

# Import BayesSpace results
import rpy2.robjects as ro
from rpy2.robjects import pandas2ri
pandas2ri.activate()

ro.r('sce <- readRDS("sce_bayesspace.rds")')
spatial_clusters = ro.r('colData(sce)$spatial.cluster')
adata.obs['bayesspace'] = list(spatial_clusters)

STAGATE for Spatial Domains

Goal: Detect spatial domains using deep learning with graph attention networks.

Approach: Build a spatial graph with STAGATE, train the model to learn spatially-aware embeddings, then cluster on those embeddings.

# STAGATE uses graph attention for spatial domain detection
import STAGATE

# Build graph
STAGATE.Cal_Spatial_Net(adata, rad_cutoff=150)
STAGATE.Stats_Spatial_Net(adata)

# Train STAGATE
adata = STAGATE.train_STAGATE(adata, alpha=0)

# Cluster on STAGATE embeddings
sc.pp.neighbors(adata, use_rep='STAGATE')
sc.tl.leiden(adata, resolution=0.5, key_added='stagate_leiden')

Evaluate Domain Quality

Goal: Assess whether identified domains form spatially and transcriptionally coherent regions.

Approach: Compute silhouette scores separately for spatial coordinates and expression PCA to quantify domain separation.

# Check if domains are spatially coherent
from sklearn.metrics import silhouette_score

coords = adata.obsm['spatial']
labels = adata.obs['spatial_leiden'].values

# Spatial silhouette score
spatial_silhouette = silhouette_score(coords, labels)
print(f'Spatial silhouette score: {spatial_silhouette:.3f}')

# Expression silhouette score
expr_silhouette = silhouette_score(adata.obsm['X_pca'], labels)
pr
Полный SKILL.md на GitHub

Установить bio-spatial-transcriptomics-spatial-domains в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

examples/detect_domains.pyusage-guide.md

FAQ

Что делает скилл bio-spatial-transcriptomics-spatial-domains?

Identify spatial domains and tissue regions in spatial transcriptomics data using Squidpy and Scanpy. Cluster spots considering both expression and spatial context to define anatomical regions. Use when identifying tissue domains or spatial regions.

Как установить скилл bio-spatial-transcriptomics-spatial-domains?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл bio-spatial-transcriptomics-spatial-domains запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить bio-spatial-transcriptomics-spatial-domains с