Mercurial > repos > jpayne > table_ops
comparison table-summarize.py @ 13:746091a78780
planemo upload
author | jpayne |
---|---|
date | Fri, 09 Mar 2018 11:14:02 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
12:15230438f7f5 | 13:746091a78780 |
---|---|
1 #! /usr/bin/env python | |
2 | |
3 from __future__ import print_function | |
4 | |
5 import csv | |
6 import sys | |
7 from collections import Counter, OrderedDict | |
8 | |
9 def main(table): | |
10 with open(table, 'rU') as table_f: | |
11 rdr = csv.DictReader(table_f, delimiter='\t', dialect='excel') | |
12 summary = OrderedDict() | |
13 data = list(rdr) | |
14 for name in rdr.fieldnames[1:]: | |
15 summary[name] = Counter([r[name] for r in data]) | |
16 total = len(data) | |
17 print("Summary:") | |
18 for name, results in summary.items(): | |
19 print('{}:'.format(name)) | |
20 for result, num in results.items(): | |
21 if result: | |
22 print("\t - {}: {} of {}".format(result, num, total)) | |
23 | |
24 | |
25 | |
26 if __name__ == '__main__': | |
27 main(sys.argv[1]) |