Parsing Standalone Blast XML Output with Biopython on Linux
1
0
Entering edit mode
6.8 years ago

Hello,

I want to parse my blast XML results and extract a few things and put them into a new multifasta file as following:

. >[alignment.title][hsp.expect][align_length][hsp.sbjct]

from Bio.Blast import NCBIXML
results=open('./results.xml', 'r' )
records=NCBIXML.parse(results)

save_file = open("./presults.fasta", "w")

for blast_record in records:
        for alignment in blast_record.alignments:
                for hsp in alignment.hsps:
                        save_file.write('>%s\n' % (alignment.title, hsp.expect, align_length, hsp.sbjct))
save_file.close()

But thats the error I get.

  File "parsing.py", line 10, in <module>
    save_file.write('>%s\n' % (alignment.title, hsp.expect, hsp.sbjct))
TypeError: not all arguments converted during string formatting

It is important that I get the complete subject sequences out of this.

Best regards

xml biopython blast parse • 2.9k views
ADD COMMENT
2
Entering edit mode
6.8 years ago

in

save_file.write('>%s\n')

there is only one palceholder '%s' while there are 4 arguments.

https://www.safaribooksonline.com/library/view/python-cookbook-2nd/0596007973/ch04s21.html

ADD COMMENT
1
Entering edit mode

Ok, I see that. But how do I get this to work?

EDIT:nevermind. I got it.

ADD REPLY

Login before adding your answer.

Traffic: 2178 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6