-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbiopython_blastparse_xml.py
More file actions
25 lines (22 loc) · 935 Bytes
/
biopython_blastparse_xml.py
File metadata and controls
25 lines (22 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from Bio.Blast import NCBIXML
# read blast output
result_handle = open("biopython_blast.xml")
blast_records = NCBIXML.parse(result_handle)
# result_handle.close()
# parse for top 3 HSPs per query and show the first 75bp of alignment
for blast_record in blast_records:
print('***********************************************')
print('query: ' + str(blast_record.query))
for alignment in blast_record.alignments[0:3]:
for hsp in alignment.hsps:
print('-----------')
print('hit: ' + str(alignment.title.split()[0]))
print('evalue: ' + str(hsp.expect))
print('length: ' + str(alignment.length))
if len(hsp.query)>75:
print('query ' + hsp.query[0:75] + '...')
print('hit ' + hsp.sbjct[0:75] + '...')
else:
print('query ' + hsp.query)
print('hit ' + hsp.sbjct)
break