annotate add_input_name_as_column.py @ 5:06061aa49527 draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
author mvdbeek
date Wed, 06 Mar 2019 09:16:29 -0500
parents 3a1f8302302d
children 3284b72eef56
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
1 import io
0
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
2 import argparse
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
3
5
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
4
0
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
5 def Parser():
5
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
6 the_parser = argparse.ArgumentParser(description="add label to last column of file")
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
7 the_parser.add_argument('--input', required=True, action="store", type=str, help="input tabular file")
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
8 the_parser.add_argument('--output', required=True, action="store", type=str, help="output file path")
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
9 the_parser.add_argument('--label', required=True, action="store", type=str, help="label to add in last column")
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
10 the_parser.add_argument('--header', action="store", type=str, help="column label for last column")
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
11 args = the_parser.parse_args()
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
12 return args
0
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
13
3a1f8302302d Imported from capsule None
mvdbeek
parents:
diff changeset
14
5
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
15 args = Parser()
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
16
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
17
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
18 with io.open(args.input, encoding="utf-8") as input, io.open(args.output, 'w', encoding="utf-8") as output:
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
19 for i, line in enumerate(input):
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
20 line = line.strip('\n')
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
21 if (i == 0) and args.header:
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
22 line = "%s\t%s\n" % (line, args.header)
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
23 else:
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
24 line = "%s\t%s\n" % (line, args.label)
06061aa49527 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/add_input_name_as_column commit db90fc6943b99322a6d7459f644a6624c69a0be5-dirty
mvdbeek
parents: 0
diff changeset
25 output.write(line)