作者,Evil Genius
今天的目標(biāo)经宏,實(shí)現(xiàn)如下的分析
對(duì)于空間轉(zhuǎn)錄組而言犀暑,高精度平臺(tái)圖像分割獲取單細(xì)胞精度的矩陣絕對(duì)是必做的驯击。大家如果選擇做高精度空轉(zhuǎn),尤其Stereo-seq耐亏、HD徊都,一定要提前問(wèn)清楚是否具有圖像識(shí)別分割的能力。
我們來(lái)實(shí)現(xiàn)這個(gè)共定位差異比較分析广辰,基礎(chǔ)分析大家做好,包括整合分析暇矫,獲取h5ad文件,示例是cluster,大家分析項(xiàng)目要用細(xì)胞類型择吊。
###pip install cellcharter
import squidpy as sq
import cellcharter as cc
import scanpy as sc
from lightning.pytorch import seed_everything
seed_everything(0)
adata =sc.read('test.h5ad')
adata
AnnData object with n_obs × n_vars = 707474 × 29
obs: 'cell_type', 'i-niche', 'tile', 'area', 'dataset', 'stage', 'sample'
uns: 'spatial', 'spatial_cluster_colors'
obsm: 'blanks', 'spatial'
adata.raw = adata.copy()
for sample in adata.obs['sample'].cat.categories:
adata.X[adata.obs['sample'] == sample, :] = sc.pp.scale(adata[adata.obs['sample'] == sample], copy=True).X
####Proximity analysis
adata.obs['condition'] = adata.obs['sample'].str.split('-').str[0].astype('category')
adata_balbc = adata[adata.obs['condition'] == 'BALBc']
cc.gr.nhood_enrichment(
adata_balbc,
cluster_key='spatial_cluster',
)
cc.pl.nhood_enrichment(
adata_balbc,
cluster_key='spatial_cluster',
annotate=True,
vmin=-1,
vmax=1,
figsize=(3,3),
fontsize=5,
)
adata_mrl = adata[adata.obs['condition'] == 'MRL']
cc.gr.nhood_enrichment(
adata_mrl,
cluster_key='spatial_cluster',
)
cc.pl.nhood_enrichment(
adata_mrl,
cluster_key='spatial_cluster',
annotate=True,
vmin=-1,
vmax=1,
figsize=(3,3),
fontsize=5,
)
鄰域差異分析
cc.gr.diff_nhood_enrichment(
adata,
cluster_key='spatial_cluster',
condition_key='condition',
library_key='sample',
pvalues=True,
n_jobs=15,
n_perms=100
)
cc.pl.diff_nhood_enrichment(
adata,
cluster_key='spatial_cluster',
condition_key='condition',
condition_groups=['MRL', 'BALBc'],
annotate=True,
figsize=(3,3),
significance=0.05,
fontsize=5
)
cc.pl.diff_nhood_enrichment(
adata,
cluster_key='spatial_cluster',
condition_key='condition',
condition_groups=['BALBc', 'MRL'],
annotate=True,
figsize=(3,3),
significance=0.05,
fontsize=5
)
Shape characterization
cc.gr.connected_components(adata, cluster_key='spatial_cluster')
cc.tl.boundaries(adata, min_hole_area_ratio=0.1)
cc.tl.linearity(adata)
cc.tl.curl(adata)
cc.pl.shape_metrics(
adata,
condition_key='condition',
condition_groups=['BALBc', 'MRL'],
cluster_key='spatial_cluster',
cluster_id=[10],
title='C4 - B-PALS shape',
figsize=(4,3),
fontsize=6
)
最后李根,我們封裝起來(lái)