mcpField
A
alphafold-database

alphafold-database

github.com/davila7数据与数据库33.0k326 次安装今天更新
代码仓库

关于 alphafold-database

AlphaFold Database 是 AI 预测蛋白质结构的公共数据库,此技能介绍数据检索与分析流程。它面向研究人员和计算生物学从业者,提供结构文件、置信度指标及批量蛋白质组数据访问方式。

主要功能

  1. 01按 UniProt ID 检索预测
  2. 02下载 mmCIF 和 PDB 文件
  3. 03查看 pLDDT 与 PAE 置信数据
  4. 04访问批量蛋白质组数据
  5. 05使用 Biopython 解析结构
  6. 06批量处理蛋白质预测

适用场景

  1. 01获取缺少实验模型的蛋白质结构
  2. 02评估预测结构置信度
  3. 03下载蛋白质组规模的预测数据
  4. 04为药物发现研究准备结构

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/davila7/claude-code-templates --skill alphafold-database

安装后在 Claude Code 中输入/alphafold-database确认已加载。

附带文件references/api_reference.md

详细介绍

AlphaFold 数据库

概述

AlphaFold DB 是一个公开的数据库,收录了由 AI 预测的、超过 2 亿个蛋白质的 3D 结构,由 DeepMind 和 EMBL-EBI 维护。可访问带有置信度指标的结构预测,下载坐标文件,获取批量数据集,并将预测结果集成到计算工作流中。

何时使用本 Skill

本 Skill 应在处理 AI 预测的蛋白质结构的场景中使用,例如:

  • 按 UniProt ID 或蛋白质名称检索蛋白质结构预测
  • 下载 PDB/mmCIF 坐标文件以进行结构分析
  • 分析预测置信度指标(pLDDT、PAE)以评估可靠性
  • 通过 Google Cloud Platform 访问批量蛋白质组数据集
  • 将预测结构与实验数据进行比较
  • 进行基于结构的药物发现或蛋白质工程
  • 为缺乏实验结构的蛋白质构建结构模型
  • 将 AlphaFold 预测集成到计算流程中

核心能力

1. 搜索和检索预测

使用 Biopython(推荐):

Biopython 库提供了检索 AlphaFold 结构的最简单接口:

from Bio.PDB import alphafold_db

# Get all predictions for a UniProt accession
predictions = list(alphafold_db.get_predictions("P00520"))

# Download structure file (mmCIF format)
for prediction in predictions:
    cif_file = alphafold_db.download_cif_for(prediction, directory="./structures")
    print(f"Downloaded: {cif_file}")

# Get Structure objects directly
from Bio.PDB import MMCIFParser
structures = list(alphafold_db.get_structural_models_for("P00520"))

直接访问 API:

使用 REST 端点查询预测:

import requests

# Get prediction metadata for a UniProt accession
uniprot_id = "P00520"
api_url = f"https://alphafold.ebi.ac.uk/api/prediction/{uniprot_id}"
response = requests.get(api_url)
prediction_data = response.json()

# Extract AlphaFold ID
alphafold_id = prediction_data[0]['entryId']
print(f"AlphaFold ID: {alphafold_id}")

使用 UniProt 查找登录号:

先搜索 UniProt 以找到蛋白质登录号:

import urllib.parse, urllib.request

def get_uniprot_ids(query, query_type='PDB_ID'):
    """Query UniProt to get accession IDs"""
    url = 'https://www.uniprot.org/uploadlists/'
    params = {
        'from': query_type,
        'to': 'ACC',
        'format': 'txt',
        'query': query
    }
    data = urllib.parse.urlencode(params).encode('ascii')
    with urllib.request.urlopen(urllib.request.Request(url, data)) as response:
        return response.read().decode('utf-8').splitlines()

# Example: Find UniProt IDs for a protein name
protein_ids = get_uniprot_ids("hemoglobin", query_type="GENE_NAME")
2. 下载结构文件

AlphaFold 为每个预测提供多种文件格式:

