changeset 13:746091a78780

planemo upload
author jpayne
date Fri, 09 Mar 2018 11:14:02 -0500
parents 15230438f7f5
children 1af2524f48b7
files table-summarize.py table-summary.xml test-data/summary.txt test-data/summary_test.txt
diffstat 4 files changed, 85 insertions(+), 0 deletions(-) [+]
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
--- /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 @@
+<tool id="table-summary" name="Summarize a tabular dataset" version="0.1.0">
+    <description>by counting unique values in columns</description>
+    <requirements>
+        <!-- <requirement type="package" version="3.4">python</requirement> -->
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+        python $__tool_directory__/table-summarize.py $table > $summary
+    ]]></command>
+    <inputs>
+        <param name="table" type="data" format="tsv" />
+    </inputs>
+    <outputs>
+        <data name="summary" format="txt" label="Summary" />
+    </outputs>
+
+    <tests>
+        <test>
+            <param name="table" value="summary_test.txt" />
+            <output name="summary" value="summary.txt" />
+        </test>
+    </tests>
+    <help><![CDATA[
+        Summarize tabular results by counting up unique values in columns.
+    ]]></help>
+
+    <citations>
+    </citations>
+</tool>
\ No newline at end of file
--- /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:
--- /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