Mercurial > repos > jpayne > table_ops
diff table-summarize.py @ 13:746091a78780
planemo upload
author | jpayne |
---|---|
date | Fri, 09 Mar 2018 11:14:02 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/table-summarize.py Fri Mar 09 11:14:02 2018 -0500 @@ -0,0 +1,27 @@ +#! /usr/bin/env python + +from __future__ import print_function + +import csv +import sys +from collections import Counter, OrderedDict + +def main(table): + with open(table, 'rU') as table_f: + rdr = csv.DictReader(table_f, delimiter='\t', dialect='excel') + summary = OrderedDict() + data = list(rdr) + for name in rdr.fieldnames[1:]: + summary[name] = Counter([r[name] for r in data]) + total = len(data) + print("Summary:") + for name, results in summary.items(): + print('{}:'.format(name)) + for result, num in results.items(): + if result: + print("\t - {}: {} of {}".format(result, num, total)) + + + +if __name__ == '__main__': + main(sys.argv[1]) \ No newline at end of file