0
|
1 import sys
|
|
2 import argparse
|
|
3
|
|
4 def Parser():
|
|
5 the_parser = argparse.ArgumentParser(description="add label to last column of file")
|
|
6 the_parser.add_argument('--input', required=True, action="store", type=str, help="input tabular file")
|
|
7 the_parser.add_argument('--output', required=True, action="store", type=str, help="output file path")
|
|
8 the_parser.add_argument('--label', required=True, action="store", type=str, help="label to add in last column")
|
|
9 the_parser.add_argument('--header', action="store", type=str, help="column label for last column")
|
|
10 args = the_parser.parse_args()
|
|
11 return args
|
|
12
|
|
13 args=Parser()
|
|
14
|
|
15 input=open(args.input)
|
|
16 output=open(args.output, 'w')
|
|
17 for i,line in enumerate(input):
|
|
18 line=line.strip('\n')
|
|
19 if (i==0) and (args.header!=None):
|
|
20 line=line+'\t'+args.header
|
|
21 else:
|
|
22 line=line+'\t'+args.label
|
|
23 print >>output, line
|
|
24 input.close()
|
|
25 output.close()
|