annotate add_input_name_as_column.py @ 4:b31219f26a8f

Change $input.name to $input.element_ideentifier. This allows keeping the input datatset collections identifier (= history name).
author mvdbeek
date Fri, 20 Mar 2015 14:51:56 +0100
parents 3a1f8302302d
children 06061aa49527
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
1 import sys
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
2 import argparse
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
3
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
4 def Parser():
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
5 the_parser = argparse.ArgumentParser(description="add label to last column of file")
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
6 the_parser.add_argument('--input', required=True, action="store", type=str, help="input tabular file")
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
7 the_parser.add_argument('--output', required=True, action="store", type=str, help="output file path")
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
8 the_parser.add_argument('--label', required=True, action="store", type=str, help="label to add in last column")
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
9 the_parser.add_argument('--header', action="store", type=str, help="column label for last column")
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
10 args = the_parser.parse_args()
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
11 return args
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
12
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
13 args=Parser()
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
14
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
15 input=open(args.input)
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
16 output=open(args.output, 'w')
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
17 for i,line in enumerate(input):
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
18 line=line.strip('\n')
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
19 if (i==0) and (args.header!=None):
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
20 line=line+'\t'+args.header
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
21 else:
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
22 line=line+'\t'+args.label
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
23 print >>output, line
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
24 input.close()
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
25 output.close()