annotate add_input_name_as_column.py @ 1:07d2cbf43b51 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:15:49 -0500
parents bfebefdd5ba4
children ea4ad41e01fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
07d2cbf43b51 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
bfebefdd5ba4 Initial Commit.
mvdbeek
parents:
diff changeset
2 import argparse
bfebefdd5ba4 Initial Commit.
mvdbeek
parents:
diff changeset
3
1
07d2cbf43b51 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
bfebefdd5ba4 Initial Commit.
mvdbeek
parents:
diff changeset
5 def Parser():
1
07d2cbf43b51 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")
07d2cbf43b51 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")
07d2cbf43b51 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")
07d2cbf43b51 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")
07d2cbf43b51 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")
07d2cbf43b51 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()
07d2cbf43b51 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
bfebefdd5ba4 Initial Commit.
mvdbeek
parents:
diff changeset
13
bfebefdd5ba4 Initial Commit.
mvdbeek
parents:
diff changeset
14
1
07d2cbf43b51 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()
07d2cbf43b51 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
07d2cbf43b51 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
07d2cbf43b51 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:
07d2cbf43b51 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):
07d2cbf43b51 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')
07d2cbf43b51 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:
07d2cbf43b51 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)
07d2cbf43b51 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:
07d2cbf43b51 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)
07d2cbf43b51 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)