ST_MOB

[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('stahl2016visualization','Rep4_MOB_trans')

load experiment[Rep4_MOB_trans] in dataset[stahl2016visualization]
[4]:






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') adata.obs['ct'] = adata.obs['ct'].astype('category') ######### determine cell state using standard Leiden [end] #########





WARNING: adata.X seems to be already log-transformed.
[5]:
# input parameters of MENDER
scale = 3

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


# 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'
    # for spot data, nn_mode is set to 'ring', since each spot is surrounded by certain number of spots (6 for visium and 4 for ST)

    nn_mode='ring',

    # default of n_scales is 15 um (see the manuscript for why).
    # MENDER also provide a function 'estimate_radius' for estimating the radius
    # if nn_mode is set to 'ring', nn_para means the number of spots around the central spot, i.e., 6 for Visium and 4 for ST

    nn_para=4,

)
# 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 ring (r=4): 5.0
scale 1, median #cells per ring (r=4): 7.5
scale 2, median #cells per ring (r=4): 10.0
[6]:
msm.output_cluster('MENDER')
_images/ST_MOB_5_0.png
[7]:
msm.adata_MENDER.write_h5ad('dump/ST_MOB.h5ad')


[ ]: