STARmap3D_VISp
[1]:
import warnings
warnings.filterwarnings("ignore")
import MENDER
import scanpy as sc
import pandas as pd
import numpy as np
from sklearn.metrics import *
import time
[2]:
## load the data using pysodb, please install pysodb in advance [https://pysodb.readthedocs.io/en/latest/]
import pysodb
sodb = pysodb.SODB()
adata_raw = sodb.load_experiment('Wang2018three','data_3D')
load experiment[data_3D] in dataset[Wang2018three]
[3]:
adata_raw.obsm['spatial'] = adata_raw.obs[['x','y','z']].values
[4]:
adata_raw.var_names_make_unique()
adata_raw.layers["counts"] = adata_raw.X.copy()
sc.pp.highly_variable_genes(adata_raw, flavor="seurat_v3", n_top_genes=4000)
sc.pp.normalize_total(adata_raw)
sc.pp.pca(adata_raw)
sc.pp.neighbors(adata_raw)
sc.tl.umap(adata_raw)
sc.tl.leiden(adata_raw,key_added='ct',resolution=2)
[5]:
adata = adata_raw.copy()
[6]:
# input parameters of MENDER
scale = 6
# 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'
)
msm.estimate_radius()
estimated radius: 8.06225774829855
[7]:
# 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
# this para in 3D might be smaller than 2D
nn_para=7,
)
# 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)
scale 0, median #cells per radius (r=7): 1.0
scale 1, median #cells per radius (r=7): 1.0
scale 2, median #cells per radius (r=7): 4.0
scale 3, median #cells per radius (r=7): 7.0
scale 4, median #cells per radius (r=7): 12.0
scale 5, median #cells per radius (r=7): 16.0
[8]:
msm.output_cluster('MENDER')
[9]:
msm.adata_MENDER.write_h5ad('dump/STARmap3D.h5ad')
[ ]: