python - 在Biopython PDB模块中获取残基编号和残基名称

标签 python bioinformatics biopython

我目前正在使用 pymol 的迭代来获取所有残基编号,然后我使用它们来检索残基名称。我认为这不是最好的方法。我试图在 biopython 中寻找一种方法无济于事。非常感谢您的意见和建议。

一个附带问题,有时甚至 chain[i].resname 都会给我一个 KeyError: (' ', 'number', ' ') 和一个特定的残基,这让我使用了一个 try 和 except block 。还有其他选择吗?

from Bio import *
from Bio.PDB.PDBParser import PDBParser
from Bio.PDB.Polypeptide import PPBuilder
structure = PDBParser().get_structure('5bmy', '5bmy.pdb')    
model = structure[0]
chain = model['A']

import __main__
__main__.pymol_argv = ['pymol','-qc']
import pymol
from pymol import cmd, stored
pymol.finish_launching()
cmd.load('5bmy.pdb')  # use the name of your pdb file
stored.residues = []
cmd.iterate('name ca', 'stored.residues.append(resi)')
numbers = [ int(x) for x in stored.residues ]
for i in numbers:
    print (chain[i].resname)

最佳答案

通过查看 API(以及可通过命令 dir(chain) 链接的内容),我可以看到有一个方法 get_residues() .查看包含的一个残基,我可以看到有一个函数 get_resname()。使用这些,您的问题的一个解决方案可能是:

from Bio import *
from Bio.PDB.PDBParser import PDBParser
from Bio.PDB.Polypeptide import PPBuilder
structure = PDBParser().get_structure('5bmy', '5bmy.pdb')    


model = structure[0]
chain = model['A']

for i in chain.get_residues():
    print(i.get_resnames())

这给出了一个不需要 pymol 的解决方案。

关于python - 在Biopython PDB模块中获取残基编号和残基名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42851010/

相关文章:

python - 如何使用biopython将多fasta文件分割成相同序列长度的 block 并更改 header

python - 在 Python 的 ASCII 文件中查找/替换带注释的子字符串

python - 字符串如何存储为 'sequence of Unicode code points' ?

python - 在 Ubuntu 上使用 pip 安装 NumPy 失败

python - 如何在 mac 上从 64 位 python 2.7 切换到 32 位 python 2.7

python - 对齐匹配序列

Docker 通过容器实现单个进程,但如何将它们一起使用

python - 如何使用Python从outlook获取突出显示(选定)的邮件?

scala - 用于生物信息学/生物统计学/医学研究的 Clojure 或 Scala

python - Biopython 的 SeqIO.parse 在第一次迭代后停止解析。为什么?这是我安装的问题吗?