I am a first time python user, and am stumped. I am using the following code to parse my blast XML file, and everything is working great. The one thing I cant figure out is the correct addition to the "OUT.write" line to extract the <hit_accession> field. If anybody knows the correct object/argument, or even better a beginning user friendly list of objects I would really appreciate it. No amount of googling has availed me so far.
#!/usr/bin/env python import sys from Bio.Blast import NCBIXML #Usage, opens an outfile and then parses any number of .xml files into that outfile, printing all hits #parse_blastn.py outfile.txt anynumberofinfiles.xml OUT = open(sys.argv, 'w') OUT.write("Query Name\tQuery Length\tAlignment Title\tAlignment ID\tAlignment Def\teValue") for xml_file in sys.argv[2:]: result_handle = open(xml_file) blast_records = NCBIXML.parse(result_handle) for rec in blast_records: for alignment in rec.alignments: for hsp in alignment.hsps: OUT.write('\n'+ str(rec.query_id) + '\t' + str(rec.query_length) + '\t' + str(alignment.title) + '\t' + str(alignment.hit_id) + '\t' + str(alignment.hit_def) + '\t' + str(hsp.expect))