modified: makesrc3.mk
[GalaxyCodeBases.git] / BioInfo / BS-Seq / bwa-meth / compare / src / parse-time-mem.py
blob268031c8eca86403d7157ad6c8428c8f6599da0d
1 import re
2 def parse_time(log_file):
4 for line in open(log_file):
5 if "CPU time" in line:
6 _, time = [x.strip() for x in line.split(":")]
7 time, unit = time.split()
8 assert unit == "sec."
9 return float(time)
10 raise Exception(log_file)
12 def parse_mem(log_file):
14 for line in open(log_file):
15 if "Max Memory" in line:
16 _, mem = [x.strip() for x in line.split(":")]
17 mem, unit = mem.split()
18 assert unit == "MB"
19 return float(mem)
21 raise Exception(log_file)
23 def parse_prog(log_file):
24 import os.path as op
25 p = op.basename(log_file)
26 if p.startswith('trim-'):
27 p = p[5:]
28 return p.split("-")[0]
30 def parse_sim_real(log_file):
31 import os.path as op
32 p = op.basename(log_file)
33 if p.startswith('trim-'):
34 p = p[5:]
35 return p.split("-")[1].split(".")[0]
37 def parse_trim(log_file):
38 return ["no", "yes"][int("trim" in log_file)]
41 FMT = "{trimmed} & {program} & {time}(min) & {mem}(GB) & {dataset} \\\\"
43 def main(logs):
44 fmt = FMT
45 print fmt.replace("{", "").replace("}", "")
46 fmt = re.sub("\(.+?\)", "", fmt)
47 for log in logs:
48 trimmed = parse_trim(log)
49 mem = '%.2f' % (parse_mem(log) / 1000.)
50 time = '%.2f' % (parse_time(log) / 60.)
51 program = parse_prog(log)
52 dataset = parse_sim_real(log)
53 print fmt.format(**locals())
55 if __name__ == "__main__":
56 import sys
57 main(sys.argv[1:])