Spatial Transcriptomics Mapper (ID: 196)
When to Use
- - Use this skill when the task is to Map spatial transcriptomics data from 10x Genomics Visium/Xenium onto.
- Use this skill for data analysis tasks that require explicit assumptions, bounded scope, and a reproducible output format.
- Use this skill when you need a documented fallback path for missing inputs, execution errors, or partial evidence.
Key Features
See ## Features above for related details.
- - Scope-focused workflow aligned to: Map spatial transcriptomics data from 10x Genomics Visium/Xenium onto.
- Packaged executable path(s):
scripts/__init__.py plus 1 additional script(s). - Structured execution path designed to keep outputs consistent and reviewable.
Dependencies
See ## Prerequisites above for related details.
- -
Python: 3.10+. Repository baseline for current packaged skills. - INLINECODE5 :
unspecified. Declared in requirements.txt. - INLINECODE8 :
unspecified. Declared in requirements.txt. - INLINECODE11 :
unspecified. Declared in requirements.txt. - INLINECODE14 :
unspecified. Declared in requirements.txt. - INLINECODE17 :
unspecified. Declared in requirements.txt. - INLINECODE20 :
unspecified. Declared in requirements.txt. - INLINECODE23 :
unspecified. Declared in requirements.txt. - INLINECODE26 :
unspecified. Declared in requirements.txt. - INLINECODE29 :
unspecified. Declared in requirements.txt. - INLINECODE32 :
unspecified. Declared in requirements.txt.
Example Usage
See ## Usage above for related details.
CODEBLOCK0
Example run plan:
- 1. Confirm the user input, output path, and any required config values.
- Edit the in-file
CONFIG block or documented parameters if the script uses fixed settings. - Run
python scripts/main.py with the validated inputs. - Review the generated output and return the final artifact with any assumptions called out.
Implementation Details
See ## Workflow above for related details.
- - Execution model: validate the request, choose the packaged workflow, and produce a bounded deliverable.
- Input controls: confirm the source files, scope limits, output format, and acceptance criteria before running any script.
- Primary implementation surface:
scripts/__init__.py with additional helper scripts under scripts/. - Parameters to clarify first: input path, output path, scope filters, thresholds, and any domain-specific constraints.
- Output discipline: keep results reproducible, identify assumptions explicitly, and avoid undocumented side effects.
Quick Check
Use this command to verify that the packaged script entry point can be parsed before deeper execution.
CODEBLOCK1
Audit-Ready Commands
Use these concrete commands for validation. They are intentionally self-contained and avoid placeholder paths.
CODEBLOCK2
Workflow
- 1. Confirm the user objective, required inputs, and non-negotiable constraints before doing detailed work.
- Validate that the request matches the documented scope and stop early if the task would require unsupported assumptions.
- Use the packaged script path or the documented reasoning path with only the inputs that are actually available.
- Return a structured result that separates assumptions, deliverables, risks, and unresolved items.
- If execution fails or inputs are incomplete, switch to the fallback path and state exactly what blocked full completion.
Description
Spatial Transcriptomics analysis tool for processing 10x Genomics Visium or Xenium data, projecting gene expression data back onto tissue section images to draw "gene-space" distribution maps. Supports gene expression visualization, spatial clustering analysis, and morphological feature correlation.
Features
- - Visium Data Processing: Supports Space Ranger output (filteredfeaturebcmatrix.h5, spatial/tissuepositionslist.csv, spatial/tissuelowresimage.png)
- Xenium Data Processing: Supports Xenium Explorer output (.h5, transcripts.parquet, nucleusboundaries.parquet)
- Gene Expression Mapping: Projects expression of specified genes onto tissue images
- Spatial Clustering Visualization: Displays spatial distribution of Seurat/Scanpy clustering results
- Multi-gene Joint Analysis: Supports combined visualization of multiple genes
- High-resolution Output: Supports high-resolution image export
Installation
CODEBLOCK3
Quick Start - Test Data
Generate sample Visium data to test the tool:
CODEBLOCK4
Usage
Basic - Visium Data
CODEBLOCK5
Basic - Xenium Data
CODEBLOCK6
Multiple Genes
CODEBLOCK7
With Clustering Results
CODEBLOCK8
Input File Structure
Visium (Space Ranger output)
CODEBLOCK9
Xenium
CODEBLOCK10
Output Files
- -
{gene}_spatial_map.png: Single gene spatial expression map - INLINECODE42 : Gene expression heatmap
- INLINECODE43 : Multi-gene overlay map (if using --mode overlay)
- INLINECODE44 : Cluster spatial distribution map
- INLINECODE45 : Comprehensive HTML report
Parameters
| Parameter | Type | Default | Description |
|---|
| INLINECODE46 | str | required | Platform type: visium or xenium |
| INLINECODE47 |
str | required | Data directory path |
|
--gene | str | optional | Single gene name |
|
--genes | list | optional | Multiple genes, comma-separated |
|
--mode | str | single | Mode: single/overlay/multi |
|
--cluster-file | str | optional | Clustering result CSV file path |
|
--output | str | ./output | Output directory |
|
--dpi | int | 300 | Output image DPI |
|
--cmap | str | viridis | Color map scheme |
|
--spot-size | float | 1.0 | Visium spot size factor |
|
--alpha | float | 0.8 | Transparency (0-1) |
|
--min-count | int | 0 | Minimum expression filter |
| --crop | str | optional | Crop region (x1,y1,x2,y2) |
Examples
Example 1: Single Gene Visualization
CODEBLOCK11
Example 2: Tumor Marker Combination
CODEBLOCK12
Example 3: Xenium Subcellular Resolution
CODEBLOCK13
Example 4: Spatial Clustering Visualization
CODEBLOCK14
API Usage
CODEBLOCK15
Notes
- - Visium data uses low-resolution images by default to improve processing speed, can use --hires parameter to enable high resolution
- For large Xenium datasets, it is recommended to use --crop parameter to specify region of interest
- Color map reference: https://matplotlib.org/stable/tutorials/colors/colormaps.html
- For large samples, consider using --downsample parameter to reduce resolution
References
- - 10x Genomics Visium: https://www.10xgenomics.com/products/spatial-gene-expression
- 10x Genomics Xenium: https://www.10xgenomics.com/platforms/xenium
- Scanpy: https://scanpy.readthedocs.io/
- Squidpy: https://squidpy.readthedocs.io/
Risk Assessment
| Risk Indicator | Assessment | Level |
|---|
| Code Execution | Python/R scripts executed locally | Medium |
| Network Access |
No external API calls | Low |
| File System Access | Read input files, write output files | Medium |
| Instruction Tampering | Standard prompt guidelines | Low |
| Data Exposure | Output files saved to workspace | Low |
Security Checklist
- - [ ] No hardcoded credentials or API keys
- [ ] No unauthorized file system access (../)
- [ ] Output does not expose sensitive information
- [ ] Prompt injection protections in place
- [ ] Input file paths validated (no ../ traversal)
- [ ] Output directory restricted to workspace
- [ ] Script execution in sandboxed environment
- [ ] Error messages sanitized (no stack traces exposed)
- [ ] Dependencies audited
Prerequisites
CODEBLOCK16
Evaluation Criteria
Success Metrics
- - [ ] Successfully executes main functionality
- [ ] Output meets quality standards
- [ ] Handles edge cases gracefully
- [ ] Performance is acceptable
Test Cases
- 1. Basic Functionality: Standard input → Expected output
- Edge Case: Invalid input → Graceful error handling
- Performance: Large dataset → Acceptable processing time
Lifecycle Status
- - Current Stage: Draft
- Next Review Date: 2026-03-06
- Known Issues: None
- Planned Improvements:
- Performance optimization
- Additional feature support
Output Requirements
Every final response should make these items explicit when they are relevant:
- - Objective or requested deliverable
- Inputs used and assumptions introduced
- Workflow or decision path
- Core result, recommendation, or artifact
- Constraints, risks, caveats, or validation needs
- Unresolved items and next-step checks
Error Handling
- - If required inputs are missing, state exactly which fields are missing and request only the minimum additional information.
- If the task goes outside the documented scope, stop instead of guessing or silently widening the assignment.
- If
scripts/main.py fails, report the failure point, summarize what still can be completed safely, and provide a manual fallback. - Do not fabricate files, citations, data, search results, or execution outcomes.
Input Validation
This skill accepts requests that match the documented purpose of spatial-transcriptomics-mapper and include enough context to complete the workflow safely.
Do not continue the workflow when the request is out of scope, missing a critical input, or would require unsupported assumptions. Instead respond:
INLINECODE60 only handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.
Response Template
Use the following fixed structure for non-trivial requests:
- 1. Objective
- Inputs Received
- Assumptions
- Workflow
- Deliverable
- Risks and Limits
- Next Checks
If the request is simple, you may compress the structure, but still keep assumptions and limits explicit when they affect correctness.
空间转录组映射器(ID: 196)
使用时机
- - 当任务需要将10x Genomics Visium/Xenium的空间转录组数据进行映射时使用此技能。
- 用于需要明确假设、限定范围以及可重复输出格式的数据分析任务。
- 当需要针对缺失输入、执行错误或部分证据提供有文档记录的备用路径时使用此技能。
关键特性
相关详情请参见上方## 特性部分。
- - 以范围为核心的工作流程,对齐目标:将10x Genomics Visium/Xenium的空间转录组数据进行映射。
- 打包的可执行路径:scripts/init.py 外加1个附加脚本。
- 结构化执行路径,旨在保持输出的一致性和可审查性。
依赖项
相关详情请参见上方## 前提条件部分。
- - Python:3.10+。当前打包技能的基础仓库版本。
- h5py:未指定版本。在requirements.txt中声明。
- matplotlib:未指定版本。在requirements.txt中声明。
- numpy:未指定版本。在requirements.txt中声明。
- pandas:未指定版本。在requirements.txt中声明。
- pil:未指定版本。在requirements.txt中声明。
- pyarrow:未指定版本。在requirements.txt中声明。
- scanpy:未指定版本。在requirements.txt中声明。
- seaborn:未指定版本。在requirements.txt中声明。
- squidpy:未指定版本。在requirements.txt中声明。
- tifffile:未指定版本。在requirements.txt中声明。
使用示例
相关详情请参见上方## 用法部分。
bash
cd 20260318/scientific-skills/Data Analytics/spatial-transcriptomics-mapper
python -m py_compile scripts/main.py
python scripts/main.py --help
示例运行计划:
- 1. 确认用户输入、输出路径以及任何必需的配置值。
- 如果脚本使用固定设置,编辑文件内的CONFIG块或文档化参数。
- 使用验证后的输入运行python scripts/main.py。
- 审查生成的输出,并返回最终产物,同时注明所有假设。
实现细节
相关详情请参见上方## 工作流程部分。
- - 执行模型:验证请求,选择打包的工作流程,并生成一个限定范围的可交付成果。
- 输入控制:在运行任何脚本之前,确认源文件、范围限制、输出格式和验收标准。
- 主要实现界面:scripts/init.py,以及scripts/目录下的其他辅助脚本。
- 需优先明确的参数:输入路径、输出路径、范围过滤器、阈值以及任何领域特定的约束条件。
- 输出规范:保持结果可重复,明确标识假设,避免未记录的副作用。
快速检查
在深入执行之前,使用此命令验证打包脚本入口点是否可解析。
bash
python -m py_compile scripts/main.py
审计就绪命令
使用这些具体命令进行验证。它们特意设计为自包含,避免使用占位符路径。
bash
python -m py_compile scripts/main.py
python scripts/main.py --help
工作流程
- 1. 在进行详细工作之前,确认用户目标、所需输入以及不可协商的约束条件。
- 验证请求是否与文档记录的范围匹配,如果任务需要不支持的假设,则尽早停止。
- 仅使用实际可用的输入,使用打包的脚本路径或文档化的推理路径。
- 返回一个结构化结果,将假设、可交付成果、风险和未解决事项分开。
- 如果执行失败或输入不完整,切换到备用路径,并明确说明阻止完整完成的具体原因。
描述
用于处理10x Genomics Visium或Xenium数据的空间转录组分析工具,将基因表达数据投影回组织切片图像,绘制基因-空间分布图。支持基因表达可视化、空间聚类分析和形态特征相关性分析。
特性
- - Visium数据处理:支持Space Ranger输出(filteredfeaturebcmatrix.h5、spatial/tissuepositionslist.csv、spatial/tissuelowresimage.png)
- Xenium数据处理:支持Xenium Explorer输出(.h5、transcripts.parquet、nucleusboundaries.parquet)
- 基因表达映射:将指定基因的表达量投影到组织图像上
- 空间聚类可视化:显示Seurat/Scanpy聚类结果的空间分布
- 多基因联合分析:支持多个基因的联合可视化
- 高分辨率输出:支持高分辨率图像导出
安装
text
必需依赖
pip install scanpy squidpy matplotlib seaborn pillow numpy pandas h5py
可选:用于Xenium数据处理
pip install pyarrow dask
可选:用于高级图像处理
pip install opencv-python scikit-image
快速入门 - 测试数据
生成示例Visium数据以测试工具:
text
生成测试数据
python scripts/generate
testdata.py \
--platform visium \
--output ./test
data/visiumsample \
--n-spots 500 \
--n-genes 1000
对测试数据运行分析
python scripts/main.py \
--platform visium \
--data-dir ./test
data/visiumsample \
--gene GENE_0000 \
--output ./test_output/
用法
基础 - Visium数据
text
python scripts/main.py \
--platform visium \
--data-dir /path/to/spaceranger/outs/ \
--gene PIK3CA \
--output ./output/
基础 - Xenium数据
text
python scripts/main.py \
--platform xenium \
--data-dir /path/to/xenium/outs/ \
--gene PIK3CA \
--output ./output/
多个基因
text
python scripts/main.py \
--platform visium \
--data-dir /path/to/data/ \
--genes PIK3CA,PTEN,EGFR \
--mode overlay \
--output ./output/
带聚类结果
text
python scripts/main.py \
--platform visium \
--data-dir /path/to/data/ \
--cluster-file ./clusters.csv \
--output ./output/
输入文件结构
Visium(Space Ranger输出)
outs/
├── filteredfeaturebc_matrix.h5 # 基因表达矩阵
├── rawfeaturebc_matrix.h5 # 原始计数(可选)
├── spatial/
│ ├── tissuepositionslist.csv # 斑点位置
│ ├── tissuelowresimage.png # 低分辨率H&E图像
│ ├── tissuehiresimage.png # 高分辨率H&E图像
│ └── scalefactors_json.json # 缩放因子
└── web_summary.html
Xenium
outs/
├── cellfeaturematrix.h5 # 细胞×基因矩阵
├── transcripts.parquet # 转录本坐标
├── nucleus_boundaries.parquet # 细胞核边界
├── cell_boundaries.parquet
├── morphology_focus.ome.tif # 形态学图像
└── experiment.xenium
输出文件
- - {gene}spatialmap.png:单基因空间表达图
- {gene}heatmap.png:基因表达热图
- multigeneoverlay.png:多基因叠加图(如果使用--mode overlay)
- clusterspatialmap.png:聚类空间分布图
- combinedreport.html:综合HTML报告
参数
| 参数 | 类型 | 默认值 | 描述 |
|---|
| --platform | str | 必需 | 平台类型:visium 或 xenium |
| --data-dir |
str | 必需 | 数据目录路径 |
| --gene | str | 可选 | 单个基因名称 |
| --genes | list | 可选 | 多个基因,逗号分隔 |
| --mode | str | single | 模式:single/overlay/multi |
| --cluster-file | str | 可选 | 聚类结果CSV文件路径 |
| --output | str | ./output | 输出目录 |
| --dpi | int | 300 | 输出图像DPI |
| --cmap | str | viridis | 颜色映射方案 |
| --spot-size | float | 1.0 | Visium斑点大小因子 |
| --alpha | float | 0.8 | 透明度(0-1) |
| --min-count | int | 0 | 最小表达