方法分享--Spotiphy获取单细胞精度的空间数据(visium)

作者,Evil Genius
马上周末了,大家做科研,也要注意劳逸结合,该休息就休息休息。
今日参考文献

我们都希望得到单细胞级别的空间精度,但事实是,现在几乎不可能,算法也只是推断。
算法的进展也是逐步的,跟技术平台的发展是一样的,最终的目标是确定的,但是过程是艰辛且漫长的。
细胞在其微环境中的位置是其功能和与邻近细胞相互作用的关键决定因素.细胞具有独特的特征和功能,通过称为细胞区域特异化的过程进行微调以满足其环境的特定需求.分析局部细胞行为涉及识别空间域,细胞对外界信号的反应由其空间域决定,影响组织发育、稳态和疾病进展。
Spotiphy实现了单细胞精度的空间全转录组。
ST + 单细胞数据 + 组织成像数据。
Spotiphy通过分割高分辨率组织学图像来确定细胞核的位置。它将上述信息整合到一个概率模型中,该模型考虑了每种细胞类型的基因贡献分布。这一独特的功能使ST数据的同时去卷积和分解成为可能,从而生成细胞类型比例和iscRNA数据。
Spotiphy生成相当于基于图像的方法输出的单细胞分辨图像,并在整个切片上进行全转录组分析。

匹配的小鼠大脑数据集

Spotiphy在稀有细胞类型反卷积精度方面表现优秀。
Xenium数据作为基础事实,当然了,都说自己的方法好。

Spotiphy捕获星形胶质细胞区域特化
Spotiphy具有将spot的转录组学谱分解到单细胞水平的能力。

Spotiphy揭示了疾病相关的小胶质细胞区域特征
对分解后单细胞级别的空间数据进行了再分析,分析差异基因与单细胞数据的差异。
GSEA富集分析,并通过CosMx进行数据验证,证明分析的有效性。

Spotiphy图表显示乳腺癌中的肿瘤-TME空间域
评估Spotiphy表征肿瘤和TME的能力(scRNA + visium)
有效识别正常细胞和肿瘤细胞。

Spotiphy创建伪单细胞全空转图像

Spotiphy克服了原位单核测序的限制
最后来看看示例代码,在https://github.com/jyyulab/Spotiphy

import spotiphy
import os
import pickle
import numpy as np
import pandas as pd
import matplotlib as mpl
import scanpy as sc
import torch
import cv2

import sys

results_folder = 'Spotiphy_Result/'
if not os.path.exists(results_folder):
    # Create result folder if it does not exist
    os.makedirs(results_folder)

import requests
if not os.path.exists('data/'):
    os.makedirs('data/')

data_path = ['data/scRNA_mouse_brain.h5ad', 'data/ST_mouse_brain.h5ad',
             'data/img_mouse_brain.png']
urls = ['https://raw.githubusercontent.com/jyyulab/Spotiphy/main/tutorials/data/scRNA_mouse_brain.h5ad',
        'https://raw.githubusercontent.com/jyyulab/Spotiphy/main/tutorials/data/ST_mouse_brain.h5ad',
        'https://raw.githubusercontent.com/jyyulab/Spotiphy/main/tutorials/data/img_mouse_brain.png']

for i, path in enumerate(data_path):
    if not os.path.exists(path):
        response = requests.get(urls[i], allow_redirects=True)
        with open(path, 'wb') as file:
            file.write(response.content)
        del response

adata_sc = sc.read_h5ad("data/scRNA_mouse_brain.h5ad")
adata_st = sc.read_h5ad("data/ST_mouse_brain.h5ad")
img = cv2.imread("data/img_mouse_brain.png")

key_type = 'celltype'
type_list = sorted(list(adata_sc.obs[key_type].unique().astype(str)))
print(f'There are {len(type_list)} cell types: {type_list}')
adata_st.var_names_make_unique()

adata_st.obsm['spatial'] = adata_st.obsm['spatial'].astype(np.int32)

fig, axs = mpl.pyplot.subplots(1, 3, figsize=(20, 5))
sc.pl.spatial(adata_st, color="in_tissue", frameon=False, show=False, ax=axs[0])
sc.pl.umap(adata_sc, color= key_type, size=10, frameon=False, show=False, ax=axs[1])
axs[2].imshow(img[:, :, [2, 1, 0]])  # In default, cv2 uses BGR. So we convert BGR to RGB.
axs[2].axis('off')
mpl.pyplot.tight_layout()
mpl.pyplot.savefig(results_folder+'figurepath+figurename.jpg', bbox_inches='tight', dpi=400)

####Deconvolution: Marker Gene Selection and scRNA Reference Construction
adata_sc, adata_st = spotiphy.initialization(adata_sc, adata_st, verbose=1)
marker_gene_dict = spotiphy.sc_reference.marker_selection(adata_sc, key_type=key_type, return_dict=True, 
                                                          n_select=50, threshold_p=0.1, threshold_fold=1.5,
                                                          q=0.15)
marker_gene = []
marker_gene_label = []
for type_ in type_list:
    marker_gene.extend(marker_gene_dict[type_])
    marker_gene_label.extend([type_]*len(marker_gene_dict[type_]))
marker_gene_df = pd.DataFrame({'gene':marker_gene, 'label':marker_gene_label})
marker_gene_df.to_csv(results_folder+'marker_gene.csv')
# Filter scRNA and spatial matrices with marker genes
adata_sc_marker = adata_sc[:, marker_gene]
adata_st_marker = adata_st[:, marker_gene]
     
sc_ref = spotiphy.construct_sc_ref(adata_sc_marker, key_type=key_type)

####Deconvolution: Cellular Proportion Estimation
device = 'cuda' if torch.cuda.is_available() else 'cpu'
X = np.array(adata_st_marker.X)
cell_proportion = spotiphy.deconvolution.estimation_proportion(X, adata_sc_marker, sc_ref, type_list, key_type, n_epoch=8000,
                                                               plot=True, batch_prior=1, device=device)
adata_st.obs[type_list] = cell_proportion
# Save the cellular proportions for future usage
np.save(results_folder+'proportion.npy', cell_proportion)
np.savetxt(results_folder+'proportion.csv', adata_st.obs[type_list], delimiter = ',')

vmax = np.quantile(adata_st.obs[type_list].values, 0.98, axis=0)
vmax[vmax<0.05] = 0.05
with mpl.rc_context({'figure.figsize': [3, 5], 'figure.dpi': 400, 'xtick.labelsize': 0}):
    ax = sc.pl.spatial(adata_st, cmap='viridis', color=type_list, img_key='hires', vmin=0, vmax=list(vmax),
                       size=1.3, show=False, ncols=5, alpha_img=0.4)
    ax[0].get_figure().savefig(results_folder+'Spotiphy_deconvolution.jpg')

生活很好,有你更好
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值