Last active
December 16, 2020 16:08
-
-
Save davipatti/f33d0fdbd4e3af24486a2d821104c4ad to your computer and use it in GitHub Desktop.
Driving NCBI BLAST from python without writing to disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from Bio.Blast.Applications import NcbiblastpCommandline | |
from Bio import SeqIO | |
# Grab any sequence to blast | |
with open("db.fasta", "r") as f: | |
record = next(SeqIO.parse(f, "fasta")) | |
read, write = os.pipe() | |
parent = os.fork() | |
if parent: | |
os.close(write) | |
read = os.fdopen(read) | |
cline = NcbiblastpCommandline(db="db.fasta") | |
cline(stdin=read.read()) | |
exit() | |
else: | |
os.close(read) | |
write = os.fdopen(write, "w") | |
SeqIO.write(record, write, "fasta") | |
write.close() | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment