[BioPython] error in writting pdb file

Peter biopython at maubp.freeserve.co.uk
Tue Dec 30 16:55:32 UTC 2008


On Tue, Dec 30, 2008 at 5:47 AM, Bala subramanian
<bala.biophysics at gmail.com> wrote:
> Peter,
> Here is the small code i where i try to renumber the residues.
>
> Python 2.5.2
>>>> from Bio.PDB import PDBParser
>>>> from Bio.PDB import PDBIO
>>>> par=PDBParser()
>>>> S=par.get_structure('cef','1CE4.pdb')
>>>> seq=range(100,134+1)
>>>> i=0
>>>> for residues in S.get_residues():
> ...     residues.id=('',seq[i],'')
> ...     i += 1
> ...
>>>> out=PDBIO()
>>>> out.set_structure(S)
>>>> out.save("new.pdb")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File
> "/home/bala/Desktop/biopython-1.49/build/lib.linux-i686-2.5/Bio/PDB/PDBIO.py",
> line 150, in save
>   File
> "/home/bala/Desktop/biopython-1.49/build/lib.linux-i686-2.5/Bio/PDB/PDBIO.py",
> line 84, in _get_atom_line
> TypeError: %c requires int or char

For this example, the copy of 1CE4.pdb I just downloaded seems to have
700 residues - but you only created a list of 35 new identifiers.
This mean the code above fails for me with an index error - easy to
fix but I'm not 100% sure how you want to renumber the residues.

As to the TypeError, I think the problem is you are setting the first
and last parts of the ID to empty string.  Try using a single space
instead - how about:

for index, residue in enumerate(S.get_residues()) :
    residue.id = (" ", index+100, " ") #Note quoted spaces!

Notice I'm using the python enumerate function, which means index
counts from 0, 1, 2, ... and I then use this to calculate the new
identifier by adding 100.  You may want to do something differently.

Peter



More information about the Biopython mailing list