This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Pass query and subject as string instead of files to blastn

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 answer

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)

Log in to answer this question.