Spateo基于SSDNA圈细胞操作指南

Cell segmentation demo

%time
exec('import warnings; warnings.filterwarnings("ignore")')
import matplotlib.pyplot as plt
import spateo as st
import numpy as np
import skimage
import sklearn
st.config.n_threads = 8

圈细胞分析需要准备的数据有空间 UMI 计数矩阵和ssDNA染色图像,测试数据可以从数据库网站MOSTA: Mouse Organogenesis Spatiotemporal Transcriptomic Atlas 下载使用。

Load data

### 加载 UMI 计数矩阵和细胞核染色图像到 AnnData 对象
adata = st.io.read_bgi_agg("./E12.5_E1S3_GEM_bin1.tsv.gz", "./E12.5_E1S3.tif")
print(adata.layers["stain"].shape)
adata
|-----> Constructing count matrices.
|-----> <insert> __type to uns in AnnData Object.
|-----> <insert> pp to uns in AnnData Object.
|-----> <insert> spatial to uns in AnnData Object.
(22834, 17384)
AnnData object with n_obs × n_vars = 22834 × 17384
    uns: '__type', 'pp', 'spatial'
    layers: 'stain'

显示细胞核染色图像

st.pl.imshow(adata, 'stain')

stain segmentation

Watershed-based approach to segment and label nuclei from the staining image.
%time
st.cs.mask_nuclei_from_stain(adata) ### 创建染色图像细胞核蒙版
st.pl.imshow(adata, 'stain_mask')
plt.savefig("stain_mask.png",dpi=600)
plt.close()

st.cs.find_peaks_from_mask(adata, 'stain', 7) 
st.cs.watershed(adata, 'stain', 5, out_layer='watershed_labels')

fig, ax = st.pl.imshow(adata, 'stain', save_show_or_return='return')
st.pl.imshow(adata, 'watershed_labels', labels=True, alpha=0.5, ax=ax)
plt.savefig("waterfall.png",dpi=600)
plt.close()

Deep learning-based approach
%time
st.cs.stardist(adata, tilesize=2000, equalize=2.0, out_layer='stardist_labels')
fig, ax = st.pl.imshow(adata, 'stain', save_show_or_return='return')
st.pl.imshow(adata, 'stardist_labels', labels=True, alpha=0.5, ax=ax)
plt.savefig("fig5_stardist.png",dpi=600)
plt.close()

Augment labels

st.cs.augment_labels(adata, 'watershed_labels', 'stardist_labels', out_layer='augmented_labels')

fig, ax = st.pl.imshow(adata, 'stain', save_show_or_return='return')
st.pl.imshow(adata, 'augmented_labels', labels=True, alpha=0.5, ax=ax)
plt.savefig("Argmented_labels.png",dpi=600)
plt.close()

Expand labels to cytoplasm

st.cs.mask_cells_from_stain(adata, out_layer='stain_cell_mask')
st.cs.watershed(adata,'stain',mask_layer='stain_cell_mask', markers_layer='augmented_labels',out_layer='cell_labels')
fig, ax = st.pl.imshow(adata, 'stain', save_show_or_return='return')
st.pl.imshow(adata, 'cell_labels', labels=True, alpha=0.5, ax=ax)
st.cs.expand_labels(adata, 'augmented_labels', distance=5, max_area=400)
st.cs.expand_labels(adata, 'cell_labels', distance=2, out_layer='cell_labels_expanded')

fig, ax = st.pl.imshow(adata, 'stain', save_show_or_return='return')
st.pl.imshow(adata, 'cell_labels_expanded', labels=True, alpha=0.5, ax=ax)

Obtain a cell x gene matrix

cell_adata = st.io.read_bgi("./E12.5_E1S3_GEM_bin1.tsv.gz",segmentation_adata=adata, labels_layer='cell_labels_expanded',)
cell_adata
|-----> <select> cell_labels_expanded layer in AnnData Object
|-----> Using labels provided with `segmentation_adata` and `labels_layer` arguments.
|-----> Constructing count matrices.
|-----> <insert> __type to uns in AnnData Object.
|-----> <insert> pp to uns in AnnData Object.
|-----> <insert> spatial to uns in AnnData Object.
AnnData object with n_obs × n_vars = 70475 × 26274
    obs: 'area'
    uns: '__type', 'pp', 'spatial'
    obsm: 'spatial', 'contour', 'bbox'
    layers: 'spliced', 'unspliced'
import joblib
joblib.dump(cell_adata,"cell_adata_segmentation.pkl")

圈细胞后获得的表达矩阵就可以进行后续的降维聚类差异分析…参考这篇文章spateo 数据分析demo进行数据分析。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

倪桦

有帮助的话请杯咖啡吧,谢谢!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值