Hello all,
I'm beginning to learn Python 2.7 and need to develop some applications for a lab project.
I want to run an external program and then use its output as input for another external call in the same script. The issue is that the script tries to call the second program even before the first one has finished working, so the output is not yet available to be used as its input. How can I solve this problem?
Here is my code:
picker = Popen ([pick_open_reference_otus.py, -i, allseq_file, -r, refseq_file, -o, noName, -s, 0.1, -m, usearch61, -p, param_file ], shell = True)
picker_out = os.path.join(path, "otu_output/otu_table_mc2_w_tax.biom")
Thank you all!
I'm not 100% sure because I have not done any work with the subprocesses module, however I think you can just use the wait() module. something like
picker.wait(picker_out)
or something to that effect.or
picker_out = picker.wait(os.path.join(path, "otu_output/otu_table_mc2_w_tax.biom")
sorry. I'm not sure about the syntaxlast one :)
Thank you a lot for your help!
https://docs.python.org/2/library/subprocess.html
Subprocess has what you want.
Python can be rather clunky for this kind of thing. If you need data from some of these programs you're calling to end up being processed in python, it is better to pull the data into python from the "outside". You may want to explore other options for managing pipelines, there are plenty of posts and tutorials on here about it.
Thank you for the link!