Communitygithub.com

deepspot-m

从 H&E 组织学图像生成全转录组虚拟空间转录组数据。当你需要以 log1p-CPM 格式获取 224x224 切片(约 20 倍放大)的空间基因表达,希望按符号查询蛋白编码基因而非固定基因面板,或在切片分块后使用 histolab 进行全切片预测时,请使用本工具。

deepspot-m 是什么?

DeepSpot-M 是一个多模态基础模型,能够将 224x224 大小的 H&E 组织学切片映射为 log1p-CPM 格式的空间基因表达数据,输出为虚拟空间转录组结果:每个查询基因在每个切片中有一个对应值,并按切片来源网格排列。该模型使用 LoRA 适配的病理基础骨干网络 (Midnight) 对切片进行标记化,并通过交叉注意力基因解码器让每个基因查询关注切片标记,同时使用基因路由器超网络从冻结的生物学嵌入 (Evo 2, Orthrus, ProtT5, scGPT, Apertus) 构建基因特异性投影。基因以可查询嵌入而非固定输出槽的形式输入模型,因此发布版本覆盖约 19,000 个蛋白编码基因面板,包括训练中未见过的基因。该模型支持 Python 3.10 至 3.13,需通过 PyTorch 进行 GPU 推理,权重存储在 Hugging Face 上需请求访问。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/skills/deepspot-m

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

deepspot-m 是做什么的?

概述

DeepSpot-M 是一个多模态基础模型,能够将 224x224 大小的 H&E 组织学切片映射为 log1p-CPM 格式的空间基因表达。输出结果为虚拟空间转录组:每个查询基因在每个切片中有一个对应值,并按切片来源网格排列。

该模型使用 LoRA 适配的病理基础骨干网络 (Midnight) 对切片进行标记化。交叉注意力基因解码器让每个基因查询关注切片标记,而基因路由器超网络从冻结的生物学嵌入 (Evo 2, Orthrus, ProtT5, scGPT, Apertus) 构建基因特异性投影。基因以可查询嵌入而非固定输出槽的形式输入模型,因此发布版本覆盖约 19,000 个蛋白编码基因面板,包括训练中未见过的基因。该面板随权重一起作为 tokens.csv 发布,并暴露为 model.gene_names;此发布版本中无法查询面板之外的基因。

应用于 TCGA 数据集时,该模型生成了涵盖 32 种癌症类型、共 28,664 张切片的虚拟空间转录组图谱。

许可

代码采用 PolyForm Noncommercial 1.0.0 许可,权重采用 CC-BY-NC-SA-4.0 许可。仅限非商业研究使用,在重新分发输出前请检查两个许可证。

安装

uv pip install deepspotm==1.0.0

1.0.0 版本支持 Python 3.10 至 3.13,并依赖 PyTorch。如果你希望使用 GPU 推理,请先安装与 CUDA 版本匹配的 PyTorch 构建版本。

模型访问

权重需要申请访问:

  1. 打开 https://huggingface.co/ratschlab/DeepSpotM 并请求访问权限。
  2. 获得访问权限后,在需要下载权重的机器上进行身份验证:
huggingface-cli login

from_pretrained 会读取缓存的令牌,因此每台机器只需登录一次。

快速开始

from deepspotm import DeepSpotM

model, image_processor = DeepSpotM.from_pretrained("ratschlab/DeepSpotM", source="scgpt")

vals = model.predict_genes(image_processor(pil_tile).unsqueeze(0), ["EPCAM", "CD3D"])

pil_tile 是一个尺寸严格为 224x224 像素的 PIL 图像。image_processor 将其转换为张量,unsqueeze(0) 添加批次维度,predict_genes 接收批次和 HGNC 基因符号列表。返回值以 log1p-CPM 格式呈现,与传入的基因列表对齐,因此请保留该列表以便于标记输出列。符号必须在发布的约 19,000 个基因面板内 (model.gene_names);未知符号会抛出 KeyError 并指明违规基因。

切片要求

切片必须为 224x224 的 RGB 图像,放大倍数约为 20 倍(约 0.5 微米每像素)。请在管线的边界检查尺寸,而不是直接传入未检查的裁剪结果:

TILE_PX = 224

