【问题标题】:When trying to create lists of CA atoms, I get the following error "key error 'CA' when executing the following code尝试创建 CA 原子列表时,执行以下代码时出现以下错误“key error 'CA'
【发布时间】:2016-02-29 09:52:34
【问题描述】:

对于以下代码,当我执行代码时出现错误,我已在下面列出。我想知道是否有人可以告诉我如何将 CA 原子附加到 tag_atoms/tagged_atoms 列表中,我将使用它来对齐。并强调我会忽略的代码编写方式中的任何潜在缺陷。我是 python 新手,所以任何见解都会很棒而且很有帮助。

def loadPDB(pdb_name):

    folder = pdb_name[1:3]
    pdbl = PDB.PDBList()
    pdbl.retrieve_pdb_file(pdb_name)
    parser = PDB.PDBParser(PERMISSIVE=1)
    structure = parser.get_structure(
        pdb_name, folder + "/pdb" + pdb_name + ".ent")

    return structure

def alignCoordinates(taggedProtein, potentialTag):
    for model in taggedProtein:
        firstModel = model
        break
    for chain in firstModel:
        firstChain = chain
        break

    for firstChain in firstModel:
        tagged_atoms = []
        tag_atoms    = []

        for residue in firstChain:
            tagged_res = residue

        for tagged_res in firstChain:
            tagged_atoms.append(firstChain['CA'])

    for model in potentialTag:
        firstTagModel = model
        break

    for chain in firstTagModel:
        firstTagChain = chain
        break

    for residue in firstTagChain:
        tag_res = residue

        for tag_res in firstTagChain:
            tag_atoms.append(firstTagChain['CA'])

    super_imposer = Bio.PDB.Superimposer()
    print repr(tagged_atoms)
    print repr(tag_atoms)
    super_imposer.set_atoms(tagged_atoms, tag_atoms)
    super_imposer.apply(tag_model.get_atoms())

    print super_imposer.rms

    io = Bio.PDB.PDBIO()
    io.set_structure(tag_model)
    io.save("Aligned.PDB")

def main():

    pdb1 = "2lyz"
    pdb2 = "4abn"

    potentialTag  = loadPDB(pdb1)
    taggedProtein = loadPDB(pdb2)

    alignCoordinates(taggedProtein, potentialTag)

main()

这是下面的错误信息:

Structure exists: '/Users/Azi_Ts/Desktop/ly/pdb2lyz.ent' 
Structure exists: '/Users/Azi_Ts/Desktop/ab/pdb4abn.ent' 
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:87:          PDBConstructionWarning: WARNING: Chain A is discontinuous at line 13957.
  PDBConstructionWarning)
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:87:   PDBConstructionWarning: WARNING: Chain B is discontinuous at line 14185.
  PDBConstructionWarning)

Traceback (most recent call last):
  File "alignPDB.py", line 76, in <module>
    main()
  File "alignPDB.py", line 74, in main
    alignCoordinates(taggedProtein, potentialTag)
  File "alignPDB.py", line 39, in alignCoordinates
    tagged_atoms.append(firstChain['CA'])
  File "/Library/Python/2.7/site-packages/Bio/PDB/Chain.py", line 70, in    __getitem__
    return Entity.__getitem__(self, id)
  File "/Library/Python/2.7/site-packages/Bio/PDB/Entity.py", line 38, in   __getitem__
    return self.child_dict[id]
KeyError: 'CA'

【问题讨论】:

    标签: python biopython sequence-alignment


    【解决方案1】:

    要获得所有CA 原子,您只需要做:

    ca_atoms = [atom for atom in taggedProtein.get_atoms() if atom.name=="CA"]
    

    请记住,加载的结构 taggedProteinpotentialTag 具有三种可能在这里有用的方法:get_chains()get_residues()get_atoms()。使用这三个你可以摆脱你在def alignCoordinates() 中的每个for 循环。

    【讨论】:

      猜你喜欢
      • 2019-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2018-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多