Pass query and subject as string instead of files to blastn
1
0
Entering edit mode
6.2 years ago

I'm running multiple blast searches using temp files. I'm looking for a method to pass via command line subject and query as strings instead of files. This is the code I'm using so far

cmd_list = ['blastn','-query',"query",'-subject',"subject",
        '-reward','2',
        '-max_target_seqs','1',
        '-penalty','-4',
        '-word_size','7','-ungapped',
        '-evalue','10','-strand',"plus",
        '-soft_masking','false' ,'-dust','no',
        '-outfmt',"6 sstart send qstart qend score length mismatch gaps gapopen nident"]
        #]
        blast_process = Popen(cmd_list, stdout=PIPE, stderr=PIPE)
        out,err = blast_process.communicate()

I've also tried this with no success:

'-query','<(echo -e ">'+record.id+'\n'+seq+'")' ,
blast python biopython • 1.8k views
ADD COMMENT
4
Entering edit mode
6.2 years ago

Python is using /bin/sh to run your command and it doesn't support process substitution. You need to manually use /bin/bash instead.

Python 3:

from subprocess import Popen, PIPE

id1 = 'seq1'
seq1 = 'TTGATGCAAAAGGCAAGATAATTACTAGTACAATATAGTCCC'
id2 = 'seq2'
seq2 = 'TTGATGCAAAAGGCAAGATAATTACTAGTACAATATAGTCCC'

cmd = 'blastn -query <(echo -e \">{}\\n{}\")'.format(id1, seq1)
cmd += ' -subject <(echo -e \">{}\\n{}\")'.format(id2, seq2)
cmd += ' -evalue 10'

p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True, executable='/bin/bash')
out,err = p.communicate()
print(out)
print(err)
ADD COMMENT
0
Entering edit mode

brillant, much faster!

ADD REPLY

Login before adding your answer.

Traffic: 1886 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