Mercurial > repos > mvdbeek > add_input_name_as_column
comparison add_input_name_as_column.py @ 0:bfebefdd5ba4
Initial Commit.
| author | mvdbeek |
|---|---|
| date | Mon, 29 Dec 2014 21:26:29 +0100 |
| parents | |
| children | 07d2cbf43b51 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:bfebefdd5ba4 |
|---|---|
| 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() |
