Mercurial > repos > jmsong > transpose
comparison transpose.py @ 0:fc1b758149c7 draft
Uploaded
author | jmsong |
---|---|
date | Tue, 18 Mar 2014 11:32:24 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc1b758149c7 |
---|---|
1 #!/usr/bin/env python | |
2 #By: Clayton Turner | |
3 | |
4 #imports | |
5 import sys | |
6 import csv | |
7 | |
8 # error | |
9 def stop_err( msg ): | |
10 sys.stderr.write( "%s\n" % msg ) | |
11 sys.exit() | |
12 | |
13 # main | |
14 def main(): | |
15 try: | |
16 # retrieve file locations/names | |
17 inputFile = sys.argv[1] | |
18 output = sys.argv[2] | |
19 | |
20 # open input file | |
21 itemList = list() | |
22 with open(inputFile) as infile: | |
23 for line in infile: | |
24 items = line.strip('\n').split('\t') | |
25 itemList.append(items) | |
26 rows = zip(*itemList) | |
27 | |
28 infile.close() | |
29 | |
30 # open output file | |
31 outfile = open(output,'w') | |
32 writer = csv.writer(outfile, delimiter='\t') | |
33 | |
34 # append data to output file | |
35 for row in rows: | |
36 writer.writerow(row) | |
37 | |
38 # close output file | |
39 outfile.close() | |
40 | |
41 except Exception, ex: | |
42 stop_err('Error running transpose.py\n' + str(ex)) | |
43 | |
44 # exit | |
45 sys.exit(0) | |
46 | |
47 if __name__ == "__main__": | |
48 main() |