# HG changeset patch # User jpayne # Date 1520612042 18000 # Node ID 746091a787805b8a9ca9b42539d130100133e5a6 # Parent 15230438f7f53d9c02eeda808fdd9e35aa08f0ef planemo upload diff -r 15230438f7f5 -r 746091a78780 table-summarize.py --- /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 diff -r 15230438f7f5 -r 746091a78780 table-summary.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/table-summary.xml Fri Mar 09 11:14:02 2018 -0500 @@ -0,0 +1,28 @@ + + by counting unique values in columns + + + + $summary + ]]> + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 15230438f7f5 -r 746091a78780 test-data/summary.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/summary.txt Fri Mar 09 11:14:02 2018 -0500 @@ -0,0 +1,19 @@ +Summary: +Wingstop: + - X: 3 of 10 +Jason's Deli: + - X: 2 of 10 +Moe's Southwest Grill: + - X: 1 of 10 +Subway: + - X: 1 of 10 +Taco Bell: + - X: 3 of 10 +Popeyes Louisiana Kitchen: + - X: 2 of 10 +Hardee's: + - X: 1 of 10 +Taco Cabana: + - X: 1 of 10 +Kenny Rogers Roasters: +KFC: diff -r 15230438f7f5 -r 746091a78780 test-data/summary_test.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/summary_test.txt Fri Mar 09 11:14:02 2018 -0500 @@ -0,0 +1,11 @@ + Wingstop Jason's Deli Moe's Southwest Grill Subway Taco Bell Popeyes Louisiana Kitchen Hardee's Taco Cabana Kenny Rogers Roasters KFC +rice wine X +celery seeds X X +eggplants X X +marshmallows +cream cheese X +chambord X +kiwi X +papayas X +bruschetta X X +focaccia X X X \ No newline at end of file