OpenClaw-Medical-Skills 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
source · Clone the upstream repo
git clone https://github.com/FreedomIntelligence/OpenClaw-Medical-Skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/FreedomIntelligence/OpenClaw-Medical-Skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/single-to-spatial-mapping" ~/.claude/skills/freedomintelligence-openclaw-medical-skills-single2spatial-spatial-mapping && rm -rf "$T"
OpenClaw · Install into ~/.openclaw/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/FreedomIntelligence/OpenClaw-Medical-Skills "$T" && mkdir -p ~/.openclaw/skills && cp -r "$T/skills/single-to-spatial-mapping" ~/.openclaw/skills/freedomintelligence-openclaw-medical-skills-single2spatial-spatial-mapping && rm -rf "$T"
manifest:
skills/single-to-spatial-mapping/SKILL.mdtags
source content
Single2Spatial spatial mapping
Overview
Apply this skill when converting single-cell references into spatially resolved profiles. It follows
, demonstrating how Single2Spatial trains on PDAC scRNA-seq and Visium data, reconstructs spot-level proportions, and visualises marker expression.t_single2spatial.ipynb
Instructions
- Import dependencies and style
- Load
,omicverse as ov
,scanpy as sc
,anndata
,pandas as pd
, andnumpy as np
.matplotlib.pyplot as plt - Call
(orov.utils.ov_plot_set()
in older versions) to align plots with omicverse styling.ov.plot_set()
- Load
- Load single-cell and spatial datasets
- Read processed matrices with
then create AnnData objects (pd.read_csv(...)
).anndata.AnnData(raw_df.T) - Attach metadata:
andsingle_data.obs = pd.read_csv(...)[['Cell_type']]
containing coordinates and slide metadata.spatial_data.obs = pd.read_csv(... )
- 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
matches spatial coordinate columns.spot_key
- Instantiate
- Train the deep-forest model
- Execute
to fit the mapper and generate reconstructed spatial AnnData (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)
).sp_adata - Explain that
defines sampled pseudo-spots per iteration andspot_num
controls per-spot cell draws.cell_num
- Execute
- Load pretrained weights
- Use
when checkpoints already exist to skip training.st_model.load(modelsize=14478, df_load_dir='.../pdac_df.pth', k=10, predicted_size=32)
- Use
- Assess spot-level outputs
- Call
to compute aggregated spot AnnData (st_model.spot_assess()
) for QC.sp_adata_spot - 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
to highlight per-spot cell fractions.sc.pl.embedding(sp_adata_spot, basis='X_spatial', color=['Acinar cells', ...], frameon=False) - Plot
coloured bysp_adata
withCell_type
to show reconstructed assignments.palette=ov.utils.ov_palette()[11:]
- Use
- Export results
- Encourage saving generated AnnData objects (
,sp_adata.write_h5ad(...)
) and derived CSV summaries for downstream reporting.sp_adata_spot.write_h5ad(...)
- Encourage saving generated AnnData objects (
- Troubleshooting tips
- If training diverges, reduce
via keyword arguments or decreaselearning_rate
to stabilise the forest.predicted_size - Ensure scRNA-seq inputs are log-normalised; raw counts can lead to scale mismatches and poor spatial predictions.
- Verify GPU availability when
is non-zero; fallback to CPU by omitting the argument or settinggpu
.gpu=-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