关于 string-database-ppi
string-database-ppi 是通过 REST API 查询 STRING 蛋白质相互作用数据库的技能,面向分析蛋白质网络的研究者。它支持网络检索、功能富集、互作伙伴发现及跨物种同源分析。
主要功能
- 01将基因名称映射为 STRING ID
- 02检索功能或物理网络
- 03查找互作伙伴并扩展网络
- 04执行 GO、KEGG 等富集分析
- 05测试 PPI 富集并查询同源关系
适用场景
- 01根据蛋白质列表构建互作网络
- 02识别蛋白质集合中的富集功能
- 03从种子蛋白扩展网络
- 04比较不同物种的蛋白质互作
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ jaechang-hits/ sciagent-skills --skill string-database-ppi安装后在 Claude Code 中输入/string-database-ppi确认已加载。
附带文件references/api_advanced.md
详细介绍
STRING 数据库——蛋白质-蛋白质相互作用
概述
通过 REST API 查询 STRING 蛋白质-蛋白质相互作用数据库(5900 万种蛋白质、200 亿余种相互作用、5000 余个物种)。涵盖网络检索、功能富集分析(GO、KEGG、Pfam)、相互作用伙伴发现、PPI 富集检验、网络可视化和同源性分析。
适用场景
- 检索一个或多个蛋白质的蛋白质-蛋白质相互作用网络
- 对蛋白质列表进行功能富集分析(GO、KEGG、Pfam、InterPro)
- 发现相互作用伙伴,并从种子蛋白质扩展蛋白质网络
- 检验一组蛋白质是否构成显著富集的功能模块
- 使用基于证据的颜色生成网络可视化
- 分析不同物种间的同源性和蛋白质家族关系
- 识别枢纽蛋白质和网络连通性模式
- 化合物相互作用请使用 chembl-database-bioactivity;以通路为中心的查询请使用 kegg-database
先决条件
uv pip install requests pandas
速率限制:没有严格的速率限制,但 API 调用间隔应约为 1 秒。对于蛋白质组规模的分析,请使用 https://string-db.org/cgi/download 提供的批量下载,而非 API。
快速入门
import requests
import time
STRING_API = "https://string-db.org/api"
def string_query(endpoint, params, fmt="tsv"):
"""Reusable helper for all STRING API calls."""
url = f"{STRING_API}/{fmt}/{endpoint}"
params.setdefault("caller_identity", "python_script")
response = requests.get(url, params=params)
response.raise_for_status()
return response.text
# Map gene names to STRING IDs (always do this first)
result = string_query("get_string_ids", {
"identifiers": "TP53\nBRCA1\nEGFR",
"species": 9606
})
print(result)
# Get interaction network
time.sleep(1)
network = string_query("network", {
"identifiers": "TP53%0dBRCA1%0dMDM2",
"species": 9606,
"required_score": 400
})
print(network[:500])
核心概念
常见物种的 NCBI 分类 ID
| 生物体 | 常用名称 | 分类 ID |
|---|---|---|
| Homo sapiens | 人类 | 9606 |
| Mus musculus | 小鼠 | 10090 |
| Rattus norvegicus | 大鼠 | 10116 |
| Drosophila melanogaster | 果蝇 | 7227 |
| Caenorhabditis elegans | 秀丽隐杆线虫 | 6239 |
| Saccharomyces cerevisiae | 酵母 | 4932 |
| Arabidopsis thaliana | 拟南芥 | 3702 |
| Escherichia coli K-12 | 大肠杆菌 | 511145 |
| Danio rerio | 斑马鱼 | 7955 |
| Gallus gallus | 鸡 | 9031 |
完整物种列表:https://string-db.org/cgi/input?input_page_active_form=organisms
STRING 标识符格式
STRING 使用带分类前缀的 Ensembl 蛋白质 ID:{taxonId}.{ensemblProteinId}(例如,人类 TP53 的 ID 为 9606.ENSP00000269305)。请务必先通过 get_string_ids 将基因名称映射为 STRING ID,以加快后续查询。
相互作用置信度评分
综合评分(0-1000)整合了 7 个证据渠道:
| 渠道 | 代码 | 来源 |
|---|---|---|
| 邻域 | nscore | 保守的基因组邻域 |
| 融合 | fscore | 基因融合事件 |
| 系统发育谱 | pscore | 不同物种间的共现 |
| 共表达 | ascore | 相关的 RNA 表达 |
| 实验 | escore | 生化/遗传实验 |
| 数据库 | dscore | 经整理的通路/复合物数据库 |
| 文本挖掘 | tscore | 文献共现和自然语言处理 |
推荐阈值:
- 150:低置信度(探索性分析、生成假设)
- 400:中等置信度(标准分析、默认值)
- 700:高置信度(保守分析、更少假阳性)
- 900:最高置信度(非常严格,优先采用实验性证据)
网络类型
- 功能性(默认):包含所有证据类型——蛋白质之间存在功能关联,但不一定直接结合。适用于通路分析、富集分析和系统生物学
- 物理性:仅包含直接结合证据——实验数据和经整理的物理相互作用。适用于结构研究和复合物分析
输出格式
将 URL 中的 /tsv/ 替换为所需格式:
- TSV:制表符分隔(默认格式,最适合数据处理)
- JSON:结构化数据(
/json/) - PNG/SVG:网络图像(
/image/) - PSI-MI/PSI-MITAB:蛋白质组学标准格式
核心 API
1. 标识符映射
# Map gene names to STRING IDs
result = string_query("get_string_ids", {
"identifiers": "TP53\nBRCA1\nEGFR",
"species": 9606,
"limit": 1, # matches per identifier
"echo_query": 1 # include query term in output
})
# Parse the mapping
import pandas as pd
import io
df = pd.read_csv(io.StringIO(result), sep='\t')
id_map = dict(zip(df['queryItem'], df['stringId']))
print(id_map)
# {'TP53': '9606.ENSP00000269305', 'BRCA1': '9606.ENSP00000...', ...}
2. 网络检索
# Get PPI network with confidence scores
network = string_query("network", {
"identifiers": "TP53%0dBRCA1%0dMDM2%0dATM%0dCHEK2",
"species": 9606,
"required_score": 400,
"network_type": "functional" # or "physical"
})
# Parse network edges
time.sleep(1)
df = pd.read_csv(io.StringIO(network), sep='\t')
print(f"Found {len(df)} interactions")
print(df[['preferredName_A', 'preferredName_B', 'score']].head())
# Expand network with additional interactors
expanded = string_query("network", {
"identifiers": "TP53",
"species": 9606,
"add_nodes": 10, # add 10 most connected proteins
"required_score": 700
})
3. 网络可视化
# Get PNG network image
url = f"{STRING_API}/image/network"
params = {
"identifiers": "TP53%0dMDM2%0dATM%0dCHEK2%0dBRCA1",
"species": 9606,
"required_score": 700,
"network_flavor": "evidence", # "evidence", "confidence", or "actions"
"caller_identity": "python_script"
}
response = requests.get(url, params=params)
with open("network.png", "wb") as f:
f.write(response.content)
4. 相互作用伙伴
# Discover top interaction partners
partners = string_query("interaction_partners", {
"identifiers": "TP53",
"species": 9606,
"limit": 20,
"required_score": 700
})
df = pd.read_csv(io.StringIO(partners), sep='\t')
print(f"Top 20 TP53 interactors:")
print(df[['preferredName_B', 'score']].head(10))
5. 功能富集分析
# GO, KEGG, Pfam, InterPro, SMART, UniProt Keywords enrichment
# Statistical method: Fisher's exact test with Benjamini-Hochberg FDR correction
enrichment = string_query("enrichment", {
"identifiers": "TP53%0dMDM2%0dATM%0dCHEK2%0dBRCA1%0dATR%0dTP73",
"species": 9606
})
df = pd.read_csv(io.StringIO(enrichment), sep='\t')
significant = df[df['fdr'] < 0.05]
print(f"Significant terms: {len(significant)}")
# Group by annotation category
for cat, group in significant.groupby('category'):
print(f"\n{cat}: {len(group)} terms")
for _, row in group.head(3).iterrows():
print(f" {row['description']} (FDR={row['fdr']:.2e})")
6. PPI 富集检验
import json
# Test if proteins form a significant functional module
result = string_query("ppi_enrichment", {
"identifiers": "TP53%0dMDM2%0dATM%0dCHEK2%0dBRCA1",
"species": 9606,
"required_score": 400
}, fmt="json")
data = json.loads(result)
print(f"Observed edges: {data['number_of_edges']}")
print(f"Expected edges: {data['expected_number_of_edges']}")
print(f"P-value: {data['p_value']}")
# p < 0.05 → proteins form a significantly enriched network
7. 同源性评分
# Get homology/similarity between proteins
homology = string_query("homology", {
"identifiers": "TP53%0dTP63%0dTP73",
"species": 9606
})
print(homology)
常见工作流
工作流 1:蛋白质列表分析(标准)
import requests, pandas as pd, io, json, time
STRING_API = "https://string-db.org/api"
def string_query(endpoint, params, fmt="tsv"):
url = f"{STRING_API}/{fmt}/{endpoint}"
params.setdefault("caller_identity", "python_script")
response = requests.get(url, params=params)
response.raise_for_status()
time.sleep(1)
return response.text
genes = "TP53%0dBRCA1%0dATM%0dCHEK2%0dMDM2%0dATR%0dBRCA2"
# Step 1: Map identifiers
mapping = string_query("get_string_ids", {"identifiers": genes.replace("%0d", "\n"), "species": 9606})
# Step 2: Get interaction network
network = string_query("network", {"identifiers": genes, "species": 9606, "required_score": 400})
net_df = pd.read_csv(io.StringIO(network), sep='\t')
print(f"Network: {len(net_df)} interactions")
# Step 3: Test PPI enrichment
ppi = json.loads(string_query("ppi_enrichment", {"identifiers": genes, "species": 9606}, fmt="json"))
print(f"PPI enrichment p-value: {ppi['p_value']}")
# Step 4: Functional enrichment
enrich = string_query("enrichment", {"identifiers": genes, "species": 9606})
enrich_df = pd.read_csv(io.StringIO(enrich), sep='\t')
sig = enrich_df[enrich_df['fdr'] < 0.05]
print(f"Significant GO/KEGG terms: {len(sig)}")
# Step 5: Save network image
img_resp = requests.get(f"{STRING_API}/image/network", params={
"identifiers": genes, "species": 9606, "required_score": 400,
"network_flavor": "evidence", "caller_identity": "python_script"
})
with open("protein_network.png", "wb") as f:
f.write(img_resp.content)
工作流 2:从种子蛋白扩展网络
# Start with seed proteins, discover connected functional modules
seed = "TP53"
# Step 1: Get high-confidence interaction partners
partners = string_query("interaction_partners", {
"identifiers": seed, "species": 9606, "limit": 30, "required_score": 700
})
df = pd.read_csv(io.StringIO(partners), sep='\t')
all_proteins = list(set(df['preferredName_A'].tolist() + df['preferredName_B'].tolist()))
print(f"Expanded network: {len(all_proteins)} proteins")
# Step 2: Enrichment on expanded set
expanded_ids = "%0d".join(all_proteins[:50])
enrichment = string_query("enrichment", {"identifiers": expanded_ids, "species": 9606})
enrich_df = pd.read_csv(io.StringIO(enrichment), sep='\t')
modules = enrich_df[enrich_df['fdr'] < 0.001]
print(f"Highly significant terms: {len(modules)}")
工作流 3:跨物种比较
# Compare protein interactions across species
for species, name, gene in [(9606, "Human", "TP53"), (10090, "Mouse", "Trp53")]:
network = string_query("network", {
"identifiers": gene, "species": species,
"required_score": 700, "add_nodes": 5
})
df = pd.read_csv(io.StringIO(network), sep='\t')
print(f"{name} ({gene}): {len(df)} interactions at score >= 700")
常用配方
配方:将富集结果解析为 DataFrame
import pandas as pd, io
enrichment_tsv = string_query("enrichment", {
"identifiers": "TP53%0dBRCA1%0dATM", "species": 9606
})
df = pd.read_csv(io.StringIO(enrichment_tsv), sep='\t')
# Columns: category, term, description, number_of_genes, p_value, fdr
kegg = df[df['category'] == 'KEGG'].sort_values('fdr')
print(kegg[['description', 'fdr']].head(5))
配方:使用速率限制批量查询蛋白质
import time
protein_lists = [["TP53", "MDM2"], ["EGFR", "ERBB2"], ["BRCA1", "BRCA2"]]
results = []
for proteins in protein_lists:
ids = "%0d".join(proteins)
network = string_query("network", {"identifiers": ids, "species": 9606})
results.append(network)
time.sleep(1) # respect rate limits
配方:为确保可复现性检查版本
version = string_query("version", {})
print(f"STRING version: {version.strip()}")
# Include in methods section: "STRING v{version}, accessed {date}"
关键参数
| 参数 | 端点 | 默认值 | 描述 |
|---|---|---|---|
identifiers | 所有 | — | 蛋白质 ID;URL 中以 %0d 分隔,POST 中以 \n 分隔 |
species | 所有 | — | NCBI 分类群 ID(9606=人类,10090=小鼠) |
required_score | network、partners、ppi_enrichment | 400 | 置信度阈值,范围为 0-1000 |
network_type | network | functional | functional(所有证据)或 physical(直接结合) |
add_nodes | network、image | 0 | 要纳入的额外相连蛋白质数量(0-10) |
limit | get_string_ids、partners | 1/10 | 每次查询的最大结果数 |
network_flavor | image | evidence | evidence、confidence 或 actions |
故障排除
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 未找到蛋白质 | 物种错误或标识符拼写错误 | 验证物种分类群 ID;使用 get_string_ids 检查标识符映射 |
| 网络为空 | 置信度阈值过严 | 降低 required_score;确认蛋白质确实在 STRING 中存在相互作用 |
| 大型查询超时 | 单次请求中的蛋白质过多 | 拆分为每批 50-100 个;对于蛋白质组规模的查询,使用批量下载 |
| 出现“Species required”错误 | 蛋白质数量超过 10 个的网络缺少物种信息 | 始终包含 species 参数 |
| 结果异常 | 网络类型或 STRING 版本错误 | 检查 network_type(functional 与 physical);使用 /version 验证版本 |
| 400 Bad Request | 标识符格式错误 | 在 URL 中使用 %0d 分隔符,或在 POST 正文中使用 \n;对特殊字符进行 URL 编码 |
| 富集结果没有术语 | 输入的蛋白质过少 | 富集分析需要至少 5 个蛋白质才能获得有意义的结果 |
最佳实践
- 始终先映射标识符 —— 在其他操作之前使用
get_string_ids();STRING ID(例如9606.ENSP00000269305)比基因名称更快 - 限制所有请求的速率 —— 在 API 调用之间添加
time.sleep(1) - 选择适当的阈值 —— 探索性分析使用 400,发表研究使用 700,仅使用高置信度结果时使用 900
- 明确指定物种 —— 对于蛋白质数量超过 10 个的网络,这是必需的;始终指定则更佳
- 通路分析和富集分析使用功能网络;结构生物学和直接结合分析使用物理网络
- 在方法部分注明版本 —— 检查
string_version()以确保可复现性
相关技能
networkx-graph-analysis— STRING 相互作用网络的图分析与可视化kegg-database— 与 STRING 富集分析互补的通路导向查询bioservices-multi-database— 通过 PSICQUIC 接口访问 STRING 的替代方式
参考资料
- STRING 网站:https://string-db.org
- API 文档:https://string-db.org/help/api/
- 下载页面:https://string-db.org/cgi/download
- 出版物:https://string-db.org/cgi/about
捆绑资源
主 SKILL.md + 1 个参考文件。原始总计:990 行(SKILL.md 534 行 + string_reference.md 456 行)。脚本:370 行(string_api.py)。
references/api_advanced.md:高级 API 功能(值/排名丰富化、批量上传、R/Cytoscape 集成)、输出格式详情、HTTP 错误代码、数据许可协议 — 内容来自超出核心 API 范围的原始 string_reference.md。
原始文件处理方式:
SKILL.md(534 行)→ 核心 API 模块 1–7、工作流 1–3、快速入门辅助函数、关键概念(物种表、评分阈值、网络类型)。根据规则 7b,将“常见用例”中的各操作子章节整合到核心 API 模块说明中:每项操作的“适用时机”和“用例”→ 核心 API 介绍文本。“详细参考”占位章节 → 删除,内容整合到相应位置references/string_reference.md(456 行)→ 部分内容整合到相应位置:API 端点 → 核心 API 模块及代码块;物种表 → 关键概念;置信度评分 → 关键概念;标识符格式 → 关键概念。高级功能(值/排名丰富化、批量上传)、集成示例(R STRINGdb、Cytoscape)、输出格式详情、HTTP 错误代码、数据许可协议 → 移至references/api_advanced.mdscripts/string_api.py(370 行)→ 将辅助函数模式整合到快速入门中的可复用string_query函数。各函数的处理方式:string_map_ids→ 核心 API 模块 1;string_network→ 模块 2;string_network_image→ 模块 3;string_interaction_partners→ 模块 4;string_enrichment→ 模块 5;string_ppi_enrichment→ 模块 6;string_homology→ 模块 7;string_version→ 配方。它们原本都是基于 urllib 的轻量封装;现已替换为基于 requests 的string_query辅助函数
保留内容:约 460 行(SKILL.md)+ 约 180 行(参考文件)= 原始 990 行中的约 640 行,即约 65%。