可用文件类型:

  • 模型坐标(model_v4.cif):mmCIF/PDBx 格式的原子坐标
  • 置信度分数(confidence_v4.json):每个残基的 pLDDT 分数(0-100)
  • 预测对齐误差(predicted_aligned_error_v4.json):用于残基对置信度的 PAE 矩阵

下载 URL:

import requests

alphafold_id = "AF-P00520-F1"
version = "v4"

# Model coordinates (mmCIF)
model_url = f"https://alphafold.ebi.ac.uk/files/{alphafold_id}-model_{version}.cif"
response = requests.get(model_url)
with open(f"{alphafold_id}.cif", "w") as f:
    f.write(response.text)

# Confidence scores (JSON)
confidence_url = f"https://alphafold.ebi.ac.uk/files/{alphafold_id}-confidence_{version}.json"
response = requests.get(confidence_url)
confidence_data = response.json()

# Predicted Aligned Error (JSON)
pae_url = f"https://alphafold.ebi.ac.uk/files/{alphafold_id}-predicted_aligned_error_{version}.json"
response = requests.get(pae_url)
pae_data = response.json()

PDB 格式(替代方案):

# Download as PDB format instead of mmCIF
pdb_url = f"https://alphafold.ebi.ac.uk/files/{alphafold_id}-model_{version}.pdb"
response = requests.get(pdb_url)
with open(f"{alphafold_id}.pdb", "wb") as f:
    f.write(response.content)
3. 使用置信度指标

AlphaFold 预测包含对解读至关重要的置信度估计:

pLDDT(每个残基的置信度):

import json
import requests

# Load confidence scores
alphafold_id = "AF-P00520-F1"
confidence_url = f"https://alphafold.ebi.ac.uk/files/{alphafold_id}-confidence_v4.json"
confidence = requests.get(confidence_url).json()

# Extract pLDDT scores
plddt_scores = confidence['confidenceScore']

# Interpret confidence levels
# pLDDT > 90: Very high confidence
# pLDDT 70-90: High confidence
# pLDDT 50-70: Low confidence
# pLDDT < 50: Very low confidence

high_confidence_residues = [i for i, score in enumerate(plddt_scores) if score > 90]
print(f"High confidence residues: {len(high_confidence_residues)}/{len(plddt_scores)}")

PAE(预测对齐误差):

PAE 表示对相对结构域位置的置信度:

import numpy as np
import matplotlib.pyplot as plt

# Load PAE matrix
pae_url = f"https://alphafold.ebi.ac.uk/files/{alphafold_id}-predicted_aligned_error_v4.json"
pae = requests.get(pae_url).json()

# Visualize PAE matrix
pae_matrix = np.array(pae['distance'])
plt.figure(figsize=(10, 8))
plt.imshow(pae_matrix, cmap='viridis_r', vmin=0, vmax=30)
plt.colorbar(label='PAE (Å)')
plt.title(f'Predicted Aligned Error: {alphafold_id}')
plt.xlabel('Residue')
plt.ylabel('Residue')
plt.savefig(f'{alphafold_id}_pae.png', dpi=300, bbox_inches='tight')

# Low PAE values (<5 Å) indicate confident relative positioning
# High PAE values (>15 Å) suggest uncertain domain arrangements
4. 通过 Google Cloud 访问批量数据

对于大规模分析,请使用 Google Cloud 数据集:

Google Cloud Storage:

# Install gsutil
uv pip install gsutil

# List available data
gsutil ls gs://public-datasets-deepmind-alphafold-v4/

# Download entire proteomes (by taxonomy ID)
gsutil -m cp gs://public-datasets-deepmind-alphafold-v4/proteomes/proteome-tax_id-9606-*.tar .

# Download specific files
gsutil cp gs://public-datasets-deepmind-alphafold-v4/accession_ids.csv .

BigQuery 元数据访问:

from google.cloud import bigquery

# Initialize client
client = bigquery.Client()

# Query metadata
query = """
SELECT
  entryId,
  uniprotAccession,
  organismScientificName,
  globalMetricValue,
  fractionPlddtVeryHigh
FROM `bigquery-public-data.deepmind_alphafold.metadata`
WHERE organismScientificName = 'Homo sapiens'
  AND fractionPlddtVeryHigh > 0.8
LIMIT 100
"""

