


# 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# 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

results
# 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",
)

# 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",
)

# 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 删除。