Ana
Ana

Reputation: 141

Biopython script is not working, it sends errortype generator

I am having a few errors I don't understand when trying to parse an xml file with biopython, can anyone help me to understand this, please?

TypeError: object of type 'generator' has no len()

    from Bio import SearchIO
    blast_qresults=SearchIO.parse('my_file.xml', 'blast-xml')
    len(blast_qresults)

    or

    blast_qresults.hit

AttributeError: 'generator' object has no attribute 'hit

Upvotes: 1

Views: 38

Answers (1)

cdlane
cdlane

Reputation: 41872

I believe this is the syntax you want:

from Bio import SearchIO

blast_qresults = SearchIO.parse('my_file.xml', 'blast-xml')

for hit in blast_qresults:
    print(hit)

Since blast_qresults is a generator, you can only "walk" it once.

Upvotes: 2

Related Questions