# input parameters of MENDER
scale = 6
# the raduis was estimated by msm.estimate_radius()
radius = 300
# record running time
time_st = time.time()
adata = adata_raw.copy()
######### determine cell state using standard Leiden [start] #########
# this step can be optionally skipped if reliable cell type annotation is available
sc.pp.highly_variable_genes(adata, flavor="seurat_v3", n_top_genes=4000)
sc.pp.normalize_total(adata, inplace=True)
sc.pp.log1p(adata)
sc.pp.pca(adata)
sc.pp.neighbors(adata)
sc.tl.leiden(adata,resolution=2,key_added='ct',random_state=666)
adata.obs['ct'] = adata.obs['ct'].astype('category')
######### determine cell state using standard Leiden [end] #########
# main body of MENDER
msm = MENDER.MENDER_single(
adata,
# determine which cell state to use
# we use the cell state got by Leiden
ct_obs='ct',
random_seed=666
)
# set the MENDER parameters
msm.set_MENDER_para(
# default of n_scales is 6
n_scales=scale,
# for single cell data, nn_mode is set to 'radius'
nn_mode='radius',
# default of n_scales is 15 um (see the manuscript for why).
# MENDER also provide a function 'estimate_radius' for estimating the radius
nn_para=radius,
)
# construct the context representation
msm.run_representation(
# the number of processings
)
# set the spatial clustering parameter
# positive values for the expected number of domains
# negative values for the clustering resolution
msm.run_clustering_normal(-0.5)
time_ed = time.time()
time_cost = time_ed-time_st