ST data deconvolution and spot annotation
If using an external R installation (may not be necessary on Linux systems).
import os
os.environ['R_HOME'] = 'C:/Program Files/R/R-4.4.1'
import the packages
import os
import sys
import cytobulk as ct
import scanpy as sc
import pandas as pd
import warnings
warnings.filterwarnings("ignore")
Load scRNA-seq and ST data
Load the mouse mob reference single cell data, e.g. GSE121891 [Download data]. and ST data from Stahl, Patrik L., et al.[Download data].
sc_adata = sc.read_h5ad(r"C:/Users/wangxueying/project/CytoBulk/case/mouse_mob/mouse_mob_input/sc_layer_mob.h5ad")
st_adata = sc.read_h5ad(r"C:/Users/wangxueying/project/CytoBulk/case/mouse_mob/mouse_mob_input/st_mob.h5ad")
Deconvolute ST data with sc-RNA seq as the reference.
If you want to use the pretrained model, please download the folder, extract it, and set the path of the extracted folder as the out_dir parameter. [Download] This will help you skip the training steps.
deconv_result,deconv_adata = ct.tl.st_deconv(st_adata = st_adata,
sc_adata = sc_adata,
annotation_key ="subtype",
out_dir="C:/Users/wangxueying/project/CytoBulk/case/MOB_layer",
dataset_name="MOB_layer",
different_source=True,
n_cell=15)
deconv_result.head(5)
Visualization of spot annotation results
ct.plots.celltype_fraction_pie(adata=deconv_adata,
scale_facter_x=5,
scale_factor_y=5,
out_dir="C:/Users/wangxueying/project/CytoBulk/case/MOB_layer",
rotation_angle=225)
ct.plots.celltype_fraction_heatmap(adata=deconv_adata,
label='OSN',
out_dir="C:/Users/wangxueying/project/CytoBulk/case/MOB_layer",
rotation_angle=225)
ct.plots.paired_violin(adata=deconv_adata,
label='OSN',
gene='Kctd12',
out_dir="C:/Users/wangxueying/project/CytoBulk/case/mouse_mob_1/output/output")