Question: Pass query and subject as string instead of files to blastn
0
gravatar for juan.crescente
21 months ago by
juan.crescente20 wrote:

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 biopython python • 695 views
ADD COMMENTlink modified 21 months ago by a.zielezinski8.9k • written 21 months ago by juan.crescente20
4
gravatar for a.zielezinski
21 months ago by
a.zielezinski8.9k
a.zielezinski8.9k wrote:

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 COMMENTlink modified 21 months ago • written 21 months ago by a.zielezinski8.9k

brillant, much faster!

ADD REPLYlink written 21 months ago by juan.crescente20
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2817 users visited in the last hour