Map scRNA-seq atlases onto spatial transcriptomics slides using omicverse's Single2Spatial workflow for deep-forest training, spot-level assessment, and marker visualisation.
Apply this skill when converting single-cell references into spatially resolved profiles. It follows t_single2spatial.ipynb, demonstrating how Single2Spatial trains on PDAC scRNA-seq and Visium data, reconstructs spot-level proportions, and visualises marker expression.
omicverse as ov, scanpy as sc, anndata, pandas as pd, numpy as np, and matplotlib.pyplot as plt.ov.utils.ov_plot_set() (or ov.plot_set() in older versions) to align plots with omicverse styling.pd.read_csv(...)anndata.AnnData(raw_df.T)single_data.obs = pd.read_csv(...)[['Cell_type']] and spatial_data.obs = pd.read_csv(... ) containing coordinates and slide metadata.ov.bulk2single.Single2Spatial(single_data=single_data, spatial_data=spatial_data, celltype_key='Cell_type', spot_key=['xcoord','ycoord'], gpu=0).spot_key matches spatial coordinate columns.st_model.train(spot_num=500, cell_num=10, df_save_dir='...', df_save_name='pdac_df', k=10, num_epochs=1000, batch_size=1000, predicted_size=32) to fit the mapper and generate reconstructed spatial AnnData (sp_adata).spot_num defines sampled pseudo-spots per iteration and cell_num controls per-spot cell draws.st_model.load(modelsize=14478, df_load_dir='.../pdac_df.pth', k=10, predicted_size=32) when checkpoints already exist to skip training.st_model.spot_assess() to compute aggregated spot AnnData (sp_adata_spot) for QC.sc.pl.embedding(sp_adata, basis='X_spatial', color=['REG1A', 'CLDN1', ...], frameon=False, ncols=4).sc.pl.embedding(sp_adata_spot, basis='X_spatial', color=['Acinar cells', ...], frameon=False) to highlight per-spot cell fractions.sp_adata coloured by Cell_type with palette=ov.utils.ov_palette()[11:] to show reconstructed assignments.sp_adata.write_h5ad(...), sp_adata_spot.write_h5ad(...)) and derived CSV summaries for downstream reporting.learning_rate via keyword arguments or decrease predicted_size to stabilise the forest.gpu is non-zero; fallback to CPU by omitting the argument or setting gpu=-1.t_single2spatial.ipynbomicverse_guide/docs/Tutorials-bulk2single/data/pdac/reference.md