I have a working code, which is doing BLAST on ncbi server, then returns sequences in xml format. It is working but I want to avoid making new files and print BLAST results directly on terminal. It is there a good solution to do this? Im pasting below my code, which is working, but it is creating a new file.
result_handle = NCBIWWW.qblast(
"blastx",
"nr",
sequences,
entrez_query = organism)
save_file = open("BLAST.xml", "w")
save_file.write(result_handle.read())
save_file.close()
result_handle.close()
result = open("BLAST.xml", "r")
records = NCBIXML.parse(result)
for i, record in enumerate(records):
if record.alignments == []:
print ("There is no BLAST result")
else:
for align in record.alignments:
print (align.hit_id)
break
I wanted to do something like this:
result = result_handle.read()
record = NCBIXML.parse(result)
for i, record in enumerate(record):
But it is not working.
Thank You in advance!
My belief is the solution should be even simpler than you're hoping:
The result from
NCBIWWW.qblast()
is a handle onto aStringIO
input stream which you can directly hand toNCBIXML.parse()
.