# HG changeset patch
# User jpayne
# Date 1515428394 18000
# Node ID f1f2497301d3dcd7c5677b6f9ff11cd84137aeaf
planemo upload
diff -r 000000000000 -r f1f2497301d3 table-sort.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/table-sort.py Mon Jan 08 11:19:54 2018 -0500
@@ -0,0 +1,18 @@
+#!/usr/bin/env python3
+
+import csv
+import sys
+
+def main(headers):
+ rows = csv.DictReader(sys.stdin, delimiter='\t', dialect='excel-tab')
+ if not any([str(header) in rows.fieldnames for header in headers]):
+ raise ValueError("Couldn't find any of supplied headers ({}) in the table.".format(','.join(['"{}"'.format(header) for header in headers])))
+ items = list(rows)
+ items.sort(key=lambda d: [d.get(h) or "" for h in headers])
+ wr = csv.DictWriter(sys.stdout, dialect='excel-tab', fieldnames=rows.fieldnames)
+ wr.writeheader()
+ wr.writerows(items)
+ sys.stdout.flush()
+
+if __name__ == '__main__':
+ main(sys.argv[1:])
\ No newline at end of file
diff -r 000000000000 -r f1f2497301d3 table-sort.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/table-sort.xml Mon Jan 08 11:19:54 2018 -0500
@@ -0,0 +1,33 @@
+
+ on specified header or headers
+
+
+ $sorted
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff -r 000000000000 -r f1f2497301d3 table-union.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/table-union.py Mon Jan 08 11:19:54 2018 -0500
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+import csv
+import sys
+
+
+
+def main(files):
+ header = []
+ items = []
+ for fi in files:
+ with open(fi, 'rU') as table:
+ rows = csv.DictReader(table, delimiter='\t', dialect='excel-tab')
+ for field in rows.fieldnames:
+ if field not in set(header):
+ header.append(field)
+ items.extend(rows)
+ wr = csv.DictWriter(sys.stdout, delimiter='\t', dialect='excel-tab', fieldnames=header)
+ wr.writeheader()
+ wr.writerows(items)
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])
\ No newline at end of file
diff -r 000000000000 -r f1f2497301d3 table-union.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/table-union.xml Mon Jan 08 11:19:54 2018 -0500
@@ -0,0 +1,35 @@
+
+
+
+ $combined_table
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff -r 000000000000 -r f1f2497301d3 test-data/combined.tsv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/combined.tsv Mon Jan 08 11:19:54 2018 -0500
@@ -0,0 +1,3 @@
+name flavor color size
+Dingbat strawberry red
+Loki chocolate massive
diff -r 000000000000 -r f1f2497301d3 test-data/dingbat.tsv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/dingbat.tsv Mon Jan 08 11:19:54 2018 -0500
@@ -0,0 +1,2 @@
+name flavor color
+Dingbat strawberry red
diff -r 000000000000 -r f1f2497301d3 test-data/loki.tsv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/loki.tsv Mon Jan 08 11:19:54 2018 -0500
@@ -0,0 +1,2 @@
+name flavor size
+Loki chocolate massive
diff -r 000000000000 -r f1f2497301d3 test-data/sort_test_multiple.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/sort_test_multiple.txt Mon Jan 08 11:19:54 2018 -0500
@@ -0,0 +1,1 @@
+A B C D
1 1 2 3
1 1 2 2
1 1 1 1
2 2 2 2
\ No newline at end of file
diff -r 000000000000 -r f1f2497301d3 test-data/sort_test_multiple_sorted.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/sort_test_multiple_sorted.txt Mon Jan 08 11:19:54 2018 -0500
@@ -0,0 +1,1 @@
+A B C D
1 1 1 1
1 1 2 2
1 1 2 3
2 2 2 2
\ No newline at end of file
diff -r 000000000000 -r f1f2497301d3 test-data/sorted.tsv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/sorted.tsv Mon Jan 08 11:19:54 2018 -0500
@@ -0,0 +1,3 @@
+name flavor color size
+Loki chocolate massive
+Dingbat strawberry red