results = client.query(query).to_dataframe()
print(f"Found {len(results)} high-confidence human proteins")

按物种下载:

import subprocess

def download_proteome(taxonomy_id, output_dir="./proteomes"):
    """Download all AlphaFold predictions for a species"""
    pattern = f"gs://public-datasets-deepmind-alphafold-v4/proteomes/proteome-tax_id-{taxonomy_id}-*_v4.tar"
    cmd = f"gsutil -m cp {pattern} {output_dir}/"
    subprocess.run(cmd, shell=True, check=True)

# Download E. coli proteome (tax ID: 83333)
download_proteome(83333)

# Download human proteome (tax ID: 9606)
download_proteome(9606)
5. 解析和分析结构

使用 BioPython 处理下载的 AlphaFold 结构:

from Bio.PDB import MMCIFParser, PDBIO
import numpy as np

# Parse mmCIF file
parser = MMCIFParser(QUIET=True)
structure = parser.get_structure("protein", "AF-P00520-F1-model_v4.cif")

# Extract coordinates
coords = []
for model in structure:
    for chain in model:
        for residue in chain:
            if 'CA' in residue:  # Alpha carbons only
                coords.append(residue['CA'].get_coord())

coords = np.array(coords)
print(f"Structure has {len(coords)} residues")

# Calculate distances
from scipy.spatial.distance import pdist, squareform
distance_matrix = squareform(pdist(coords))

# Identify contacts (< 8 Å)
contacts = np.where((distance_matrix > 0) & (distance_matrix < 8))
print(f"Number of contacts: {len(contacts[0]) // 2}")

提取 B-factor(pLDDT 值):

AlphaFold 将 pLDDT 分数存储在 B-factor 列中:

from Bio.PDB import MMCIFParser

parser = MMCIFParser(QUIET=True)
structure = parser.get_structure("protein", "AF-P00520-F1-model_v4.cif")

# Extract pLDDT from B-factors
plddt_scores = []
for model in structure:
    for chain in model:
        for residue in chain:
            if 'CA' in residue:
                plddt_scores.append(residue['CA'].get_bfactor())

# Identify high-confidence regions
high_conf_regions = [(i, score) for i, score in enumerate(plddt_scores, 1) if score > 90]
print(f"High confidence residues: {len(high_conf_regions)}")
6. 批量处理多个蛋白质

高效处理多个预测:

from Bio.PDB import alphafold_db
import pandas as pd

uniprot_ids = ["P00520", "P12931", "P04637"]  # Multiple proteins
results = []

for uniprot_id in uniprot_ids:
    try:
        # Get prediction
        predictions = list(alphafold_db.get_predictions(uniprot_id))

        if predictions:
            pred = predictions[0]

            # Download structure
            cif_file = alphafold_db.download_cif_for(pred, directory="./batch_structures")

            # Get confidence data
            alphafold_id = pred['entryId']
            conf_url = f"https://alphafold.ebi.ac.uk/files/{alphafold_id}-confidence_v4.json"
            conf_data = requests.get(conf_url).json()

            # Calculate statistics
            plddt_scores = conf_data['confidenceScore']
            avg_plddt = np.mean(plddt_scores)
            high_conf_fraction = sum(1 for s in plddt_scores if s > 90) / len(plddt_scores)

            results.append({
                'uniprot_id': uniprot_id,
                'alphafold_id': alphafold_id,
                'avg_plddt': avg_plddt,
                'high_conf_fraction': high_conf_fraction,
                'length': len(plddt_scores)
            })
    except Exception as e:
        print(f"Error processing {uniprot_id}: {e}")

# Create summary DataFrame
df = pd.DataFrame(results)
print(df)

安装和设置

Python 库
# Install Biopython for structure access
uv pip install biopython

# Install requests for API access
uv pip install requests

# For visualization and analysis
uv pip install numpy matplotlib pandas scipy

# For Google Cloud access (optional)
uv pip install google-cloud-bigquery gsutil
3D-Beacons API 替代方案

