Mercurial > repos > jmsong > transpose
diff transpose.py @ 0:fc1b758149c7 draft
Uploaded
author | jmsong |
---|---|
date | Tue, 18 Mar 2014 11:32:24 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/transpose.py Tue Mar 18 11:32:24 2014 -0400 @@ -0,0 +1,48 @@ +#!/usr/bin/env python +#By: Clayton Turner + +#imports +import sys +import csv + +# error +def stop_err( msg ): + sys.stderr.write( "%s\n" % msg ) + sys.exit() + +# main +def main(): + try: + # retrieve file locations/names + inputFile = sys.argv[1] + output = sys.argv[2] + + # open input file + itemList = list() + with open(inputFile) as infile: + for line in infile: + items = line.strip('\n').split('\t') + itemList.append(items) + rows = zip(*itemList) + + infile.close() + + # open output file + outfile = open(output,'w') + writer = csv.writer(outfile, delimiter='\t') + + # append data to output file + for row in rows: + writer.writerow(row) + + # close output file + outfile.close() + + except Exception, ex: + stop_err('Error running transpose.py\n' + str(ex)) + + # exit + sys.exit(0) + +if __name__ == "__main__": + main()