[BioPython] NCBIXML

Björn Thorwirth bjoern.thorwirth at uni-due.de
Tue Nov 27 03:13:35 EST 2007


Hello List!

Today i got some trouble with the NCBIXML module. I've tested my code on
a
32-Bit machine with Biopython-1.43 where it worked flawless.  On 64-Bit
i
got the this error with Biopython-1.43 / 1.44:


 File "/usr/lib/python2.4/site-packages/twisted/internet/threads.py",
line
25, in _putResultInDeferred
    result = f(*args, **kwargs)
  File "/home/user/workspace/PLGDaemon/src/mmCIF/blast_util.py", line
56,
in getResults
    for record in records:
  File
"/home/user/Desktop/biopython/biopython-1.43/build/lib.linux-x86_64-2.4/Bio/Blast/NCBIXML.py",
line 625, in parse
    assert len(blast_parser._records) == 0
exceptions.UnboundLocalError: local variable 'blast_parser' referenced
before assignment
  File "/usr/lib/python2.4/site-packages/twisted/internet/threads.py",
line 25, in _putResultInDeferred
    result = f(*args, **kwargs)
  File "/home/user/workspace/PLGDaemon/src/mmCIF/blast_util.py", line
56,
in get Results
    for record in records:
  File
"/home/user/Desktop/biopython/biopython-1.43/build/lib.linux-x86_64-2.4/B
io/Blast/NCBIXML.py", line 625, in parse
    assert len(blast_parser._records) == 0
exceptions.UnboundLocalError: local variable 'blast_parser' referenced
before as signment^[[B


And here is the Code which calls the NCBIXML module:
def getResults(self,resultFileHandle,err_handle):
        try:
            records=NCBIXML.parse(resultFileHandle)
        except Exception,e:
            self.IoErrorHandler(e, resultFileHandle, err_handle)
            raise
        bestScore=None
        bestExpect=None
        bestRes=None
        results=[]
        if records:
            for record in records:
                for alignment in record.alignments:
                    resRec={}
                    resRec['title']=alignment.title
                    resRec['length']=alignment.length
                    for hsp in alignment.hsps:
                        resRec['score']=hsp.score
                        resRec['expect']=hsp.expect
                        resRec['subj']=hsp.sbjct
                        resRec['obj']=hsp.query
                        resRec['match']=hsp.match
                        if self.debug:
                            print 'alignment.hsp:'
                            print hsp.score,hsp.expect,hsp.sbjct,
hsp.match, hsp.query
                        results.append(resRec)
                        if bestScore==None:
                            bestScore=hsp.score
                            bestExpect=hsp.expect
                            bestRes=len(results)-1
                        elif hsp.score>bestScore:
                            bestScore=hsp.score
                            bestExpect=hesp.expect
                            bestRes=len(results)-1

Has someone an Idea? Should I just catch the error?

Best regards,

Björn Thorwirth




More information about the BioPython mailing list