1 | #!/usr/bin/env python2
|
2 | """
|
3 | gc_stats_to_tsv.py
|
4 |
|
5 | Turn a set of files with OILS_GC_STATS output into a TSV file.
|
6 | """
|
7 | from __future__ import print_function
|
8 |
|
9 | import collections
|
10 | import os
|
11 | import sys
|
12 |
|
13 |
|
14 | def main(argv):
|
15 | header = None
|
16 |
|
17 | for path in argv[1:]:
|
18 | filename = os.path.basename(path)
|
19 | join_id, _ = os.path.splitext(filename)
|
20 |
|
21 | d = collections.OrderedDict()
|
22 |
|
23 | d["join_id"] = join_id
|
24 |
|
25 | with open(path) as f:
|
26 | for line in f:
|
27 | line = line.strip()
|
28 | if not line:
|
29 | continue
|
30 | key, value = line.split("=", 1)
|
31 | key = key.strip().replace(" ", "_")
|
32 | value = value.strip()
|
33 | d[key] = value
|
34 |
|
35 | if header is None:
|
36 | header = d.keys()
|
37 | print("\t".join(header))
|
38 | else:
|
39 | # Ensure the order
|
40 | assert d.keys() == header
|
41 |
|
42 | row = d.values()
|
43 | print("\t".join(row))
|
44 |
|
45 |
|
46 | if __name__ == '__main__':
|
47 | try:
|
48 | main(sys.argv)
|
49 | except RuntimeError as e:
|
50 | print('FATAL: %s' % e, file=sys.stderr)
|
51 | sys.exit(1)
|