Mercurial > repos > jpayne > table_ops
diff table-union.py @ 0:f1f2497301d3
planemo upload
author | jpayne |
---|---|
date | Mon, 08 Jan 2018 11:19:54 -0500 |
parents | |
children | 8c5fb0c5e560 |
line wrap: on
line diff
--- /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