I'm testing now, Idk of x = subprocess.wait() the correct syntax for python 3.5 or previous versions, but for python 3.6 shoud be:
x = subprocess.Popen(GLAPD_SINGLE)
x.wait()
When my current analysis ends, I'll give the feedback, thanks Joe !
Hey guys, I'm writting a python script to automatize a lot of tasks, one of this tasks is the use of GLAPD (a tool to desing primers of lamp (http://cgm.sjtu.edu.cn/GLAPD/)).
So I have a list with the name of files that I want to use in the GLAPD, and use subprocess to execute GLAPD.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os, subprocess, shlex
uniq_list = ['file1.fasta','file2.fasta','file3.fasta','file4.fasta']
for x in uniq_list:
GLAPD_SINGLE = './Single -in ../'+x+' -out '+x+'_glapd_single'
GLAPD_SINGLE = shlex.split(GLAPD_SINGLE)
GLAPD_LAMP = './LAMP -in '+x+'_glapd_single'+' -ref ../'+x+' -out '+x+'_lamp_primers.txt'
GLAPD_LAMP = shlex.split(GLAPD_LAMP)
subprocess.Popen(GLAPD_SINGLE)
subprocess.Popen(GLAPD_LAMP)
Which is my problem,
when I run the script, in a first moment appear that the GLAPD_LAMP process runs before the end of GLAPD_SINGLE run, and this message is showed:
Sorry! Don't have any candidate single primers in /home/GLAPD/Outer/file1.fasta_glapd_single!
but after that, the GLADP_SINGLE continues running.
I think that GLAPD_SINGLE run much quickly in the first time, so the script continues to GLAPD_LAMP, but GLAPD_SINGLE continues running in background.
Can anyone help me? P.S: I know that is much more easy to do this with a shell script, but this is only one part of a great python scrypt.
If you want to be sure, change:
subprocess.Popen(GLAPD_SINGLE)
subprocess.Popen(GLAPD_LAMP)
to
x = subprocess.Popen(GLAPD_SINGLE)
x.wait()
y = subprocess.Popen(GLAPD_LAMP)
y.wait()
Then they will only execute in order, and you'll know what the order of operations was. You can also capture all of the STDOUT and STDERR to variables, so you may want to do that to check if they are completing correctly.
Also, test run the program with those files outside of python first to make sure you understand the syntax/errors etc.
I'm testing now, Idk of x = subprocess.wait() the correct syntax for python 3.5 or previous versions, but for python 3.6 shoud be:
x = subprocess.Popen(GLAPD_SINGLE)
x.wait()
When my current analysis ends, I'll give the feedback, thanks Joe !
Log in to answer this question.