diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/add_input_name_as_column.py	Tue Jan 13 12:05:08 2015 -0500
@@ -0,0 +1,25 @@
+import sys
+import argparse
+
+def Parser():
+  the_parser = argparse.ArgumentParser(description="add label to last column of file")
+  the_parser.add_argument('--input', required=True, action="store", type=str, help="input tabular file")
+  the_parser.add_argument('--output', required=True,  action="store", type=str, help="output file path")
+  the_parser.add_argument('--label', required=True, action="store", type=str, help="label to add in last column")
+  the_parser.add_argument('--header', action="store", type=str, help="column label for last column")
+  args = the_parser.parse_args()
+  return args
+
+args=Parser()
+
+input=open(args.input)
+output=open(args.output, 'w')
+for i,line in enumerate(input):
+  line=line.strip('\n')
+  if (i==0) and (args.header!=None):
+    line=line+'\t'+args.header
+  else:
+    line=line+'\t'+args.label
+  print >>output, line
+input.close()
+output.close()