def require_tile(tile):
    """返回 RGB 224x224 切片,如果裁剪尺寸错误则抛出异常。"""
    if tile.size != (TILE_PX, TILE_PX):
        raise ValueError(
            f"DeepSpot-M 期望 {TILE_PX}x{TILE_PX} 的切片(约 20 倍放大,"
            f"~0.5 微米每像素);实际收到 {tile.size[0]}x{tile.size[1]}。"
            "请在与 0.5 微米每像素最接近的层级进行重新分块,或对裁剪结果进行重采样。"
        )
    return tile.convert("RGB")

在切片级别中提取分辨率最接近 0.5 微米每像素的切片,然后裁剪至 224x224。从较粗层级进行重采样会改变骨干网络读取的纹理。

将依赖项保持为可选

deepspotm 及其权重是较重且受控的依赖项。将其导入放在需要使用它的函数内部,这样周围的项目可以在没有它的情况下安装、导入和测试,并将 ImportError 转换为说明所有步骤的消息:

DEEPSPOTM_HELP = (
    "DeepSpot-M 不可用。请使用 `uv pip install deepspotm==1.0.0` 安装,"
    "在 https://huggingface.co/ratschlab/DeepSpotM 请求访问受控权重,"
    "然后使用 `huggingface-cli login` 进行身份验证。"
)

def load_deepspotm(source="scgpt"):
    try:
        from deepspotm import DeepSpotM
    except ImportError as exc:
        raise RuntimeError(DEEPSPOTM_HELP) from exc
    return DeepSpotM.from_pretrained("ratschlab/DeepSpotM", source=source)

嵌入来源

source 参数选择路由器用于构建投影的冻结基因嵌入。共有五个可选值:

source基因嵌入
evo2基因组序列
orthrusRNA
prott5蛋白质序列
scgpt单细胞表达
apertus语言模型

每种来源提供不同的基因身份视角。每次运行选择一个来源,当选择对你的分析至关重要时,可使用多个来源对相同切片运行。请参阅 references/api.md 获取完整的调用接口、批处理和设备放置、基因符号处理以及输出单位。

全切片工作流程

预测是基于切片的,因此全切片运行需要先进行分块,然后进行批量推理:

  1. 使用 histolab 技能在网格上提取 224x224 切片,并保留每个切片的坐标。
  2. 使用 torch.stack 处理和堆叠切片成批次。
  3. 每批次调用一次 predict_genes,传入相同的基因列表。
  4. 将所有批次拼接成一个切片 × 基因的矩阵,并附加坐标。

该矩阵即为切片的虚拟空间转录组图谱,可直接导入 AnnData 进行下游空间分析。references/whole_slide.md 提供了详细的工作循环、批大小设置以及 AnnData 组装步骤。

常见用例

  • 肿瘤切片中标记基因的空间表达图谱。
  • 在没有匹配实验数据的情况下,对整个切片队列进行全转录组预测。
  • 按符号查询约 19,000 个面板基因中的任意一个,包括训练中未见过的基因——远超典型空间实验面板的几百个基因。
  • 为仅包含形态学的组织学管线添加表达通道。
  • 构建切片级别的队列图谱,如针对 TCGA 所做的研究。

详细参考

  • references/api.md:from_pretrained 和 predict_genes 的完整说明、五种嵌入来源及选择方法、批处理、设备放置、基因符号处理以及 log1p-CPM 输出转换。
  • references/whole_slide.md:使用 histolab 分块、全切片预测循环、切片 × 基因矩阵的组装和存储,以及队列级别运行。

主要来源

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

adaptyv

How to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.

aeon

This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

alphagenome

Look up precomputed AlphaGenome Atlas effects for any GRCh38 single-nucleotide variant (AVI score with Phred and 18 SHAP feature attributions, plus raw and quantile scores for RNA-seq, DNase, ATAC, ChIP-TF, ChIP-histone, CAGE, PRO-cap, splicing, polyadenylation and contact-map tracks), score variants or scan windows on demand with the AlphaGenome model for human and mouse (variant scoring, in silico mutagenesis, REF-versus-ALT track prediction), and build Atlas website deep links. Use when the user mentions AlphaGenome, AlphaGenome Atlas, AVI or AlphaGenome Variant Impact, DeepMind variant effect prediction, or wants to prioritise or mechanistically interpret non-coding, regulatory, splicing, enhancer, promoter, or chromatin-accessibility effects of SNVs from a VCF, credible set, or region. Research use only; not a clinical tool.

