[Tutor] Re subprocess
jarod_v6 at libero.it
jarod_v6 at libero.it
Thu Sep 11 15:52:38 CEST 2014
Thanks for the suggestion and corrections.
I don't put the else staement onf if log_file but now I realize my mistake
I have 3 comand to do:
step_1_out =["STAR --genomeDir /home/sbsuser/databases/Starhg19/GenomeDir/ --
runMode alignReads --readFilesIn %s %s --runThreadN 12 --readFilesCommand
zcat "%(dx[i],sn[i])]
step_2_out = ["STAR --runMode genomeGenerate --genomeDir %s --
genomeFastaFiles ~/databases/bowtie2Database/hg19.fa --sjdbFileChrStartEnd %
sSJ.out.tab --sjdbOverhang 49 --runThreadN 12" %(tx[i],tx[i])]
step_3_out =["STAR --genomeDir %s --runMode alignReads --readFilesIn %s %s
--runThreadN 12 --readFilesCommand zcat "%(Pos2,dx,sn)]
So I need to run one step a time. cmd is the comand (step_1_out) e pi is the
directory of the files.
def run(cmd,pi):
import subprocess
import time
import logging
logging.basicConfig(level=logging.DEBUG,format="%(asctime)s - %(name)s - %
(levelname)s - %(message)s")
#logging.debug(" Running pipelines: %s" % (cmd))
# setup logging
tou = "log.txt"
logfh = open(tou, "r+")
p1 = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=logfh,
cwd=pi)
#logging.info(" Running pipelines: %s" % (cmd))
while True:
if p1.poll() is None:
time.sleep(120)
pass
if p1.poll()==0:
print 'Finish this step.'
logging.info("###################: %s %s" % (cmd,time.ctime()))
break
if p1.poll() is not None and p1.poll() != 0:
raise Exception('Not working please check the error')
# end logging
logfh.close()
return 0
I don't understand where is the error in the code above.
If I change the code in this way seems work
def run(cmd,pi):
import subprocess
import time
import logging
logging.basicConfig(level=logging.DEBUG,format="%(asctime)s - %(name)s - %
(levelname)s - %(messag
e)s")
#logging.debug(" Running pipelines: %s" % (cmd))
# setup logging
log_file = "None"
tou = "og.txt"
logfh = open(tou, "r+")
p1 = subprocess.Popen(cmd,shell=True,stdout=logfh,stderr=logfh,cwd=pi)
p1.wait()
#logging.info(" Running pipelines: %s" % (cmd))
return 0
Someone can explain to me when we neet to choose wait or pool?
Thanks for the help
More information about the Tutor
mailing list