首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >脚本更新---高精度空转(Xenium、CosMx)Patch Proximity Analysis

脚本更新---高精度空转(Xenium、CosMx)Patch Proximity Analysis

原创
作者头像
追风少年i
发布2025-12-09 10:17:15
发布2025-12-09 10:17:15
1720
举报

作者,Evil Genius

周一了,小伙伴们,我们来更新一下脚本吧。

这个分析就是依据邻域范围分析空间结构

我们来分享一下

代码语言:javascript
复制
# import spacec
import spacec as sp

#import standard packages
import os
import scanpy as sc

# silencing warnings
import warnings
warnings.filterwarnings('ignore')

sc.settings.set_figure_params(dpi=80, facecolor='white')
# Specify the path to the data
root_path = "/home/user/path/SPACEc/" # inset your own path

data_path = root_path + 'example_data/raw/' # where the data is stored

# where you want to store the output
output_dir = root_path + 'example_data/output/'
os.makedirs(output_dir, exist_ok=True)

# read in the annotated anndata
adata = sc.read(output_dir + 'adata_nn_demo_annotated_cn.h5ad')
adata

邻近细胞计算

这个还是之前提到的两种策略:第一种方法“border_cell_radius”会识别勾勒凹包轮廓的细胞及其最近邻细胞,随后以这些细胞为中心、按指定半径绘制圆形区域,以检测空间上邻近的细胞,同时忽略属于同一斑块的细胞。此方法能生成高度精确的边界,但计算强度通常高于“hull_expansion”方法。此外,“border_cell_radius”方法对内部边界高度敏感:若半径范围覆盖斑块内部孔洞,该方法可有效识别这些孔洞结构。

代码语言:javascript
复制
# this region result is also saved to adata.uns
results, outlines_results = sp.tl.patch_proximity_analysis(
    adata, # the annotated adata object
    region_column = "unique_region", # column with the region information
    patch_column = "CN_k20_n6_annot", # column with the patch information (derive patches from this column)
    group="Germinal Center", # group to consider
    min_cluster_size=50, # minimum cluster size to consider
    x_column='x', y_column='y', # spatial coordinates
    radius = [20, 40, 60, 80, 100], # to get the distance in µm
    edge_neighbours = 1, # number of neighbours to consider for edge detection if set to 1 only the hull is considered
    plot = True, # plot the results for demonstration and/or documentation (set to False to skip plotting - improves speed)
    original_unit_scale = 1.96656, # scale factor for the units (1 = 1px per unit e.g. µm)
    method= "border_cell_radius", # method to use for the edge detection
    key_name = "ppa_result_20_40_60_80_100_border_cell_radius", # key name to store the result in adata.uns
    save_geojson = False, # save the results as geojson
    ) # plot detection for demonstration purposes

##Processing reg002_Germinal Center
##Estimated number of clusters: 4
##Estimated number of noise points: 7
代码语言:javascript
复制
results

可视化

代码语言:javascript
复制
# Donut plots for cell types around Germinal Center
sp.pl.ppa_res_donut(
    adata,
    cat_col = 'cell_type',
    key_name="ppa_result_20_40_60_80_100_border_cell_radius",
    palette=None,
    distance_mode="within",  # "within" or "between"
    unit="µm",
    figsize=(10, 10),
    add_guides=True,
    text="Cell types around Germinal Center",
    label_color="black",
    group_by= 'condition',
    title="PPA",
)
代码语言:javascript
复制
# Donut plots for cell types around Germinal Center
sp.pl.ppa_res_donut(
    adata,
    cat_col = 'cell_type',
    key_name="ppa_result_20_40_60_80_100_border_cell_radius",
    palette=None,
    distance_mode="between",  # "within" or "between"
    unit="µm",
    figsize=(10, 10),
    add_guides=True,
    text="Cell types around Germinal Center",
    label_color="black",
    group_by= 'condition',
    title="PPA",
)
代码语言:javascript
复制
# Donut plots for cell types around Germinal Center
sp.pl.ppa_res_donut(
    adata,
    cat_col = 'CN_k20_n6_annot',
    key_name="ppa_result_20_40_60_80_100_border_cell_radius",
    palette=None,
    distance_mode="within",  # "within" or "between"
    unit="µm",
    figsize=(10, 10),
    add_guides=True,
    text="Cell types around Germinal Center",
    label_color="black",
    group_by= 'condition',
    title="PPA",
)

生活很好,有你更好

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 作者,Evil Genius
  • 周一了,小伙伴们,我们来更新一下脚本吧。
  • 这个分析就是依据邻域范围分析空间结构
  • 我们来分享一下
  • 邻近细胞计算
  • 这个还是之前提到的两种策略:第一种方法“border_cell_radius”会识别勾勒凹包轮廓的细胞及其最近邻细胞,随后以这些细胞为中心、按指定半径绘制圆形区域,以检测空间上邻近的细胞,同时忽略属于同一斑块的细胞。此方法能生成高度精确的边界,但计算强度通常高于“hull_expansion”方法。此外,“border_cell_radius”方法对内部边界高度敏感:若半径范围覆盖斑块内部孔洞,该方法可有效识别这些孔洞结构。
  • 可视化
  • 生活很好,有你更好
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档