-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
70 lines (59 loc) · 1.94 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import subprocess
import time
import os
import glob
import sys
Note="""
change reference
"""
Reference="/home/cre/data/GRCh38_full_analysis_set_plus_decoy_hla.fa"
Samples="/home/cre/data/HG0051*chr22.cram"
PythonName="python3"
ProgramName="jc.py"
TestDirRoot="test"
RunDir=TestDirRoot+"/"+"TestRun"+time.strftime("%Y%m%d%H%M%S",time.localtime())
SamplesArray=glob.glob(Samples)
SamplesArray.sort()
run=subprocess.Popen(["ls",TestDirRoot],bufsize=1,stdout=subprocess.PIPE,universal_newlines=True)
Runs=[]
while True:
line=run.stdout.readline()
if line=="":
break
if len(line)<7:
continue
if line[:7]=="TestRun":
Runs.append(line.strip())
run.wait()
Runs.sort()
LastDir=TestDirRoot+"/"+Runs[-1]
LastSource=LastDir+"/src"
while os.path.isdir(RunDir):
RunDir+="+"
os.mkdir(RunDir)
SourceDir=RunDir+"/src"
os.mkdir(SourceDir)
OutFile=open(RunDir+"/"+"out.txt","w")
ErrFile=open(RunDir+"/"+"err.txt","w")
LogFile=open(RunDir+"/"+"log.txt","w")
PatchFile=open(RunDir+"/"+"diff.patch","w")
subprocess.Popen(["cp * %s"%(SourceDir)],shell=True).wait()
subprocess.Popen(["diff","-N",SourceDir,LastSource],bufsize=1,stdout=PatchFile,stderr=subprocess.PIPE,universal_newlines=True).wait()
PatchFile.close()
print("Run %s\nStart at:%s\nProgram:%s\nReference:%s\nSamples:%s\nNote:%s\n"%(RunDir.split("/")[-1],ProgramName,time.ctime(),Reference,Samples,Note),file=LogFile)
LogFile.flush()
Start=time.time()
run=subprocess.Popen([PythonName,"-u",ProgramName,Reference]+SamplesArray,bufsize=1,stdout=OutFile,stderr=subprocess.PIPE,universal_newlines=True)
while True:
line=run.stderr.readline()
if line=="":
break
ErrFile.write(line)
print(line, end="", file=sys.stderr)
run.wait()
print("Time elapsed:%s"%(time.time()-Start),file=LogFile)
subprocess.Popen([PythonName,"benchmark.py",RunDir+"/"+"out.txt"],stdout=LogFile).wait()
OutFile.close()
ErrFile.close()
LogFile.close()
subprocess.call(["cat", RunDir+"/"+"log.txt"])