analytical-method-validation

Plan, execute, and document validation, verification, and transfer of analytical procedures under the governing framework - ICH Q2(R2) and Q14, USP <1220>/<1225>/<1226>, ICH M10 bioanalytical, CLSI EP, or ISO/IEC 17025. Use for HPLC, LC-MS/MS, GC, CE, ICP-MS, dissolution, qNMR, qPCR, NIR, and ligand binding or cell-based assays whenever the question is whether a procedure is fit for its intended purpose. Triggers include

anndata

Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.

arbor

Autonomously improve a real artifact (code, training recipe, agent harness, data pipeline, prompt) against an objective and an evaluator, using Hypothesis Tree Refinement (HTR) from the Arbor paper. Use this whenever someone wants to iteratively optimize something over many experiments without overfitting — e.g.

arboreto

Infer gene regulatory networks (GRNs) from gene expression data using scalable algorithms (GRNBoost2, GENIE3). Use when analyzing transcriptomics data (bulk RNA-seq, single-cell RNA-seq) to identify transcription factor-target gene relationships and regulatory interactions. Supports distributed computation for large-scale datasets.

astropy

Core Python library for astronomy and astrophysics workflows that need Astropy APIs, including units/quantities, coordinates, FITS I/O, tables, time systems, WCS, and cosmology. Use when implementing or debugging astronomical data analysis code with Astropy.

autoskill

Observe the user

benchling-integration

Benchling Python SDK and REST API integration for registry entities, inventory, ELN entries, workflows, Benchling Apps, and Data Warehouse queries. Use when automating lab data with benchling-sdk or the v2 API.

bgpt-paper-search

Search scientific papers and retrieve structured experimental data extracted from full-text studies via the BGPT MCP server. Returns 25+ fields per paper including methods, results, sample sizes, quality scores, and conclusions. Use for literature reviews, evidence synthesis, and finding experimental details not available in abstracts alone.

bids

>

biopython

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.

bioservices

Unified Python interface to 40+ bioinformatics services. Use when querying multiple databases (UniProt, KEGG, ChEMBL, Reactome) in a single workflow with consistent API. Best for cross-database analysis, ID mapping across services. For quick single-database lookups use gget; for sequence/file manipulation use biopython.

bulk-rnaseq

End-to-end bulk RNA-seq orchestrator — takes raw FASTQ reads through QC and trimming (FastQC, fastp/Trim Galore), alignment and quantification (STAR, Salmon, featureCounts), assembles a gene-level counts matrix, then hands off to differential expression (pydeseq2), pathway/GSEA enrichment (pathway-enrichment), and publication figures (scientific-visualization). Use whenever the user has bulk RNA-seq reads or quant output and wants a complete, reproducible differential-expression workflow — e.g.

cellxgene-census

Query the CZ CELLxGENE Census programmatically for versioned public single-cell and spatial transcriptomics data. Use when you need population-scale cell metadata, gene expression slices, Census summary counts, source H5AD URIs/downloads, embeddings, spatial Census data, or reference atlas comparisons across organisms, tissues, diseases, assays, and cell types. For analyzing your own local single-cell data use scanpy, anndata, or scvi-tools.

cirq

Google quantum computing framework. Use when targeting Google Quantum AI hardware, designing noise-aware circuits, or running quantum characterization experiments. Best for Google hardware, noise modeling, and low-level circuit design. For IBM hardware use qiskit; for quantum ML with autodiff use pennylane; for physics simulations use qutip.

citation-management

Comprehensive citation management for academic research. Search OpenAlex, PubMed, and Google Scholar for papers, extract accurate metadata, validate citations, and generate properly formatted BibTeX entries. This skill should be used when you need to find papers, verify citation information, convert DOIs to BibTeX, or ensure reference accuracy in scientific writing.

clinical-decision-support

Prepare and validate research-only clinical decision-support evaluation, evidence-profile, cohort, survival, biomarker/model, privacy, and governance artifacts. Use for aggregate or synthetic research documentation and traceability—not patient care or live clinical operation.

clinical-reports

Create safety-bounded draft structures and run local deterministic checks for clinical case, diagnostic, trial, safety, and aggregate research reports. Use only with synthetic, de-identified, or aggregate inputs and verified source-fact manifests; every output requires qualified review.

相关技能