AlphaFold 也可以通过 3D-Beacons 联合 API 访问:

import requests

# Query via 3D-Beacons
uniprot_id = "P00520"
url = f"https://www.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons/api/uniprot/summary/{uniprot_id}.json"
response = requests.get(url)
data = response.json()

# Filter for AlphaFold structures
af_structures = [s for s in data['structures'] if s['provider'] == 'AlphaFold DB']

常见用例

结构蛋白质组学
  • 下载完整的蛋白质组预测以进行分析
  • 识别蛋白质中高置信度的结构区域
  • 将预测结构与实验数据进行比较
  • 为蛋白质家族构建结构模型
药物发现
  • 检索目标蛋白质结构以进行对接研究
  • 分析结合位点构象
  • 识别预测结构中的可成药口袋
  • 比较同源物之间的结构
蛋白质工程
  • 使用 pLDDT 识别稳定/不稳定区域
  • 在高置信度区域设计突变
  • 使用 PAE 分析结构域架构
  • 对蛋白质变体和突变进行建模
进化研究
  • 比较不同物种间的直系同源物结构
  • 分析结构特征的保守性
  • 研究结构域进化模式
  • 识别功能上重要的区域

关键概念

UniProt 登录号: 蛋白质的主要标识符(例如 "P00520")。查询 AlphaFold DB 时必需。

AlphaFold ID: 内部标识符格式:AF-[UniProt accession]-F[fragment number](例如 "AF-P00520-F1")。

pLDDT(预测的局部距离差异检验): 逐残基置信度指标(0-100)。数值越高表示预测越可信。

PAE(预测对齐误差): 表示残基对之间相对位置置信度的矩阵。低数值(<5 Å)表示相对定位可信。

数据库版本: 当前版本为 v4。文件 URL 包含版本后缀(例如 model_v4.cif)。

片段编号: 大型蛋白质可能被拆分为多个片段。片段编号出现在 AlphaFold ID 中(例如 F1、F2)。

置信度解读指南

pLDDT 阈值:

  • >90:极高置信度 - 适合详细分析
  • 70-90:高置信度 - 主链结构总体可靠
  • 50-70:低置信度 - 谨慎使用,柔性区域
  • <50:极低置信度 - 可能无序或不可靠

PAE 指南:

  • <5 Å:结构域相对定位可信
  • 5-10 Å:排列置信度中等
  • >15 Å:相对位置不确定,结构域可能可移动

资源

references/api_reference.md

全面的 API 文档,涵盖:

  • 完整的 REST API 端点规范
  • 文件格式详情和数据模式
  • Google Cloud 数据集结构和访问模式
  • 高级查询示例和批处理策略
  • 速率限制、缓存和最佳实践
  • 常见问题排查

如需详细的 API 信息、批量下载策略,或处理大规模数据集时,请查阅此参考文档。

重要说明

数据使用与署名
  • AlphaFold DB 在 CC-BY-4.0 许可下免费提供
  • 引用:Jumper et al. (2021) Nature 和 Varadi et al. (2022) Nucleic Acids Research
  • 预测结果是计算模型,而非实验结构
  • 在下游分析前务必评估置信度指标
版本管理
  • 当前数据库版本:v4(截至 2024-2025)
  • 文件 URL 包含版本后缀(例如 _v4.cif)
  • 定期检查数据库更新
  • 旧版本可能随时间被弃用
数据质量注意事项
  • 高 pLDDT 并不保证功能准确性
  • 低置信度区域在体内可能无序
  • PAE 表示结构域相对置信度,而非绝对定位
  • 预测结果缺少配体、翻译后修饰和辅因子
  • 不预测多链复合物(仅单链)
性能提示
  • 使用 Biopython 进行简单的单蛋白质访问
  • 使用 Google Cloud 进行批量下载(比逐个文件快得多)
  • 将下载的文件缓存到本地以避免重复下载
  • BigQuery 免费层:每月 1 TB 处理数据
  • 大规模下载时考虑网络带宽

其他资源

评论

支持 Markdown