Mercurial > repos > mvdbeek > add_input_name_as_column
comparison add_input_name_as_column.py @ 0:3a1f8302302d
Imported from capsule None
| author | mvdbeek |
|---|---|
| date | Tue, 13 Jan 2015 12:05:08 -0500 |
| parents | |
| children | 06061aa49527 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3a1f8302302d |
|---|---|
| 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() |
