[Biopython] Parsing Blast results in XML format
Michiel de Hoon
mjldehoon at yahoo.com
Thu Nov 5 23:22:17 EST 2009
> blast_record = blast_records.next()
You're only pulling out the first Blast record. If you call blast_records.next() again, it will give you the second Blast record. And so on.
Easiest solution is to have a for-loop:
blast_records = NCBIXML.parse(result_handle)
for blast_record in blast_records:
# get the information you need from blast_record.
--Michiel.
--- On Thu, 11/5/09, Jon Bråte <jon.brate at bio.uio.no> wrote:
> From: Jon Bråte <jon.brate at bio.uio.no>
> Subject: [Biopython] Parsing Blast results in XML format
> To: biopython at lists.open-bio.org
> Date: Thursday, November 5, 2009, 7:29 PM
> Dear all,
>
> I have a Blast output file in xml format generated by
> qBlast done through biopython. The Blast was performed with
> 22 query sequences and 50 hits were returned for each query.
> The result is in one single xml file. I want to extract all
> the sequence IDs for all the hits (22x50) and I have been
> checking out the BioPython cookbook page 53.
>
> I am using this code, but I am only getting the 50 hits for
> the 1st query sequence:
> from Bio.Blast import NCBIXM
> blast_records = NCBIXML.parse(result_handle)
> blast_record = blast_records.next()
>
> save_file =
> open("/Users/jonbra/Desktop/my_fasta_seq.fasta", 'w')
>
> for alignment in blast_record.alignments:
> for hsp in alignment.hsps:
>
> save_file.write('>%s\n' % (alignment.title,))
> save_file.close()
> Can anyone help me to retrieve all the hits for all the
> query sequences?
>
> Best wishes
>
> Jon Bråte
>
>
> -------------------------------------------------------------
> Jon Bråte
> PhD student
>
> Microbial Evolution Research Group (MERG)
> Department of Biology
> University of Oslo
> P.b. 1066 Blindern
> N-0316 Oslo
> Norway
> Phone: +47 22855083
>
>
> _______________________________________________
> Biopython mailing list - Biopython at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biopython
>
More information about the Biopython
mailing list