Saving output of a for-loop to file

前端 未结 5 952
礼貌的吻别
礼貌的吻别 2020-12-17 06:32

I have opened a file with blast results and printed out the hits in fasta format to the screen.

The code looks like this:

result_handle = open(\"/Use         


        
5条回答
  •  甜味超标
    2020-12-17 06:35

    for some reason the code above posted by OP did not work for me.. I modified a bit

    from Bio.Blast import NCBIXML
    f = open('result.txt','w')
    for record in NCBIXML.parse(open("file.xml")) :
        for alignment in record.alignments:
            for hsp in alignment.hsps:
                f.write(">%s\n"%alignment.title)
                f.write(hsp.sbjct+"\n")
    

提交回复
热议问题