Biopython从pdb文件中提取蛋白质链的信息
使用Biopython
的PDB
模块可以方便地解析PDB文件并提取你需要的信息。下面是一个示例代码,用于提取PDB文件中的链名称、序列和长度:
示例代码
from Bio import PDB
# 读取PDB文件
pdb_file = "/Users/zhengxueming/Downloads/1a0h.pdb"
parser = PDB.PDBParser(QUIET=True)
structure = parser.get_structure("protein", pdb_file)
# 初始化保存信息的列表
chain_info = []
# 遍历所有模型、链和残基
for model in structure:
for chain in model:
chain_id = chain.id
sequence = []
for residue in chain:
# 检查是否是标准氨基酸
if PDB.is_aa(residue):
sequence.append(PDB.Polypeptide.three_to_one(residue.resname))
# 提取链的序列和长度
seq_str = ''.join(sequence)
chain_length = len(sequence)
chain_info.append((chain_id, chain_length, seq_str))
# 打印链的信息
for chain_id, chain_length, seq_str in chain_info:
print(f"链ID: {chain_id}, 长度: {chain_length}, 序列: {seq_str}")