I looked and found solutions, tried them and got the same result. I tried using Popen.wait()
, run()
and call()
. As suggested by other users, I also tried passing the command as a list of strings. Didn't work. The subprocess call doesn't give an error, so that's not the issue.
Here's the function:
def blast(file):
command = f'blastn -query {output_path}fasta_files/{file} -db {db_path} -max_hsps 1 -max_target_seqs 40 -num_threads 4 -evalue 1e-5 ' \
f'-out {output_path}blast/{file[:-2]}txt -outfmt "6 qseqid sseqid pident staxids sskingdoms qstart qend ' \
f'qlen length sstart send slen evalue mismatch gapopen bitscore stitle"'
subprocess.Popen(command, stdout=subprocess.PIPE, shell=True).wait()
Here's the call to the function:
import blastn
from process_blast_output import *
from remove_false_sequences import *
import os
directory = '/some/path/'
if __name__ == '__main__':
for file in os.listdir(directory + 'fasta_files'):
if 'btcaA1_trimmed' in file:
blastn.blast(f'{file}') # That's where the function is called
dataframe = get_dataframe(directory + f'blast/{file[:-2]}txt')
dataframe = get_taxonomic_data(dataframe)
delete_false_hits(fasta_to_dictionary(dataframe), directory + f'fasta_files/{file[:-2]}fa')
Instead of passing a string I also tried passing a list:
subprocess.Popen(['blastn', '-query', f'{output_path}fasta_files/{file}', '-db', f'{db_path}', '-max_hsps', '1',
'-max_target_seqs', '40', '-num_threads', '4', '-evalue', '1e-5', '-out',
f'{output_path}blast/{file[:-2]}txt', '-outfmt', "6 qseqid sseqid pident staxids sskingdoms "
"qstart qend qlen length sstart send slen evalue"
" mismatch gapopen bitscore stitle"],
stdout=subprocess.PIPE).wait()