1
|
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]
|
4
|
10
|
1
|
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 f = open(args[current], 'r')
|
|
27 line = f.readline()
|
|
28 line = f.readline()
|
|
29 while line:
|
|
30 o.write(line[:line.rfind(newline)] + separator + sampleID + separator + str(count) + newline)
|
|
31 line = f.readline()
|
|
32 f.close()
|
|
33
|
|
34 if current >= (len(args) - 1):
|
|
35 break
|
|
36 if args[current + 1].find("/") is -1:
|
|
37 sampleID = args[current + 1]
|
|
38 current += 1
|
|
39 count = 1
|
|
40 else:
|
|
41 count += 1
|
|
42 current += 1
|
|
43 o.close()
|
|
44
|
|
45 except Exception, ex:
|
|
46 stop_err('Error running new_column.py\n' + str(ex))
|
|
47 sys.exit(0)
|
|
48
|
|
49 if __name__ == "__main__":
|
|
50 print sys.argv
|
|
51 main()
|