I'm trying to use Bio.Blast in a python script to return alignments for a sequence but when I run the query the resulting XML does not contain any alignments. I've gone onto the BLAST page via web browser and queried the same sequence and it was able to find high coverage alignments successfully. I've tried many different ways of passing in values to the query that the browser tool used but got the same empty XML result. If anyone has encountered this issue or knows what I'm doing wrong, please let me know. I've attached the code I'm using and what the resulting XML file from the query looks like. Any help is greatly appreciated! :)
from Bio.Blast import NCBIWWW, NCBIXML
# Perform BLAST search
result_handle = NCBIWWW.qblast(
"blastn",
"nt",
decoded_dna,
expect = .05,
nucl_penalty= -2,
nucl_reward = 1,
word_size=28,
megablast=True,
entrez_query='txid9606[ORGN]')
xml_file = "blast_results.xml"
with open(xml_file, "w") as out_file:
out_file.write(result_handle.read())
out_file.close()
# Parse BLAST results(NOTE: can only call read(results_handle) once, 2nd time will return an empty string)
blast_record = NCBIXML.read(open(xml_file))
# Print out the results
for alignment in blast_record.alignments:
for hsp in alignment.hsps:
# if hsp.expect < 0.01: # E-value threshold
print("****Alignment****")
print("sequence:", alignment.title)
print("length:", alignment.length)
print("e value:", hsp.expect)
print(hsp.query[0:75] + "...")
print(hsp.match[0:75] + "...")
print(hsp.sbjct[0:75] + "...")
What the resulting XML file looks like:
Please do not paste screenshots of plain text content, it is counterproductive. You can copy paste the content directly here (using the code formatting option shown below), or use a GitHub Gist if the content volume exceeds allowed length here.
Got it, thanks for letting me know!