Agent skill
single2spatial-spatial-mapping
Map scRNA-seq atlases onto spatial transcriptomics slides using omicverse's Single2Spatial workflow for deep-forest training, spot-level assessment, and marker visualisation.
Install this agent skill to your Project
npx add-skill https://github.com/FreedomIntelligence/OpenClaw-Medical-Skills/tree/main/skills/single-to-spatial-mapping
SKILL.md
Single2Spatial spatial mapping
Overview
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.
Instructions
- Import dependencies and style
- Load
omicverse as ov,scanpy as sc,anndata,pandas as pd,numpy as np, andmatplotlib.pyplot as plt. - Call
ov.utils.ov_plot_set()(orov.plot_set()in older versions) to align plots with omicverse styling.
- Load
- Load single-cell and spatial datasets
- Read processed matrices with
pd.read_csv(...)then create AnnData objects (anndata.AnnData(raw_df.T)). - Attach metadata:
single_data.obs = pd.read_csv(...)[['Cell_type']]andspatial_data.obs = pd.read_csv(... )containing coordinates and slide metadata.
- Read processed matrices with
- Initialise Single2Spatial
- Instantiate
ov.bulk2single.Single2Spatial(single_data=single_data, spatial_data=spatial_data, celltype_key='Cell_type', spot_key=['xcoord','ycoord'], gpu=0). - Note that inputs should be normalised/log-scaled scRNA-seq matrices; ensure
spot_keymatches spatial coordinate columns.
- Instantiate
- Train the deep-forest model
- Execute
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). - Explain that
spot_numdefines sampled pseudo-spots per iteration andcell_numcontrols per-spot cell draws.
- Execute
- Load pretrained weights
- Use
st_model.load(modelsize=14478, df_load_dir='.../pdac_df.pth', k=10, predicted_size=32)when checkpoints already exist to skip training.
- Use
- Assess spot-level outputs
- Call
st_model.spot_assess()to compute aggregated spot AnnData (sp_adata_spot) for QC. - Plot marker genes with
sc.pl.embedding(sp_adata, basis='X_spatial', color=['REG1A', 'CLDN1', ...], frameon=False, ncols=4).
- Call
- Visualise proportions and cell-type maps
- Use
sc.pl.embedding(sp_adata_spot, basis='X_spatial', color=['Acinar cells', ...], frameon=False)to highlight per-spot cell fractions. - Plot
sp_adatacoloured byCell_typewithpalette=ov.utils.ov_palette()[11:]to show reconstructed assignments.
- Use
- Export results
- Encourage saving generated AnnData objects (
sp_adata.write_h5ad(...),sp_adata_spot.write_h5ad(...)) and derived CSV summaries for downstream reporting.
- Encourage saving generated AnnData objects (
- Troubleshooting tips
- If training diverges, reduce
learning_ratevia keyword arguments or decreasepredicted_sizeto stabilise the forest. - Ensure scRNA-seq inputs are log-normalised; raw counts can lead to scale mismatches and poor spatial predictions.
- Verify GPU availability when
gpuis non-zero; fallback to CPU by omitting the argument or settinggpu=-1.
- If training diverges, reduce
Examples
- "Train Single2Spatial on PDAC scRNA-seq and Visium slides, then visualise REG1A and CLDN1 spatial expression."
- "Load a saved Single2Spatial checkpoint to regenerate spot-level cell-type proportions for reporting."
- "Plot reconstructed cell-type maps with omicverse palettes to compare against histology."
References
- Tutorial notebook:
t_single2spatial.ipynb - Example datasets and models:
omicverse_guide/docs/Tutorials-bulk2single/data/pdac/ - Quick copy/paste commands:
reference.md
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
vcf-annotator
Annotate VCF variants with VEP, ClinVar, gnomAD frequencies, and ancestry-aware context. Generates prioritised variant reports.
chemist-analyst
Analyzes events through chemistry lens using molecular structure, reaction mechanisms, thermodynamics, kinetics, and analytical techniques (spectroscopy, chromatography, mass spectrometry). Provides insights on chemical processes, material properties, reaction pathways, synthesis, and analytical methods. Use when: Chemical reactions, material analysis, synthesis planning, process optimization, environmental chemistry. Evaluates: Molecular structure, reaction mechanisms, yield, selectivity, safety, environmental impact.
bio-alignment-io
Read, write, and convert multiple sequence alignment files using Biopython Bio.AlignIO. Supports Clustal, PHYLIP, Stockholm, FASTA, Nexus, and other alignment formats for phylogenetics and conservation analysis. Use when reading, writing, or converting alignment file formats.
sleep-analyzer
分析睡眠数据、识别睡眠模式、评估睡眠质量,并提供个性化睡眠改善建议。支持与其他健康数据的关联分析。
metabolomics-workbench-database
Access NIH Metabolomics Workbench via REST API (4,200+ studies). Query metabolites, RefMet nomenclature, MS/NMR data, m/z searches, study metadata, for metabolomics and biomarker discovery.
bio-hi-c-analysis-matrix-operations
Balance, normalize, and transform Hi-C contact matrices using cooler and cooltools. Apply iterative correction (ICE), compute expected values, and generate observed/expected matrices. Use when normalizing or transforming Hi-C matrices.
Didn't find tool you were looking for?