Exchhattu
Exchhattu

Reputation: 307

post effect of renumbering residue number of pdb using biopython

In the following code, I parsed the pdb and computed secondary structure using DSSP library. After parsing and storing values, I renumbered the residue number but I did not modify _pdb and _dssp instances. After renumbering, it also renumbered the previously assigned values of _dssp like you can see in output that I commented. I think this is effect of by reference operation. I want to avoid the changes in _dssp value after renumbering since I did not explicitly modify the _dssp. How can this type of operation be avoided?

class PDBModify:

  _pdb = None
  _dssp = None

  def parse(self, pdbid, pdbfile):
    pdbparser = PDBParser(PERMISSIVE=1)
    structure = pdbparser.get_structure(pdbid, pdbfile)
    self._pdb = structure[0]
    self._dssp = DSSP(structure[0], pdbfile)

  def delete_n_dump(self, rsds, map_rsds):
    current = self._pdb
    for chain in current:
      for residue in list(chain):
        if not residue.id[1] in rsds:
          chain.detach_child(residue.id)
        else:
          residue.id = (' ', map_rsds[residue.id[1]], ' ')

    write_pdb = PDBIO()
    write_pdb.set_structure(current)
    write_pdb.save("./3chy_md.pdb")

if __name__=="__main__":
  map_rsds = {15:200, 20: 201, 25:202, 26:203, 30:204, 34:205, 35:206, 36:207}
  rsds = [15, 20, 25, 26, 30, 34, 35, 36]

  pdbmodify = PDBModify()
  pdbmodify.parse('3chy', './3chy.pdb')  # parsing pdb and computing ss
  print "before "
  for item in pdbmodify._dssp:  # initial call
    print item
  pdbmodify.delete_n_dump(rsds, map_rsds)  # renumber the residue id
  print "after "
  for item in pdbmodify._dssp:  # second call 
    print item

Output:

before
(<Residue ALA het=  resseq=2 icode= >, '-', 65, 0.6132075471698113, 360.0, 127.6)
...
(<Residue SER het=  resseq=15 icode= >, 'H', 73, 0.5615384615384615, -60.0, -33.4)
...

after 
(<Residue ALA het=  resseq=2 icode= >, '-', 65, 0.6132075471698113, 360.0, 127.6)
...
(<Residue SER het=  resseq=200 icode= >, 'H', 73, 0.5615384615384615, -60.0, -33.4) # residue number is changed here why?
...

Upvotes: 0

Views: 543

Answers (1)

joaquin
joaquin

Reputation: 85605

You are pointing to the same structure[0] object with self._pdb and self._dssp

self._pdb = structure[0]
self._dssp = DSSP(structure[0], pdbfile)

If you want to unlink them, you could use copy.copy or copy.deepcopy (depending if structure[0] is a simple object, like a list, that needs just a shallow copy, or complex, like a list of lists).

For example:

import copy
self._pdb = copy.deepcopy(structure[0])
self._dssp = DSSP(structure[0], pdbfile)

Upvotes: 1

Related Questions