← 返回知识库

Transformer推断基因调控网络

基因调控网络 Transformer 因果推断 更新时间:2025-01-15

什么是基因调控网络(GRN)

基因调控网络描述了转录因子(TF)如何调控靶基因的表达,是理解细胞命运决定、疾病机制的核心。 传统GRN推断方法(如GENIE3、SCENIC)依赖于相关性分析,但面临以下挑战:

为什么Transformer适合GRN推断

核心优势:

代表性方法:GeneFormer

GeneFormer是首个基于Transformer的单细胞基础模型,通过在3000万个单细胞样本上预训练, 学习到了基因组范围的调控语法。其GRN推断能力来自于对注意力权重的解析。

工作流程

# 1. 安装GeneFormer
git clone https://huggingface.co/ctheodoris/Geneformer
cd Geneformer
pip install -e .

# 2. 准备数据(需转换为rank-value编码)
from geneformer import TranscriptomeTokenizer

tk = TranscriptomeTokenizer(
    custom_attr_name_dict={"cell_type": "celltype"},
    nproc=4
)
tk.tokenize_data(
    data_directory="data/",
    output_directory="data/tokenized/",
    output_prefix="dataset"
)

# 3. 加载预训练模型
from transformers import BertForMaskedLM, BertConfig

model = BertForMaskedLM.from_pretrained(
    "ctheodoris/Geneformer",
    output_attentions=True
)

# 4. 提取注意力矩阵推断GRN
from geneformer import InSilicoPerturber

perturber = InSilicoPerturber(
    model_type="Pretrained",
    num_classes=0,
    emb_mode="cell",
    cell_states_to_model={"state_key": "celltype", "states": "fibroblast"},
    max_ncells=1000
)

# 5. 扰动分析:敲除某个TF,观察下游基因变化
perturbation_results = perturber.perturb_data(
    model_directory="ctheodoris/Geneformer",
    input_data_file="data/tokenized/dataset.dataset",
    output_directory="results/",
    perturb_type="delete",
    perturb_rank_shift=None,
    genes_to_perturb=["SOX9", "RUNX2"]  # 扰动这些TF
)

其他Transformer-based工具

实战案例:推断成纤维细胞衰老GRN

import scanpy as sc
import pyscenic

# 方法1:传统SCENIC流程(作为对照)
adata = sc.read_h5ad('fibroblast_aging.h5ad')
lf = pyscenic.run_scenic(
    adata,
    tfs_file='resources/hs_tfs.txt',
    motif_anno='resources/motifs-v10nr_clust.hg38.feather'
)

# 方法2:使用GeneFormer进行扰动分析
# (代码同上,设置cell_states_to_model为衰老相关状态)

# 比较两种方法识别的关键调控因子
scenic_tfs = set(lf.keys())
geneformer_tfs = set(perturbation_results['top_regulators'])
common_tfs = scenic_tfs & geneformer_tfs  # 取交集验证

解释注意力矩阵

Transformer的注意力权重可以直接解释为基因-基因的调控强度:

# 提取注意力权重
attentions = model(input_ids, output_attentions=True).attentions

# 平均所有层和所有头的注意力
avg_attention = torch.mean(torch.stack(attentions), dim=(0, 1))

# 构建GRN邻接矩阵
import networkx as nx
G = nx.DiGraph()
gene_names = tokenizer.gene_list

for i, tf in enumerate(gene_names):
    for j, target in enumerate(gene_names):
        weight = avg_attention[i, j].item()
        if weight > threshold:  # 设定阈值过滤弱连接
            G.add_edge(tf, target, weight=weight)

# 可视化
nx.draw_spring(G, with_labels=True, node_color='lightblue')

验证GRN的真实性

  1. ChIP-seq验证:比对预测的TF-靶基因对与ChIP-seq结合峰
  2. 扰动实验:使用CRISPR-Cas9敲除预测的关键TF,检测下游基因表达变化
  3. 已知通路富集:检查推断的网络是否富集已知调控模块(如KEGG、GO)
  4. 跨数据集验证:在独立数据集上测试GRN的可复现性

未来方向

当前GRN推断的前沿是整合多模态数据(scRNA-seq + scATAC-seq + Hi-C), 利用Transformer学习从DNA序列到染色质开放性再到基因表达的完整调控级联。 代表性工作包括Enformer、Sei等,这些模型正在向"从基因组预测表型"的终极目标迈进。

相关资源


© 2025 知识库 | 返回首页