view 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 source
#!/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:])