[Biopython] a parsing error

Bala subramanian bala.biophysics at gmail.com
Tue May 25 16:29:44 UTC 2010


Friends,

The following code takes all the pdb's in the current directory and creates
a matrix. I get a parsing error. Pls write what is going wrong.

from numpy import zeros,savetxt,matrix
from Bio.PDB import *
import glob
donor=[ 'ARG','ASN', 'GLN', 'LYS', 'TRP' ]
ali=['ALA', 'ARG', 'CYS', 'ILE', 'LEU', 'LYS', 'MET', 'PRO', 'THR', 'VAL' ]
parser=PDBParser()
X5_MAT=matrix(zeros((34,34),int))
files=glob.glob('*.pdb')
for i in range(len(files)):
    strng=str(i)
    structure=parser.get_structure(strng,files[i])
    res=Selection.unfold_entities(structure,'R')

    for x in range(len(res)):
        for y in range(len(res)):
            if x <> y :
                if not res[x].get_resname() in donor: continue

                else:
                    if res[y].get_resname() in ali:
                        X5_MAT[x,y] = X5_MAT[x,y] + 1

            else: pass


savetxt('myfile.txt', matrix(X5_MAT), fmt='%d')


*The error is pasted below*

Traceback (most recent call last):
  File "un_don_ali.py", line 14, in <module>
    structure=parser.get_structure(' ',files[i])
  File "/usr/lib/python2.5/site-packages/Bio/PDB/PDBParser.py", line 64, in
get_structure
    self._parse(file.readlines())
  File "/usr/lib/python2.5/site-packages/Bio/PDB/PDBParser.py", line 82, in
_parse
    self.header, coords_trailer=self._get_header(header_coords_trailer)
  File "/usr/lib/python2.5/site-packages/Bio/PDB/PDBParser.py", line 95, in
_get_header
    header=header_coords_trailer[0:i]
UnboundLocalError: local variable 'i' referenced before assignment



More information about the Biopython mailing list