作者,Evil Genius
什么是空间轨迹?
以一个空间位置为起点(例如上图的交界区域),沿着固定方向上的细胞、基因表达的变化。
还有如下的分析结果,沿着相同方向、以相同的区域为起点,分析细胞类型空间分布的轨迹变化。
以及如下的区域细胞/基因转换
但我们最常见的空间轨迹分析如下:
Indicated cell signatures from sc/snRNA-seq mapped onto the Visium zonation data
我们需要实现的空间轨迹分析正是如此,分析示例(visium平台)
import warnings
warnings.filterwarnings("ignore")
import scanpy as sc
import pandas as pd
import SOAPy_st as sp
import matplotlib.pyplot as plt
# input adata
adata = sc.read_h5ad('1516761_10X_adata.h5ad')
# delete genes with same names
adata.var_names_make_unique()
# preprocessing
adata.var["mt"] = adata.var_names.str.startswith("MT-")
sc.pp.calculate_qc_metrics(adata, qc_vars=["mt"], inplace=True)
sc.pp.filter_genes(adata, min_counts=10)
sc.pp.filter_genes(adata, min_cells=2)
sc.pp.normalize_total(adata, inplace=True)
sc.pp.log1p(adata)
sc.pl.spatial(adata, img_key="hires", color='cluster')
##### Generate a mask image from the domain cluster
mask = sp.tl.get_mask_from_domain(adata, clusters='WM', KSize=35, cluster_key='cluster')
plt.imshow(mask, cmap='gray')
plt.show()
统计与回归
wilcoxon_res = sp.tl.wilcoxon_test(
adata,
mask,
radius=1000,
location='out',
cut=500
)
pearman_res = sp.tl.spearman_correlation(
adata,
mask,
radius=1000,
num=5
)
sp.tl.spatial_tendency(
adata,
mask, #
radius=1000,
location='out',
frac=5
)
sp.pl.show_tendency(adata, gene_name = 'PCP4', show=True)
sc.pl.spatial(adata, img_key="hires", color='PCP4')
Clustering genes based on regression curves
sp.tl.gene_cluster(adata=adata, k=10, range_min=0.03, fdr=True, pvalue=0.05)
sp.pl.show_curves_cluster(adata)
分析示例,高精度平台大家可以借鉴squidpy,不过离我们想要的效果还是差点。
sq.gr.co_occurrence(
adata_subsample,
cluster_key="leiden",
)
sq.pl.co_occurrence(
adata_subsample,
cluster_key="leiden",
clusters="12",
figsize=(10, 10),
)
sq.pl.spatial_scatter(
adata_subsample,
color="leiden",
shape=None,
size=2,
)
或者其他很好的方法
sm.pl.spatial_distance (adata, method='distribution',distance_from='ECAD+',distance_to = 'SMA+', imageid='ROI', log=True, height=3, aspect=9/8)
生活很好,有你更好
网友评论