10X Visium(55um)进行高分辨率降维分析

作者,Evil Genius

感受一下空间转录组精度分析上的变化

那么如何实现visium低精度实现高精度的数据分析呢?毕竟现在都是HD等高精度的天下了,分析也需要跟进。

10XVisium的空间分辨率仍然有限。每个ST spot通常包含多个细胞,并且测序spot没有覆盖大面积的组织。较新的技术,如Stereo-seq和Xenium,实现了更高的分辨率,但产生更稀疏和噪声数据。通常需要将spot聚合为较大的meta-spot,以提高信噪比,但不幸的是,这显著降低了空间分辨率。

ST 数据是高维的,并且通常表现出相当大的噪声和稀疏性,因此需要将其作为分析的关键步骤进行降维。由于传统的降维方法没有考虑空间信息,因此最近开发了专门适用于ST数据的方法。通过利用空间信息,这些方法可以生成具有空间感知的低维表示,更好地保留细胞或spot之间的空间关系。

ST 数据通常伴随着高分辨率的组织学图像,如苏木精-伊红(H&E)染色图像或免疫荧光图像,这些图像在更高的分辨率下提供了有关组织形态细胞组成和空间组织的有价值的信息。

基因表达 + 组织学图像进行高分辨率降维

更精确的嵌入和空间聚类,多方法比较

小鼠大脑数据集测试效果

更精细的空间结构

多样本的整合效果

CRC样本中的肿瘤异质性和免疫活性

示例代码,10X数据

###pip install SpaHDmap
import torch
import numpy as np
import scanpy as sc

import SpaHDmap as hdmap

rank = 20
seed = 123
verbose = True

np.random.seed(seed)
torch.manual_seed(seed)

root_path = '../experiments/'
project = 'MPBS01'

results_path = f'{root_path}/{project}/Results_Rank{rank}/'

radius = 45
scale_factor = 1

# Load the data (This data has been preprocessed, including normalization, swapping the coordinates and selecting SVGs)
mouse_posterior = hdmap.prepare_stdata(section_name='mouse_posterior',
                                       image_path='../data/MPBS01/HE.tif',
                                       spot_coord_path='../data/MPBS01/spot_coord.csv', # The coordinates must be in the first two columns
                                       spot_exp_path='../data/MPBS01/expression_nor.csv', # Has been normalized in this data
                                       scale_factor=scale_factor,
                                       radius=radius,
                                       swap_coord=False) # Has been swapped in the data
section_id = 'V1_Mouse_Brain_Sagittal_Posterior'

# Download the data from the 10X website (set include_hires_tiff=True to download the hires image)
adata = sc.datasets.visium_sge(section_id, include_hires_tiff=True)
image_path = adata.uns["spatial"][section_id]["metadata"]["source_image_path"]

# or load the data from a local folder
# adata = sc.read_visium(f'data/{section_id}')
# image_path = f'data/{section_id}/image.tif'

# Load the data from the 10X Visium folder
mouse_posterior = hdmap.prepare_stdata(adata=adata,
                                       section_name='mouse_posterior',
                                       image_path=image_path,
                                       scale_factor=scale_factor)

hdmap.select_svgs(mouse_posterior, n_top_genes=3000)

# Initialize the SpaHDmap runner
mapper = hdmap.Mapper(mouse_posterior, results_path=results_path, rank=rank, verbose=verbose)

# Run all steps in one function
mapper.run_SpaHDmap(save_score=False, save_model=True, visualize=True)

# Run NMF on concatenated data
mapper.get_NMF_score(save_score=False)

print(mouse_posterior.scores['NMF'].shape)

mapper.visualize(mouse_posterior, score='NMF', index=2)
# mapper.visualize('mouse_posterior', score='NMF', index=2) # visualize given the name
# mapper.visualize(score='NMF', index=2) # ignore the section name if only one section

# Save all NMF scores into `results_path/section_name/NMF`
mapper.visualize(score='NMF')
# Pre-train the SpaHDmap model via reconstructing the HE image
mapper.pretrain(save_model=True)
# Train the GCN model and get GCN score
mapper.get_GCN_score(save_score=False)

print(mouse_posterior.scores['GCN'].shape)
# Visualize the GCN score
mapper.visualize(mouse_posterior, score='GCN', index=2)

# Save all GCN scores into `results_path/section_name/GCN`
mapper.visualize(score='GCN')

# The refined metagene matrix based on the GCN score
print(mapper.metagene_GCN.shape)
# Get the VD score
mapper.get_VD_score(use_score='GCN')

# Train the SpaHDmap model
# If train_path is not empty, SpaHDmap will load the trained model from the train_path
mapper.train(save_model=True)

# Get the SpaHDmap score
mapper.get_SpaHDmap_score(save_score=False)

print(mouse_posterior.scores['SpaHDmap'].shape)

# Visualize the SpaHDmap score
mapper.visualize(mouse_posterior, score='SpaHDmap', index=2)

生活很好,有你更好

您好!对于您提供的代码段,它主要使用了Scanpy库来进行单细胞数据分析。下面是代码段的解释: 1. 导入所需的库: - `scanpy as sc`:导入Scanpy库并使用别名`sc`。 - `pandas as pd`:导入Pandas库并使用别名`pd`。 - `numpy as np`:导入NumPy库并使用别名`np`。 - `matplotlib.pyplot as plt`:导入Matplotlib库的Pyplot模块并使用别名`plt`。 - `seaborn as sns`:导入Seaborn库并使用别名`sns`。 2. 打印Scanpy和相关库的版本信息: - `sc.logging.print_versions()`:打印Scanpy和相关库的版本信息。 3. 设置图形参数: - `sc.set_figure_params(facecolor='white', figsize=(8,8))`:设置图形的背景颜色为白色,图形大小为8x8。 4. 设置Scanpy的日志输出级别: - `sc.settings.verbosity = 3`:将Scanpy的日志输出级别设置为3,以便显示详细的日志信息。 5. 下载数据集: - `adata = sc.datasets.visium_sge(sample_id="V1_Human_Lymph_Node")`:下载名为"V1_Human_Lymph_Node"的Visium数据集,并将其存储在名为`adata`的对象中。 6. 确保变量名称唯一: - `adata.var_names_make_unique()`:确保数据集中的变量名称是唯一的。 7. 计算质控指标: - `adata.var['mt'] = adata.var_names.str.startswith('MT-')`:为数据集中的变量添加一个名为'mt'的新列,该列表示变量名称是否以'MT-'开头。 - `sc.pp.calculate_qc_metrics(adata, qc_vars=['mt'], inplace=True)`:计算质控指标,并将结果保存在数据集的变量中。 希望以上解释对您有所帮助!如果您有任何其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值