annotate table-union.py @ 0:f1f2497301d3

planemo upload
author jpayne
date Mon, 08 Jan 2018 11:19:54 -0500
parents
children 8c5fb0c5e560
rev   line source
jpayne@0 1 #!/usr/bin/env python3
jpayne@0 2
jpayne@0 3 import csv
jpayne@0 4 import sys
jpayne@0 5
jpayne@0 6
jpayne@0 7
jpayne@0 8 def main(files):
jpayne@0 9 header = []
jpayne@0 10 items = []
jpayne@0 11 for fi in files:
jpayne@0 12 with open(fi, 'rU') as table:
jpayne@0 13 rows = csv.DictReader(table, delimiter='\t', dialect='excel-tab')
jpayne@0 14 for field in rows.fieldnames:
jpayne@0 15 if field not in set(header):
jpayne@0 16 header.append(field)
jpayne@0 17 items.extend(rows)
jpayne@0 18 wr = csv.DictWriter(sys.stdout, delimiter='\t', dialect='excel-tab', fieldnames=header)
jpayne@0 19 wr.writeheader()
jpayne@0 20 wr.writerows(items)
jpayne@0 21
jpayne@0 22
jpayne@0 23 if __name__ == '__main__':
jpayne@0 24 main(sys.argv[1:])