Error passing generated fasta to blastn in biopython
1
0
Entering edit mode
7.5 years ago
Daniel ★ 4.0k

I'm running a script which finds regions of interest, outputs them to a fasta, then passes them to blastn. Both steps work independently, but the script wont wait for the file to be generated and says:

./seq_targeter.py -i ecoli.fa -o tester -B
Testing if regions match guidelines.
Running blastn for all generated sequences.
('', 'Warning: [blastn] Query is Empty!\n')
All done, see files: tester-table.txt, tester.fasta and tester.bln

The script is basically this:

def main():
    outfasta = open(args.o + ".fasta", 'w')  
    seqTargeter(outfasta)               # Outputs a fasta file as expected
    blastFunc(args.o + ".fasta")      # Outputs a blank file and gives error above

seqTargeter(outfasta):
    print "Testing if regions match guidelines."
    .................
    outfasta.write('...........')

def blastFunc(blastfasta):
    print "Running blastn for all generated sequences."
    blastn_cline = NcbiblastnCommandline(query=blastfasta, db=args.d, outfmt=7, out=args.o + ".bln")()
    print blastn_cline

If I comment out the seqTargeter parts and let the script run on the already generated output.fasta file, then blastn will be called correctly and give the correct output. But if I want them both to work after the other, then nothing. I've been looking at something like this from Stackexchange, but I think the file exists doesn't work as it's still being generated...

Thanks

biopython blast blastn • 2.5k views
ADD COMMENT
1
Entering edit mode

Reposted comment as answer.

ADD REPLY
0
Entering edit mode

Perfect, totally what I'd missed. If you put this as an answer I could accept it.

ADD REPLY
3
Entering edit mode
7.5 years ago
Jenez ▴ 540

outfasta = open(args.o + ".fasta", 'w')

It's never closed again from what I see. The file content will not be properly written unless you close the file. Even if this is not the issue, try to use with open(file, 'w') as out: instead as it will close itself properly.

ADD COMMENT

Login before adding your answer.

Traffic: 2503 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6