作者,Evil Genius
我们高精度空间转录组也迎来了结尾了,这一篇我们总结一下空间邻域通讯分析了。
我们还是以王凌华的文章为例
前面的空精度空转(Xenium、CosMx)等的基础分析,细胞注释,RCN、邻域、亚群区分我们都做完整,就来到亚群的空间邻域通讯。


邻域通讯分析的方法写的也比较简单

cellphoneDB、Cellchat、iTALK全部用上了(其实就是把所有的配受体库都放进来看看)。
但是大家看文章不知道注意到没有,文章分析的时候不仅分析配受体,也要分析如下内容,各个CAF邻域细胞的差异表达


其实真正项目分析的时候,空间邻域的通讯分析与空间依赖基因,英文是neighbor-dependent genes.
核心就是分析细胞间相互作用和邻域依赖基因表达,结合配受体数据库(如CellPhoneDB)可以更全面地解析细胞间通讯机制。
我们来简单更新一下这部分代码,当然了,大家现在要更多的采用大panel的高精度空间转录组产品了。
#! usr/bin/python
####zhaoyunfei
####20250411
import scanpy as sc
import pandas as pd
import CellNeighborEX
import os
from cellphonedb.src.core.methods import cpdb_statistical_analysis_method
adata = sc.read("scimap.xenium.h5ad")
df = CellNeighborEX.neighbors.create_dataframe(adata, coord_key='spatial', celltype_key='subtype')
closest_distances = CellNeighborEX.neighbors.calculate_closest_distance(df, save=True)
# Find immediate neighbors using Delaunay triangulation and retrieve the spatial connectivity matrix.
matrix = CellNeighborEX.neighbors.detect_neighbors(adata, coord_key='spatial', type='generic', knn=None, radius_value=None, delaunay=True)
# Calculate the number of neighbors for each cell.
neiNum = CellNeighborEX.neighbors.get_neighbors(matrix)
df_processed = CellNeighborEX.neighbors.process_dataframe(df, matrix, neiNum, save=True)
# All categorzied files (index_, matchComb_, neiCombUnique_, prop_ .csv) are saved in the "categorized_data folder" in the root directory.
CellNeighborEX.categorization.generate_input_files(data_type = "Image", df = df_processed, sample_size=30, min_sample_size=1)
# Normalize gene expression data.
barcodes = df_processed['barcode'].tolist()
adata = adata[barcodes, :]
sc.pp.normalize_total(adata, target_sum=1e4) # normlization
sc.pp.log1p(adata)
# Save the data into dataframes.
index_name = adata.obs.index.name
df_cell_id = pd.DataFrame(adata.obs.index)
df_cell_id = df_cell_id.rename(columns={index_name: 0})
var_name = adata.var.index.name
df_gene_name = pd.DataFrame(adata.var.index)
df_gene_name = df_gene_name.rename(columns={var_name: 0})
df_log_data = adata.T.to_df()
###Perform neighbor-dependent gene expression analysis
data_type = "Image" # Image: image-based ST data, NGS: NGS-based ST data
lrCutoff = 0.4
pCutoff = 0.01
pCutoff2 = 0.05
direction = 'up'
normality_test = False
top_genes = 30
path_categorization = './categorized_data/'
DEG_list = CellNeighborEX.DEanalysis.analyze_data(df_cell_id, df_gene_name, df_log_data, path_categorization, data_type, lrCutoff, pCutoff, pCutoff2, direction, normality_test, top_genes, save=True)
生活很好,有你更好