annotate add_input_name_as_column.py @ 3:c9459a7e08ff draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
author iuc
date Tue, 14 Oct 2025 17:12:53 +0000
parents ea4ad41e01fc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ea4ad41e01fc "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 9292c57c34283543e86ecc65f805977224f6fc7b"
iuc
parents: 1
diff changeset
1 import argparse
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
2 import io
0
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")
3
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
7 the_parser.add_argument(
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
8 "--input", required=True, action="store", type=str, help="input tabular file"
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
9 )
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
10 the_parser.add_argument(
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
11 "--output", required=True, action="store", type=str, help="output file path"
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
12 )
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
13 the_parser.add_argument(
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
14 "--label",
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
15 required=True,
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
16 action="store",
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
17 type=str,
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
18 help="label to add in last column",
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
19 )
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
20 the_parser.add_argument(
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
21 "--header", action="store", type=str, help="column label for last column"
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
22 )
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
23 the_parser.add_argument(
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
24 "--prepend",
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
25 action="store_true",
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
26 default=False,
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
27 help="Prepend column instead of appending",
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
28 )
2
ea4ad41e01fc "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 9292c57c34283543e86ecc65f805977224f6fc7b"
iuc
parents: 1
diff changeset
29
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
30 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
31 return args
0
bfebefdd5ba4 Initial Commit.
mvdbeek
parents:
diff changeset
32
bfebefdd5ba4 Initial Commit.
mvdbeek
parents:
diff changeset
33
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
34 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
35
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
36
3
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
37 with io.open(args.input, encoding="utf-8") as input, io.open(
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
38 args.output, "w", encoding="utf-8"
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
39 ) as output:
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
40 for i, line in enumerate(input):
3
c9459a7e08ff planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 1775d01920f27931a1935e233766f615d753502b
iuc
parents: 2
diff changeset
41 line = line.strip("\n")
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
42 if (i == 0) and args.header:
2
ea4ad41e01fc "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 9292c57c34283543e86ecc65f805977224f6fc7b"
iuc
parents: 1
diff changeset
43 new_entry = args.header
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
44 else:
2
ea4ad41e01fc "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 9292c57c34283543e86ecc65f805977224f6fc7b"
iuc
parents: 1
diff changeset
45 new_entry = args.label
ea4ad41e01fc "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 9292c57c34283543e86ecc65f805977224f6fc7b"
iuc
parents: 1
diff changeset
46 if args.prepend:
ea4ad41e01fc "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 9292c57c34283543e86ecc65f805977224f6fc7b"
iuc
parents: 1
diff changeset
47 line = "%s\t%s\n" % (new_entry, line)
ea4ad41e01fc "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 9292c57c34283543e86ecc65f805977224f6fc7b"
iuc
parents: 1
diff changeset
48 else:
ea4ad41e01fc "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/add_input_name_as_column commit 9292c57c34283543e86ecc65f805977224f6fc7b"
iuc
parents: 1
diff changeset
49 line = "%s\t%s\n" % (line, new_entry)
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
50 output.write(line)