annotate table-summarize.py @ 13:746091a78780

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