0
|
1 import sys
|
|
2 # error
|
|
3 def stop_err( msg ):
|
|
4 sys.stderr.write( "%s\n" % msg )
|
|
5 sys.exit()
|
|
6
|
|
7 # main
|
|
8 def main():
|
|
9 args = sys.argv[1:-2]
|
|
10
|
|
11 try:
|
|
12 o = open(sys.argv[-1], 'w')
|
|
13 i = open(args[1], 'r')
|
|
14 separator = "\t"
|
|
15 newline = "\n"
|
|
16 line = i.readline()
|
|
17 #write the header
|
|
18 o.write(line[:line.rfind(newline)] + separator + "Sample" + separator + "Replicate" + newline)
|
|
19 i.close()
|
|
20
|
|
21 current = 1
|
|
22 sampleID = args[0]
|
|
23 count = 1
|
|
24
|
|
25 while True:
|
|
26 print str(o)
|
|
27 f = open(args[current], 'r')
|
|
28 line = f.readline()
|
|
29 line = f.readline()
|
|
30 while line:
|
|
31 o.write(line[:line.rfind(newline)] + separator + sampleID + separator + str(count) + newline)
|
|
32 line = f.readline()
|
|
33 f.close()
|
|
34
|
|
35 if current >= (len(args) - 1):
|
|
36 break
|
|
37 if args[current + 1].find("/") is -1:
|
|
38 sampleID = args[current + 1]
|
|
39 current += 1
|
|
40 count = 1
|
|
41 else:
|
|
42 count += 1
|
|
43 current += 1
|
|
44 o.close()
|
|
45
|
|
46 except Exception, ex:
|
|
47 stop_err('Error running new_column.py\n' + str(ex))
|
|
48 sys.exit(0)
|
|
49
|
|
50 if __name__ == "__main__":
|
|
51 print sys.argv
|
|
52 main()
|